From d32a02f21abc6ff1a5bdb65a3bfd82e713ce97ab Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 1 Jul 2014 17:12:47 +0400 Subject: [PATCH] Modify top-level/extension property hierarchy - rename KTopLevelProperty to KTopLevelVariable - create KTopLevelExtensionProperty, a subclass of KExtensionProperty - create KTopLevelProperty, a superclass of KTopLevelVariable and KTopLevelExtensionProperty. (In the future, it will have a container of type KPackage.) --- .../jet/codegen/ExpressionCodegen.java | 8 +++---- .../lang/resolve/java/AsmTypeConstants.java | 8 +++---- .../jet/lang/reflect/ReflectionTypes.kt | 16 +++++++------- .../property/extensionFromTopLevel.kt | 3 +++ .../property/topLevelFromTopLevel.kt | 5 ++++- .../reflect/KTopLevelExtensionProperty.kt | 21 +++++++++++++++++++ .../src/kotlin/reflect/KTopLevelProperty.kt | 4 ++-- .../src/kotlin/reflect/KTopLevelVariable.kt | 21 +++++++++++++++++++ ...l.kt => KTopLevelExtensionPropertyImpl.kt} | 8 +++---- ...opertyImpl.kt => KTopLevelVariableImpl.kt} | 8 +++---- .../kotlin/reflect/jvm/internal/factory.kt | 16 +++++++------- 11 files changed, 83 insertions(+), 35 deletions(-) create mode 100644 core/reflection/src/kotlin/reflect/KTopLevelExtensionProperty.kt create mode 100644 core/reflection/src/kotlin/reflect/KTopLevelVariable.kt rename core/runtime.jvm/src/kotlin/reflect/jvm/internal/{KExtensionPropertyImpl.kt => KTopLevelExtensionPropertyImpl.kt} (82%) rename core/runtime.jvm/src/kotlin/reflect/jvm/internal/{KTopLevelPropertyImpl.kt => KTopLevelVariableImpl.kt} (85%) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 1b04b121b57..af203a1a0a0 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -2452,14 +2452,14 @@ public class ExpressionCodegen extends JetVisitor implem if (receiverParameter != null) { Type[] parameterTypes = new Type[] {JAVA_STRING_TYPE, K_PACKAGE_IMPL_TYPE, getType(Class.class)}; factoryMethod = descriptor.isVar() - ? method("mutableExtensionProperty", K_MUTABLE_EXTENSION_PROPERTY_IMPL_TYPE, parameterTypes) - : method("extensionProperty", K_EXTENSION_PROPERTY_IMPL_TYPE, parameterTypes); + ? method("mutableTopLevelExtensionProperty", K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE, parameterTypes) + : method("topLevelExtensionProperty", K_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE, parameterTypes); } else { Type[] parameterTypes = new Type[] {JAVA_STRING_TYPE, K_PACKAGE_IMPL_TYPE}; factoryMethod = descriptor.isVar() - ? method("mutableTopLevelProperty", K_MUTABLE_TOP_LEVEL_PROPERTY_IMPL_TYPE, parameterTypes) - : method("topLevelProperty", K_TOP_LEVEL_PROPERTY_IMPL_TYPE, parameterTypes); + ? method("mutableTopLevelVariable", K_MUTABLE_TOP_LEVEL_VARIABLE_IMPL_TYPE, parameterTypes) + : method("topLevelVariable", K_TOP_LEVEL_VARIABLE_IMPL_TYPE, parameterTypes); } v.visitLdcInsn(descriptor.getName().asString()); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AsmTypeConstants.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AsmTypeConstants.java index c4d094cb347..0f65adb0d8b 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AsmTypeConstants.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AsmTypeConstants.java @@ -43,10 +43,10 @@ public class AsmTypeConstants { public static final Type K_CLASS_IMPL_TYPE = reflectInternal("KClassImpl"); public static final Type K_PACKAGE_IMPL_TYPE = reflectInternal("KPackageImpl"); - public static final Type K_TOP_LEVEL_PROPERTY_IMPL_TYPE = reflectInternal("KTopLevelPropertyImpl"); - public static final Type K_MUTABLE_TOP_LEVEL_PROPERTY_IMPL_TYPE = reflectInternal("KMutableTopLevelPropertyImpl"); - public static final Type K_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KExtensionPropertyImpl"); - public static final Type K_MUTABLE_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KMutableExtensionPropertyImpl"); + public static final Type K_TOP_LEVEL_VARIABLE_IMPL_TYPE = reflectInternal("KTopLevelVariableImpl"); + public static final Type K_MUTABLE_TOP_LEVEL_VARIABLE_IMPL_TYPE = reflectInternal("KMutableTopLevelVariableImpl"); + public static final Type K_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KTopLevelExtensionPropertyImpl"); + public static final Type K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KMutableTopLevelExtensionPropertyImpl"); public static final String REFLECTION_INTERNAL_PACKAGE = reflectInternal("InternalPackage").getInternalName(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/reflect/ReflectionTypes.kt b/compiler/frontend/src/org/jetbrains/jet/lang/reflect/ReflectionTypes.kt index 299d3b2c8fa..a1e53d6b063 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/reflect/ReflectionTypes.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/reflect/ReflectionTypes.kt @@ -49,12 +49,12 @@ public class ReflectionTypes(private val module: ModuleDescriptor) { public fun getKExtensionFunction(n: Int): ClassDescriptor = find("KExtensionFunction$n") public fun getKMemberFunction(n: Int): ClassDescriptor = find("KMemberFunction$n") - public val kTopLevelProperty: ClassDescriptor by ClassLookup - public val kMutableTopLevelProperty: ClassDescriptor by ClassLookup + public val kTopLevelVariable: ClassDescriptor by ClassLookup + public val kMutableTopLevelVariable: ClassDescriptor by ClassLookup public val kMemberProperty: ClassDescriptor by ClassLookup public val kMutableMemberProperty: ClassDescriptor by ClassLookup - public val kExtensionProperty: ClassDescriptor by ClassLookup - public val kMutableExtensionProperty: ClassDescriptor by ClassLookup + public val kTopLevelExtensionProperty: ClassDescriptor by ClassLookup + public val kMutableTopLevelExtensionProperty: ClassDescriptor by ClassLookup public fun getKFunctionType( annotations: Annotations, @@ -85,14 +85,14 @@ public class ReflectionTypes(private val module: ModuleDescriptor) { mutable: Boolean ): JetType { val classDescriptor = if (mutable) when { - extensionProperty -> kMutableExtensionProperty + extensionProperty -> kMutableTopLevelExtensionProperty receiverType != null -> kMutableMemberProperty - else -> kMutableTopLevelProperty + else -> kMutableTopLevelVariable } else when { - extensionProperty -> kExtensionProperty + extensionProperty -> kTopLevelExtensionProperty receiverType != null -> kMemberProperty - else -> kTopLevelProperty + else -> kTopLevelVariable } if (ErrorUtils.isError(classDescriptor)) { diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionFromTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionFromTopLevel.kt index dc7c5dd3052..9a2b860ecb1 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionFromTopLevel.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/extensionFromTopLevel.kt @@ -8,6 +8,7 @@ var Int.meaning: Long fun test() { val f = String::countCharacters + f : KTopLevelExtensionProperty f : KExtensionProperty f : KMutableExtensionProperty f.get("abc") : Int @@ -15,7 +16,9 @@ fun test() { val g = Int::meaning + g : KTopLevelExtensionProperty g : KExtensionProperty + g : KMutableTopLevelExtensionProperty g : KMutableExtensionProperty g.get(0) : Long g.set(1, 0L) diff --git a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/topLevelFromTopLevel.kt b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/topLevelFromTopLevel.kt index 85ef42b4398..88ca4f1037d 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/topLevelFromTopLevel.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/callableReference/property/topLevelFromTopLevel.kt @@ -4,8 +4,11 @@ val y: String get() = "y" fun testX() { val xx = ::x xx : KMutableTopLevelProperty + xx : KMutableTopLevelVariable xx : KTopLevelProperty + xx : KTopLevelVariable xx : KMutableProperty + xx : KMutableVariable xx : KProperty xx : KCallable @@ -17,7 +20,7 @@ fun testX() { fun testY() { val yy = ::y yy : KMutableTopLevelProperty - yy : KTopLevelProperty + yy : KTopLevelVariable yy : KMutableProperty yy : KProperty yy : KCallable diff --git a/core/reflection/src/kotlin/reflect/KTopLevelExtensionProperty.kt b/core/reflection/src/kotlin/reflect/KTopLevelExtensionProperty.kt new file mode 100644 index 00000000000..9771d4ffbbd --- /dev/null +++ b/core/reflection/src/kotlin/reflect/KTopLevelExtensionProperty.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.reflect + +public trait KTopLevelExtensionProperty : KExtensionProperty, KTopLevelProperty + +public trait KMutableTopLevelExtensionProperty : KTopLevelExtensionProperty, KMutableExtensionProperty, KMutableTopLevelProperty diff --git a/core/reflection/src/kotlin/reflect/KTopLevelProperty.kt b/core/reflection/src/kotlin/reflect/KTopLevelProperty.kt index ee1bf17b6b7..2a10126ba66 100644 --- a/core/reflection/src/kotlin/reflect/KTopLevelProperty.kt +++ b/core/reflection/src/kotlin/reflect/KTopLevelProperty.kt @@ -16,6 +16,6 @@ package kotlin.reflect -public trait KTopLevelProperty : KVariable +public trait KTopLevelProperty : KProperty -public trait KMutableTopLevelProperty : KTopLevelProperty, KMutableVariable +public trait KMutableTopLevelProperty : KTopLevelProperty, KMutableProperty diff --git a/core/reflection/src/kotlin/reflect/KTopLevelVariable.kt b/core/reflection/src/kotlin/reflect/KTopLevelVariable.kt new file mode 100644 index 00000000000..c7239c73b07 --- /dev/null +++ b/core/reflection/src/kotlin/reflect/KTopLevelVariable.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.reflect + +public trait KTopLevelVariable : KVariable, KTopLevelProperty + +public trait KMutableTopLevelVariable : KTopLevelVariable, KMutableVariable, KMutableTopLevelProperty diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KExtensionPropertyImpl.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelExtensionPropertyImpl.kt similarity index 82% rename from core/runtime.jvm/src/kotlin/reflect/jvm/internal/KExtensionPropertyImpl.kt rename to core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelExtensionPropertyImpl.kt index 50406e2c72e..5e58247c5e3 100644 --- a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KExtensionPropertyImpl.kt +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelExtensionPropertyImpl.kt @@ -18,11 +18,11 @@ package kotlin.reflect.jvm.internal import java.lang.reflect.* -open class KExtensionPropertyImpl( +open class KTopLevelExtensionPropertyImpl( public override val name: String, protected val owner: KPackageImpl, protected val receiverClass: Class -) : KExtensionProperty, KPropertyImpl { +) : KTopLevelExtensionProperty, KPropertyImpl { override val field: Field? get() = null // TODO: extract, make lazy (weak?), use our descriptors knowledge, support Java fields @@ -33,11 +33,11 @@ open class KExtensionPropertyImpl( } } -class KMutableExtensionPropertyImpl( +class KMutableTopLevelExtensionPropertyImpl( name: String, owner: KPackageImpl, receiverClass: Class -) : KMutableExtensionProperty, KMutablePropertyImpl, KExtensionPropertyImpl(name, owner, receiverClass) { +) : KMutableTopLevelExtensionProperty, KMutablePropertyImpl, KTopLevelExtensionPropertyImpl(name, owner, receiverClass) { override val setter: Method = owner.jClass.getMethod(setterName(name), receiverClass, getter.getReturnType()!!) override fun set(receiver: T, value: R) { diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelPropertyImpl.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelVariableImpl.kt similarity index 85% rename from core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelPropertyImpl.kt rename to core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelVariableImpl.kt index a95bed1131f..eb765c13d08 100644 --- a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelPropertyImpl.kt +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/KTopLevelVariableImpl.kt @@ -18,10 +18,10 @@ package kotlin.reflect.jvm.internal import java.lang.reflect.* -open class KTopLevelPropertyImpl( +open class KTopLevelVariableImpl( public override val name: String, protected val owner: KPackageImpl -) : KTopLevelProperty, KVariableImpl { +) : KTopLevelVariable, KVariableImpl { // TODO: load the field from the corresponding package part override val field: Field? get() = null @@ -33,10 +33,10 @@ open class KTopLevelPropertyImpl( } } -class KMutableTopLevelPropertyImpl( +class KMutableTopLevelVariableImpl( name: String, owner: KPackageImpl -) : KMutableTopLevelProperty, KMutableVariableImpl, KTopLevelPropertyImpl(name, owner) { +) : KMutableTopLevelVariable, KMutableVariableImpl, KTopLevelVariableImpl(name, owner) { override val setter: Method = owner.jClass.getMethod(setterName(name), getter.getReturnType()!!) override fun set(value: R) { diff --git a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/factory.kt b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/factory.kt index 9ec07585bef..07c18b226ef 100644 --- a/core/runtime.jvm/src/kotlin/reflect/jvm/internal/factory.kt +++ b/core/runtime.jvm/src/kotlin/reflect/jvm/internal/factory.kt @@ -23,14 +23,14 @@ fun kClass(jClass: Class): KClassImpl = fun kPackage(jClass: Class<*>): KPackageImpl = KPackageImpl(jClass) -fun topLevelProperty(name: String, owner: KPackageImpl): KTopLevelPropertyImpl = - KTopLevelPropertyImpl(name, owner) +fun topLevelVariable(name: String, owner: KPackageImpl): KTopLevelVariableImpl = + KTopLevelVariableImpl(name, owner) -fun mutableTopLevelProperty(name: String, owner: KPackageImpl): KMutableTopLevelPropertyImpl = - KMutableTopLevelPropertyImpl(name, owner) +fun mutableTopLevelVariable(name: String, owner: KPackageImpl): KMutableTopLevelVariableImpl = + KMutableTopLevelVariableImpl(name, owner) -fun extensionProperty(name: String, owner: KPackageImpl, receiver: Class): KExtensionPropertyImpl = - KExtensionPropertyImpl(name, owner, receiver) +fun topLevelExtensionProperty(name: String, owner: KPackageImpl, receiver: Class): KTopLevelExtensionPropertyImpl = + KTopLevelExtensionPropertyImpl(name, owner, receiver) -fun mutableExtensionProperty(name: String, owner: KPackageImpl, receiver: Class): KMutableExtensionPropertyImpl = - KMutableExtensionPropertyImpl(name, owner, receiver) +fun mutableTopLevelExtensionProperty(name: String, owner: KPackageImpl, receiver: Class): KMutableTopLevelExtensionPropertyImpl = + KMutableTopLevelExtensionPropertyImpl(name, owner, receiver)