diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 1c1806566ba..591f878d981 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -2796,14 +2796,14 @@ public class ExpressionCodegen extends JetVisitor implem if (receiverParameter != null) { Type[] parameterTypes = new Type[] {JAVA_STRING_TYPE, K_PACKAGE_TYPE, getType(Class.class)}; factoryMethod = descriptor.isVar() - ? method("mutableTopLevelExtensionProperty", K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_TYPE, parameterTypes) - : method("topLevelExtensionProperty", K_TOP_LEVEL_EXTENSION_PROPERTY_TYPE, parameterTypes); + ? method("mutableTopLevelExtensionProperty", K_MUTABLE_PROPERTY1_TYPE, parameterTypes) + : method("topLevelExtensionProperty", K_PROPERTY1_TYPE, parameterTypes); } else { Type[] parameterTypes = new Type[] {JAVA_STRING_TYPE, K_PACKAGE_TYPE}; factoryMethod = descriptor.isVar() - ? method("mutableTopLevelVariable", K_MUTABLE_TOP_LEVEL_VARIABLE_TYPE, parameterTypes) - : method("topLevelVariable", K_TOP_LEVEL_VARIABLE_TYPE, parameterTypes); + ? method("mutableTopLevelVariable", K_MUTABLE_PROPERTY0_TYPE, parameterTypes) + : method("topLevelVariable", K_PROPERTY0_TYPE, parameterTypes); } return StackValue.operation(factoryMethod.getReturnType(), new Function1() { @@ -2828,8 +2828,8 @@ public class ExpressionCodegen extends JetVisitor implem @NotNull final ClassDescriptor containingClass ) { final Method factoryMethod = descriptor.isVar() - ? method("mutableMemberProperty", K_MUTABLE_MEMBER_PROPERTY_TYPE, JAVA_STRING_TYPE, K_CLASS_TYPE) - : method("memberProperty", K_MEMBER_PROPERTY_TYPE, JAVA_STRING_TYPE, K_CLASS_TYPE); + ? method("mutableMemberProperty", K_MUTABLE_PROPERTY1_TYPE, JAVA_STRING_TYPE, K_CLASS_TYPE) + : method("memberProperty", K_PROPERTY1_TYPE, JAVA_STRING_TYPE, K_CLASS_TYPE); return StackValue.operation(factoryMethod.getReturnType(), new Function1() { @Override diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java index fc1cdc5a981..853ec58a853 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java @@ -44,12 +44,10 @@ public class AsmTypes { public static final Type K_FUNCTION = reflect("KFunction"); - public static final Type K_MEMBER_PROPERTY_TYPE = reflect("KMemberProperty"); - public static final Type K_MUTABLE_MEMBER_PROPERTY_TYPE = reflect("KMutableMemberProperty"); - public static final Type K_TOP_LEVEL_VARIABLE_TYPE = reflect("KTopLevelVariable"); - public static final Type K_MUTABLE_TOP_LEVEL_VARIABLE_TYPE = reflect("KMutableTopLevelVariable"); - public static final Type K_TOP_LEVEL_EXTENSION_PROPERTY_TYPE = reflect("KTopLevelExtensionProperty"); - public static final Type K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_TYPE = reflect("KMutableTopLevelExtensionProperty"); + public static final Type K_PROPERTY0_TYPE = reflect("KProperty0"); + public static final Type K_PROPERTY1_TYPE = reflect("KProperty1"); + public static final Type K_MUTABLE_PROPERTY0_TYPE = reflect("KMutableProperty0"); + public static final Type K_MUTABLE_PROPERTY1_TYPE = reflect("KMutableProperty1"); public static final String REFLECTION = "kotlin/jvm/internal/Reflection"; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index dce191599b6..7e6679e91b2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -694,20 +694,15 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { return null; } - JetType receiverType = null; - if (extensionReceiver != null) { - receiverType = extensionReceiver.getType(); - } - else if (dispatchReceiver != null) { - receiverType = dispatchReceiver.getType(); - } - boolean isExtension = extensionReceiver != null; + JetType receiverType = extensionReceiver != null ? extensionReceiver.getType() : + dispatchReceiver != null ? dispatchReceiver.getType() : + null; if (descriptor instanceof FunctionDescriptor) { return createFunctionReferenceType(expression, context, (FunctionDescriptor) descriptor, receiverType); } else if (descriptor instanceof PropertyDescriptor) { - return createPropertyReferenceType(expression, context, (PropertyDescriptor) descriptor, receiverType, isExtension); + return createPropertyReferenceType(expression, context, (PropertyDescriptor) descriptor, receiverType); } else if (descriptor instanceof VariableDescriptor) { context.trace.report(UNSUPPORTED.on(reference, "References to variables aren't supported yet")); @@ -751,11 +746,11 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { @NotNull JetCallableReferenceExpression expression, @NotNull ExpressionTypingContext context, @NotNull PropertyDescriptor descriptor, - @Nullable JetType receiverType, - boolean isExtension + @Nullable JetType receiverType ) { - JetType type = components.reflectionTypes.getKPropertyType(Annotations.EMPTY, receiverType, descriptor.getType(), isExtension, - descriptor.isVar()); + JetType type = components.reflectionTypes.getKPropertyType( + Annotations.EMPTY, receiverType, descriptor.getType(), descriptor.isVar() + ); LocalVariableDescriptor localVariable = new LocalVariableDescriptor(context.scope.getContainingDeclaration(), Annotations.EMPTY, Name.special(""), diff --git a/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.kt b/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.kt index bb2102216e9..8d89bd89451 100644 --- a/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.kt +++ b/compiler/testData/codegen/boxAgainstJava/reflection/mapping/javaFields.kt @@ -10,8 +10,8 @@ fun box(): String { val s = J::s // Check that correct reflection objects are created - assert(i.javaClass.getSimpleName() == "KMemberPropertyImpl", "Fail i class") - assert(s.javaClass.getSimpleName() == "KMutableMemberPropertyImpl", "Fail s class") + assert(i.javaClass.getSimpleName() == "KProperty1Impl", "Fail i class") + assert(s.javaClass.getSimpleName() == "KMutableProperty1Impl", "Fail s class") // Check that no Method objects are created for such properties assert(i.javaGetter == null, "Fail i getter") @@ -33,8 +33,8 @@ fun box(): String { assert(a.s == "def", "Fail js access") // Check that valid Kotlin reflection objects are created by those Field objects - val ki = ji.kotlin as KMemberProperty - val ks = js.kotlin as KMutableMemberProperty + val ki = ji.kotlin as KProperty1 + val ks = js.kotlin as KMutableProperty1 assert(ki.get(a) == 42, "Fail ki get") assert(ks.get(a) == "def", "Fail ks get") ks.set(a, "ghi") diff --git a/compiler/testData/codegen/boxWithJava/reflection/kotlinPropertyInheritedInJava/K.kt b/compiler/testData/codegen/boxWithJava/reflection/kotlinPropertyInheritedInJava/K.kt index 7cb9078f898..71c941f1bca 100644 --- a/compiler/testData/codegen/boxWithJava/reflection/kotlinPropertyInheritedInJava/K.kt +++ b/compiler/testData/codegen/boxWithJava/reflection/kotlinPropertyInheritedInJava/K.kt @@ -11,7 +11,7 @@ fun box(): String { val j = J() val prop = J::prop - if (prop !is KMutableMemberProperty<*, *>) return "Fail instanceof" + if (prop !is KMutableProperty1<*, *>) return "Fail instanceof" if (prop.name != "prop") return "Fail name: ${prop.name}" if (prop.get(j) != ":(") return "Fail get before: ${prop[j]}" prop[j] = ":)" @@ -27,13 +27,13 @@ fun box(): String { val prop2 = klass.properties.firstOrNull { it.name == "prop" } ?: "Fail: no 'prop' property in properties" if (prop != prop2) return "Fail: property references from :: and from properties differ: $prop != $prop2" - if (prop2 !is KMutableMemberProperty<*, *>) return "Fail instanceof 2" - (prop2 as KMutableMemberProperty).set(j, "::)") + if (prop2 !is KMutableProperty1<*, *>) return "Fail instanceof 2" + (prop2 as KMutableProperty1).set(j, "::)") if (prop.get(j) != "::)") return "Fail get after 2: ${prop[j]}" val ext = klass.extensionProperties.firstOrNull { it.name == "ext" } ?: "Fail: no 'ext' property in extensionProperties" - ext as KMemberExtensionProperty + ext as KProperty2 val fortyTwo = ext.get(j, 42) if (fortyTwo != 42) return "Fail ext get: $fortyTwo" diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/genericProperty.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/genericProperty.kt index d5e2dd8f1d2..fae016e0a82 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/property/genericProperty.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/genericProperty.kt @@ -1,6 +1,6 @@ //For KT-6020 -import kotlin.reflect.KMemberProperty -import kotlin.reflect.KMutableMemberProperty +import kotlin.reflect.KProperty1 +import kotlin.reflect.KMutableProperty1 class Value(var value: T = null as T, var text: String? = null) @@ -8,7 +8,7 @@ val Value.additionalText by DVal(Value::text) //works val Value.additionalValue by DVal(Value::value) //not work -class DVal>(val kmember: P) { +class DVal>(val kmember: P) { fun get(t: T, p: PropertyMetadata): R { return kmember.get(t) } @@ -17,4 +17,4 @@ class DVal>(val kmember: P) { fun box(): String { val p = Value("O", "K") return p.additionalValue + p.additionalText -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/kClassInstanceIsInitializedFirst.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/kClassInstanceIsInitializedFirst.kt index db87afa64e7..5ce636926d5 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/property/kClassInstanceIsInitializedFirst.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/kClassInstanceIsInitializedFirst.kt @@ -1,8 +1,8 @@ -import kotlin.reflect.KMemberProperty +import kotlin.reflect.KProperty1 class A { companion object { - val ref: KMemberProperty = A::foo + val ref: KProperty1 = A::foo } val foo: String = "OK" diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVal.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVal.kt index c6ed7d44c65..99f6d3ee6d9 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVal.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVal.kt @@ -1,11 +1,11 @@ import kotlin.reflect.IllegalPropertyAccessException -import kotlin.reflect.KMemberProperty +import kotlin.reflect.KProperty1 import kotlin.reflect.jvm.accessible class Result { private val value = "OK" - fun ref(): KMemberProperty = ::value + fun ref(): KProperty1 = ::value } fun box(): String { diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVar.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVar.kt index f8f4d8226ca..0d5ea464a93 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVar.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/property/privateClassVar.kt @@ -1,11 +1,11 @@ import kotlin.reflect.IllegalPropertyAccessException -import kotlin.reflect.KMutableMemberProperty +import kotlin.reflect.KMutableProperty1 import kotlin.reflect.jvm.accessible class A { private var value = 0 - fun ref(): KMutableMemberProperty = ::value + fun ref(): KMutableProperty1 = ::value } fun box(): String { diff --git a/compiler/testData/codegen/boxWithStdlib/platformStatic/callableRef.kt b/compiler/testData/codegen/boxWithStdlib/platformStatic/callableRef.kt index a02509760fb..346de4cd500 100644 --- a/compiler/testData/codegen/boxWithStdlib/platformStatic/callableRef.kt +++ b/compiler/testData/codegen/boxWithStdlib/platformStatic/callableRef.kt @@ -4,7 +4,7 @@ object A { val b: String = "OK" - platformStatic val c: String = "OK" + platformStatic var c: String = "Fail" platformStatic fun test1() : String { return b @@ -36,6 +36,8 @@ fun box(): String { if ((A::test4)(A) != "1OK") return "fail 4" + (A::c).set(A, "OK") + if (((A::c).get(A)) != "OK") return "fail 5" return "OK" diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/extensionPropertyReceiverToString.kt b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/extensionPropertyReceiverToString.kt index bb1915fb389..5f4f70ce558 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/extensionPropertyReceiverToString.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/extensionPropertyReceiverToString.kt @@ -1,7 +1,7 @@ -import kotlin.reflect.KExtensionProperty +import kotlin.reflect.KProperty1 import kotlin.test.assertEquals -fun check(expected: String, p: KExtensionProperty<*, *>) { +fun check(expected: String, p: KProperty1<*, *>) { var s = p.toString() // Strip "val" or "var" diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/properties/callPrivatePropertyFromGetProperties.kt b/compiler/testData/codegen/boxWithStdlib/reflection/properties/callPrivatePropertyFromGetProperties.kt index 59589294b1c..b11fc5e5dd8 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/properties/callPrivatePropertyFromGetProperties.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/properties/callPrivatePropertyFromGetProperties.kt @@ -4,7 +4,7 @@ import kotlin.reflect.jvm.* class K(private val value: String) fun box(): String { - val p = javaClass().kotlin.properties.single() as KMemberProperty + val p = javaClass().kotlin.properties.single() as KProperty1 try { return p.get(K("Fail: private property should not be accessible by default")) diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/properties/genericClassLiteralPropertyReceiverIsStar.kt b/compiler/testData/codegen/boxWithStdlib/reflection/properties/genericClassLiteralPropertyReceiverIsStar.kt index c87de4331d0..e97248ae99b 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/properties/genericClassLiteralPropertyReceiverIsStar.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/properties/genericClassLiteralPropertyReceiverIsStar.kt @@ -1,11 +1,10 @@ -import kotlin.reflect.KMemberProperty +import kotlin.reflect.KProperty1 class A { val result = "OK" } fun box(): String { - val k = A::class.properties.single() - k : KMemberProperty, *> + val k : KProperty1, *> = A::class.properties.single() return k.get(A()) as String } diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/properties/getExtensionPropertiesMutableVsReadonly.kt b/compiler/testData/codegen/boxWithStdlib/reflection/properties/getExtensionPropertiesMutableVsReadonly.kt index 76b17b83f51..2ebf098af3c 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/properties/getExtensionPropertiesMutableVsReadonly.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/properties/getExtensionPropertiesMutableVsReadonly.kt @@ -1,5 +1,5 @@ import kotlin.reflect.jvm.kotlin -import kotlin.reflect.KMutableMemberExtensionProperty +import kotlin.reflect.KMutableProperty2 var storage = "before" @@ -15,12 +15,12 @@ class A { fun box(): String { val props = javaClass().kotlin.extensionProperties val readonly = props.single { it.name == "readonly" } - assert(readonly !is KMutableMemberExtensionProperty) { "Fail 1: $readonly" } + assert(readonly !is KMutableProperty2) { "Fail 1: $readonly" } val mutable = props.single { it.name == "mutable" } - assert(mutable is KMutableMemberExtensionProperty) { "Fail 2: $mutable" } + assert(mutable is KMutableProperty2) { "Fail 2: $mutable" } val a = A() - mutable as KMutableMemberExtensionProperty + mutable as KMutableProperty2 assert(mutable[a, ""] == "before") { "Fail 3: ${mutable.get(a, "")}" } mutable[a, ""] = "OK" return mutable.get(a, "") diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/properties/getPropertiesMutableVsReadonly.kt b/compiler/testData/codegen/boxWithStdlib/reflection/properties/getPropertiesMutableVsReadonly.kt index 435243a6938..fb764361b30 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/properties/getPropertiesMutableVsReadonly.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/properties/getPropertiesMutableVsReadonly.kt @@ -1,5 +1,5 @@ import kotlin.reflect.jvm.kotlin -import kotlin.reflect.KMutableMemberProperty +import kotlin.reflect.KMutableProperty1 class A(val readonly: String) { var mutable: String = "before" @@ -8,12 +8,12 @@ class A(val readonly: String) { fun box(): String { val props = javaClass().kotlin.properties val readonly = props.single { it.name == "readonly" } - assert(readonly !is KMutableMemberProperty) { "Fail 1: $readonly" } + assert(readonly !is KMutableProperty1) { "Fail 1: $readonly" } val mutable = props.single { it.name == "mutable" } - assert(mutable is KMutableMemberProperty) { "Fail 2: $mutable" } + assert(mutable is KMutableProperty1) { "Fail 2: $mutable" } val a = A("") - mutable as KMutableMemberProperty + mutable as KMutableProperty1 assert(mutable[a] == "before") { "Fail 3: ${mutable.get(a)}" } mutable[a] = "OK" return mutable.get(a) diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/properties/memberAndMemberExtensionWithSameName.kt b/compiler/testData/codegen/boxWithStdlib/reflection/properties/memberAndMemberExtensionWithSameName.kt index b194d12e01c..a60072738bd 100644 --- a/compiler/testData/codegen/boxWithStdlib/reflection/properties/memberAndMemberExtensionWithSameName.kt +++ b/compiler/testData/codegen/boxWithStdlib/reflection/properties/memberAndMemberExtensionWithSameName.kt @@ -1,6 +1,6 @@ import kotlin.reflect.jvm.kotlin -import kotlin.reflect.KMemberProperty -import kotlin.reflect.KMemberExtensionProperty +import kotlin.reflect.KProperty1 +import kotlin.reflect.KProperty2 class A { val foo: String = "member" @@ -9,15 +9,15 @@ class A { fun box(): String { run { - val foo: KMemberProperty = javaClass().kotlin.properties.single() + val foo: KProperty1 = javaClass().kotlin.properties.single() assert(foo.name == "foo") { "Fail name: $foo (${foo.name})" } assert(foo.get(A()) == "member") { "Fail value: ${foo[A()]}" } } run { - val foo: KMemberExtensionProperty = javaClass().kotlin.extensionProperties.single() + val foo: KProperty2 = javaClass().kotlin.extensionProperties.single() assert(foo.name == "foo") { "Fail name: $foo (${foo.name})" } - foo as KMemberExtensionProperty + foo as KProperty2 assert(foo.get(A(), Unit) == "extension") { "Fail value: ${foo[A(), Unit]}" } } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/abstractPropertyViaSubclasses.kt b/compiler/testData/diagnostics/tests/callableReference/property/abstractPropertyViaSubclasses.kt index 0f5adfb8e4b..36ec672d567 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/abstractPropertyViaSubclasses.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/abstractPropertyViaSubclasses.kt @@ -1,6 +1,6 @@ // !CHECK_TYPE -import kotlin.reflect.KMemberProperty +import kotlin.reflect.KProperty1 interface Base { val x: Any @@ -20,17 +20,17 @@ class C : B() { fun test() { val base = Base::x - checkSubtype>(base) + checkSubtype>(base) checkSubtype(base.get(A())) checkSubtype(base.get(B())) checkSubtype(base.get(C())) val a = A::x - checkSubtype>(a) + checkSubtype>(a) checkSubtype(a.get(A())) checkSubtype(a.get(B())) val b = B::x - checkSubtype>(b) + checkSubtype>(b) checkSubtype(b.get(C())) } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/accessViaSubclass.kt b/compiler/testData/diagnostics/tests/callableReference/property/accessViaSubclass.kt index 44bba28e333..ec5c86975b4 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/accessViaSubclass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/accessViaSubclass.kt @@ -1,6 +1,6 @@ // !CHECK_TYPE -import kotlin.reflect.KMemberProperty +import kotlin.reflect.KProperty1 open class Base { val foo: Int = 42 @@ -10,6 +10,6 @@ open class Derived : Base() fun test() { val o = Base::foo - checkSubtype>(o) + checkSubtype>(o) checkSubtype(o.get(Derived())) } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/classFromClass.kt b/compiler/testData/diagnostics/tests/callableReference/property/classFromClass.kt index 65ef1ee9ca2..b5d3570a170 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/classFromClass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/classFromClass.kt @@ -6,7 +6,7 @@ class A(var g: A) { val f: Int = 0 fun test() { - val fRef: KMemberProperty = ::f - val gRef: KMutableMemberProperty = ::g + val fRef: KProperty1 = ::f + val gRef: KMutableProperty1 = ::g } } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/extensionFromClass.kt b/compiler/testData/diagnostics/tests/callableReference/property/extensionFromClass.kt index ac92c4a0dbc..e28b2c4c6d2 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/extensionFromClass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/extensionFromClass.kt @@ -4,8 +4,8 @@ import kotlin.reflect.* class A { fun test() { - val fooRef: KExtensionProperty = ::foo - val barRef: KMutableExtensionProperty = ::bar + val fooRef: KProperty1 = ::foo + val barRef: KMutableProperty1 = ::bar } } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/extensionFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/property/extensionFromTopLevel.kt index afb67c72591..6da7eaec881 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/extensionFromTopLevel.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/extensionFromTopLevel.kt @@ -12,18 +12,14 @@ var Int.meaning: Long fun test() { val f = String::countCharacters - checkSubtype>(f) - checkSubtype>(f) - checkSubtype>(f) + checkSubtype>(f) + checkSubtype>(f) checkSubtype(f.get("abc")) f.set("abc", 0) val g = Int::meaning - checkSubtype>(g) - checkSubtype>(g) - checkSubtype>(g) - checkSubtype>(g) + checkSubtype>(g) checkSubtype(g.get(0)) g.set(1, 0L) } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/genericClass.kt b/compiler/testData/diagnostics/tests/callableReference/property/genericClass.kt index a741e69b357..3c1181248c1 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/genericClass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/genericClass.kt @@ -1,6 +1,6 @@ // !CHECK_TYPE -import kotlin.reflect.KMemberProperty +import kotlin.reflect.KProperty1 class A(val t: T) { val foo: T = t @@ -8,9 +8,9 @@ class A(val t: T) { fun bar() { val x = A::foo - checkSubtype, String>>(x) - checkSubtype, Any?>>(x) + checkSubtype, String>>(x) + checkSubtype, Any?>>(x) val y = A<*>::foo - checkSubtype, Any?>>(y) + checkSubtype, Any?>>(y) } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/javaInstanceField.kt b/compiler/testData/diagnostics/tests/callableReference/property/javaInstanceField.kt index 7304ad21fdf..901c2f1d084 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/javaInstanceField.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/javaInstanceField.kt @@ -17,10 +17,10 @@ public class JavaClass { import kotlin.reflect.* fun test() { - val pubFinRef: KMemberProperty = JavaClass::publicFinal - val pubMutRef: KMutableMemberProperty = JavaClass::publicMutable - val protFinRef: KMemberProperty = JavaClass::protectedFinal - val protMutRef: KMutableMemberProperty = JavaClass::protectedMutable - val privFinRef: KMemberProperty = JavaClass::privateFinal - val privMutRef: KMutableMemberProperty = JavaClass::privateMutable + val pubFinRef: KProperty1 = JavaClass::publicFinal + val pubMutRef: KMutableProperty1 = JavaClass::publicMutable + val protFinRef: KProperty1 = JavaClass::protectedFinal + val protMutRef: KMutableProperty1 = JavaClass::protectedMutable + val privFinRef: KProperty1 = JavaClass::privateFinal + val privMutRef: KMutableProperty1 = JavaClass::privateMutable } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/javaStaticFieldViaImport.kt b/compiler/testData/diagnostics/tests/callableReference/property/javaStaticFieldViaImport.kt index 1d3017e8e4a..6109457f932 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/javaStaticFieldViaImport.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/javaStaticFieldViaImport.kt @@ -1,4 +1,3 @@ -// !CHECK_TYPE // !DIAGNOSTICS:-UNUSED_VARIABLE // FILE: JavaClass.java @@ -20,8 +19,8 @@ import JavaClass.* import kotlin.reflect.* fun test() { - val pubFinRef: KTopLevelProperty = ::publicFinal - val pubMutRef: KMutableTopLevelProperty = ::publicMutable + val pubFinRef: KProperty0 = ::publicFinal + val pubMutRef: KMutableProperty0 = ::publicMutable val protFinRef: KProperty = ::protectedFinal val protMutRef: KMutableProperty = ::protectedMutable val privFinRef: KProperty = ::privateFinal diff --git a/compiler/testData/diagnostics/tests/callableReference/property/kt7564.kt b/compiler/testData/diagnostics/tests/callableReference/property/kt7564.kt index acbf68eb5d4..26295d99f72 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/kt7564.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/kt7564.kt @@ -6,7 +6,7 @@ class A(var g: A) { val f: Int = 0 fun test() { - checkSubtype>(::f) - checkSubtype>(::g) + checkSubtype>(::f) + checkSubtype>(::g) } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.kt b/compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.kt index f9c917d5be8..2354ecf0ba7 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.kt @@ -1,10 +1,10 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -import kotlin.reflect.KMemberProperty +import kotlin.reflect.KProperty1 class TestClass(var prop: Int) open class OtherClass -fun OtherClass.test(prop: KMemberProperty): Unit = throw Exception() +fun OtherClass.test(prop: KProperty1): Unit = throw Exception() class OtherClass2: OtherClass() { val result = test(TestClass::result) } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.txt b/compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.txt index d99d7aa2d2c..013fce270d6 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.txt +++ b/compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.txt @@ -1,6 +1,6 @@ package -internal fun OtherClass.test(/*0*/ prop: kotlin.reflect.KMemberProperty): kotlin.Unit +internal fun OtherClass.test(/*0*/ prop: kotlin.reflect.KProperty1): kotlin.Unit internal open class OtherClass { public constructor OtherClass() diff --git a/compiler/testData/diagnostics/tests/callableReference/property/memberFromExtension.kt b/compiler/testData/diagnostics/tests/callableReference/property/memberFromExtension.kt index 24b84678ee1..32958ec26ab 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/memberFromExtension.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/memberFromExtension.kt @@ -15,9 +15,9 @@ fun A.test() { val y = ::bar val z = ::self - checkSubtype>(x) - checkSubtype>(y) - checkSubtype>(z) + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) y.set(z.get(A()), x.get(A()).toString()) } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/memberFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/property/memberFromTopLevel.kt index 14be337f739..0afa68cc50a 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/memberFromTopLevel.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/memberFromTopLevel.kt @@ -10,16 +10,16 @@ class A { fun test() { val p = A::foo - checkSubtype>(p) - checkSubtype>(p) + checkSubtype>(p) + checkSubtype>(p) checkSubtype(p.get(A())) p.get() p.set(A(), 239) val q = A::bar - checkSubtype>(q) - checkSubtype>(q) + checkSubtype>(q) + checkSubtype>(q) checkSubtype(q.get(A())) q.set(A(), "q") } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/samePriorityForFunctionsAndProperties.kt b/compiler/testData/diagnostics/tests/callableReference/property/samePriorityForFunctionsAndProperties.kt index 2065b87f8d4..6bedc84c041 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/samePriorityForFunctionsAndProperties.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/samePriorityForFunctionsAndProperties.kt @@ -1,6 +1,6 @@ // !CHECK_TYPE -import kotlin.reflect.KMemberProperty +import kotlin.reflect.KProperty1 class C { val baz: Int = 12 @@ -9,5 +9,5 @@ class C { fun Int.baz() {} fun test() { - C::baz checkType { _>() } -} \ No newline at end of file + C::baz checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/property/topLevelFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/property/topLevelFromTopLevel.kt index d9fcb90c7ff..ce7ccf72c9d 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/topLevelFromTopLevel.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/topLevelFromTopLevel.kt @@ -7,12 +7,9 @@ val y: String get() = "y" fun testX() { val xx = ::x - checkSubtype>(xx) - checkSubtype>(xx) - checkSubtype>(xx) - checkSubtype>(xx) + checkSubtype>(xx) + checkSubtype>(xx) checkSubtype>(xx) - checkSubtype>(xx) checkSubtype>(xx) checkSubtype>(xx) @@ -23,8 +20,8 @@ fun testX() { fun testY() { val yy = ::y - checkSubtype>(yy) - checkSubtype>(yy) + checkSubtype>(yy) + checkSubtype>(yy) checkSubtype>(yy) checkSubtype>(yy) checkSubtype>(yy) diff --git a/core/builtins/src/kotlin/reflect/KClass.kt b/core/builtins/src/kotlin/reflect/KClass.kt index a12536a465a..965a5470f47 100644 --- a/core/builtins/src/kotlin/reflect/KClass.kt +++ b/core/builtins/src/kotlin/reflect/KClass.kt @@ -41,10 +41,10 @@ public interface KClass : KDeclarationContainer { /** * Returns non-extension properties declared in this class and all of its superclasses. */ - public val properties: Collection> + public val properties: Collection> /** * Returns extension properties declared in this class and all of its superclasses. */ - public val extensionProperties: Collection> + public val extensionProperties: Collection> } diff --git a/core/builtins/src/kotlin/reflect/KExtensionProperty.kt b/core/builtins/src/kotlin/reflect/KExtensionProperty.kt deleted file mode 100644 index 817e1c3c216..00000000000 --- a/core/builtins/src/kotlin/reflect/KExtensionProperty.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2010-2015 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 - -/** - * Represents an extension property. - * See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/extensions.html#extension-properties) - * for more information. - * - * @param E the type of the extension receiver. - * @param R the type of the property. - */ -public interface KExtensionProperty : KProperty { - /** - * Returns the current value of the property. - * - * @param receiver the instance of the extension receiver. - */ - public fun get(receiver: E): R -} - -/** - * Represents an extension property declared as a `var`. - */ -public interface KMutableExtensionProperty : KExtensionProperty, KMutableProperty { - /** - * Modifies the value of the property. - * - * @param receiver the instance of the extension receiver. - * @param value the new value to be assigned to this property. - */ - public fun set(receiver: E, value: R) -} diff --git a/core/builtins/src/kotlin/reflect/KMemberExtensionProperty.kt b/core/builtins/src/kotlin/reflect/KMemberExtensionProperty.kt deleted file mode 100644 index a99c19a4f9f..00000000000 --- a/core/builtins/src/kotlin/reflect/KMemberExtensionProperty.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2010-2015 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 - -/** - * Represents an extension property declared in a class. - * See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/extensions.html#extension-properties) - * for more information. - * - * @param T the type of the instance which should be used to obtain the value of the property. - * Must be derived either from a class declaring this property, or any subclass of that class. - * @param E the type of the extension receiver. - * @param R the type of the property. - */ -public interface KMemberExtensionProperty : KProperty { - /** - * Returns the current value of the property. - * - * @param instance the instance to obtain the value of the property from. - * @param extensionReceiver the instance of the extension receiver. - */ - public fun get(instance: T, extensionReceiver: E): R -} - -/** - * Represents a `var` extension property declared in a class. - */ -public interface KMutableMemberExtensionProperty : KMemberExtensionProperty, KMutableProperty { - /** - * Modifies the value of the property. - * - * @param instance the instance to obtain the value of the property from. - * @param extensionReceiver the instance of the extension receiver. - * @param value the new value to be assigned to this property. - */ - public fun set(instance: T, extensionReceiver: E, value: R) -} diff --git a/core/builtins/src/kotlin/reflect/KMemberProperty.kt b/core/builtins/src/kotlin/reflect/KMemberProperty.kt deleted file mode 100644 index 58c4d9f2ab1..00000000000 --- a/core/builtins/src/kotlin/reflect/KMemberProperty.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2010-2015 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 - -/** - * Represents a property declared in a class. - * - * @param T the type of the instance which should be used to obtain the value of the property. - * Must be derived either from a class declaring this property, or any subclass of that class. - * @param R the type of the property. - */ -public interface KMemberProperty : KProperty { - /** - * Returns the current value of the property. - * - * @param instance the instance to obtain the value of the property from. - */ - public fun get(instance: T): R -} - -/** - * Represents a `var` property declared in a class. - */ -public interface KMutableMemberProperty : KMemberProperty, KMutableProperty { - /** - * Modifies the value of the property. - * - * @param instance the instance to obtain the value of the property from. - * @param value the new value to be assigned to this property. - */ - public fun set(instance: T, value: R) -} diff --git a/core/builtins/src/kotlin/reflect/KProperty.kt b/core/builtins/src/kotlin/reflect/KProperty.kt index 10f4a3508a2..b068eff3f55 100644 --- a/core/builtins/src/kotlin/reflect/KProperty.kt +++ b/core/builtins/src/kotlin/reflect/KProperty.kt @@ -30,3 +30,97 @@ public interface KProperty : KCallable * Represents a property declared as a `var`. */ public interface KMutableProperty : KProperty + + +/** + * Represents a property without any kind of receiver. + * Such property is either originally declared in a receiverless context such as a package, + * or has the receiver bound to it. + */ +public interface KProperty0 : KProperty { + /** + * Returns the current value of the property. + */ + public fun get(): R +} + +/** + * Represents a `var`-property without any kind of receiver. + */ +public interface KMutableProperty0 : KProperty0, KMutableProperty { + /** + * Modifies the value of the property. + * + * @param value the new value to be assigned to this property. + */ + public fun set(value: R) +} + + +/** + * Represents a property, operations on which take one receiver as a parameter. + * + * @param T the type of the receiver which should be used to obtain the value of the property. + * @param R the type of the property. + */ +public interface KProperty1 : KProperty { + /** + * Returns the current value of the property. + * + * @param receiver the receiver which is used to obtain the value of the property. + * For example, it should be a class instance if this is a member property of that class, + * or an extension receiver if this is a top level extension property. + */ + public fun get(receiver: T): R +} + +/** + * Represents a `var`-property, operations on which take one receiver as a parameter. + */ +public interface KMutableProperty1 : KProperty1, KMutableProperty { + /** + * Modifies the value of the property. + * + * @param receiver the receiver which is used to modify the value of the property. + * For example, it should be a class instance if this is a member property of that class, + * or an extension receiver if this is a top level extension property. + * @param value the new value to be assigned to this property. + */ + public fun set(receiver: T, value: R) +} + + +/** + * Represents a property, operations on which take two receivers as parameters, + * such as an extension property declared in a class. + * + * @param D the type of the first receiver. In case of the extension property in a class this is + * the type of the declaring class of the property, or any subclass of that class. + * @param E the type of the second receiver. In case of the extension property in a class this is + * the type of the extension receiver. + * @param R the type of the property. + */ +public interface KProperty2 : KProperty { + /** + * Returns the current value of the property. In case of the extension property in a class, + * the instance of the class should be passed first and the instance of the extension receiver second. + * + * @param receiver1 the instance of the first receiver. + * @param receiver2 the instance of the second receiver. + */ + public fun get(receiver1: D, receiver2: E): R +} + +/** + * Represents a `var`-property, operations on which take two receivers as parameters. + */ +public interface KMutableProperty2 : KProperty2, KMutableProperty { + /** + * Modifies the value of the property. + * + * @param receiver1 the instance of the first receiver. + * @param receiver2 the instance of the second receiver. + * @param value the new value to be assigned to this property. + */ + public fun set(receiver1: D, receiver2: E, value: R) +} diff --git a/core/builtins/src/kotlin/reflect/KTopLevelExtensionProperty.kt b/core/builtins/src/kotlin/reflect/KTopLevelExtensionProperty.kt deleted file mode 100644 index 3381b037182..00000000000 --- a/core/builtins/src/kotlin/reflect/KTopLevelExtensionProperty.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2010-2015 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 - -/** - * Represents an extension property declared in a package. - */ -public interface KTopLevelExtensionProperty : KExtensionProperty, KTopLevelProperty - -/** - * Represents a package extension property declared as a `var`. - */ -public interface KMutableTopLevelExtensionProperty : KTopLevelExtensionProperty, KMutableExtensionProperty, KMutableTopLevelProperty diff --git a/core/builtins/src/kotlin/reflect/KTopLevelProperty.kt b/core/builtins/src/kotlin/reflect/KTopLevelProperty.kt deleted file mode 100644 index 597e831325f..00000000000 --- a/core/builtins/src/kotlin/reflect/KTopLevelProperty.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2010-2015 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 - -/** - * Represents a property declared in a package. - */ -public interface KTopLevelProperty : KProperty - -/** - * Represents a package property declared as a `var`. - */ -public interface KMutableTopLevelProperty : KTopLevelProperty, KMutableProperty diff --git a/core/builtins/src/kotlin/reflect/KTopLevelVariable.kt b/core/builtins/src/kotlin/reflect/KTopLevelVariable.kt deleted file mode 100644 index 39b8856ac66..00000000000 --- a/core/builtins/src/kotlin/reflect/KTopLevelVariable.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2010-2015 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 - -/** - * Represents a variable declared in a package. - */ -public interface KTopLevelVariable : KVariable, KTopLevelProperty - -/** - * Represents a package variable declared as a `var`. - */ -public interface KMutableTopLevelVariable : KTopLevelVariable, KMutableVariable, KMutableTopLevelProperty diff --git a/core/builtins/src/kotlin/reflect/KVariable.kt b/core/builtins/src/kotlin/reflect/KVariable.kt deleted file mode 100644 index 100e149a5c0..00000000000 --- a/core/builtins/src/kotlin/reflect/KVariable.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2010-2015 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 - -/** - * Represents a property without any kind of receiver. - * Such property is either originally declared in a receiverless context such as a package, - * or has the receiver bound to it. - */ -public interface KVariable : KProperty { - /** - * Returns the current value of the variable. - */ - public fun get(): R -} - -/** - * Represents a variable declared as a `var`. - */ -public interface KMutableVariable : KVariable, KMutableProperty { - /** - * Modifies the value of the variable. - * - * @param value the new value to be assigned to this variable. - */ - public fun set(value: R) -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt index 71539e305b8..5b02b53cd56 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt @@ -50,12 +50,10 @@ public class ReflectionTypes(private val module: ModuleDescriptor) { public fun getKFunction(n: Int): ClassDescriptor = find("KFunction$n") public val kClass: 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 kTopLevelExtensionProperty: ClassDescriptor by ClassLookup - public val kMutableTopLevelExtensionProperty: ClassDescriptor by ClassLookup + public val kProperty0: ClassDescriptor by ClassLookup + public val kProperty1: ClassDescriptor by ClassLookup + public val kMutableProperty0: ClassDescriptor by ClassLookup + public val kMutableProperty1: ClassDescriptor by ClassLookup public fun getKClassType(annotations: Annotations, type: JetType): JetType { val descriptor = kClass @@ -84,23 +82,18 @@ public class ReflectionTypes(private val module: ModuleDescriptor) { return JetTypeImpl(annotations, classDescriptor.getTypeConstructor(), false, arguments, classDescriptor.getMemberScope(arguments)) } - public fun getKPropertyType( - annotations: Annotations, - receiverType: JetType?, - returnType: JetType, - extensionProperty: Boolean, - mutable: Boolean - ): JetType { - val classDescriptor = if (mutable) when { - extensionProperty -> kMutableTopLevelExtensionProperty - receiverType != null -> kMutableMemberProperty - else -> kMutableTopLevelVariable - } - else when { - extensionProperty -> kTopLevelExtensionProperty - receiverType != null -> kMemberProperty - else -> kTopLevelVariable - } + public fun getKPropertyType(annotations: Annotations, receiverType: JetType?, returnType: JetType, mutable: Boolean): JetType { + val classDescriptor = + when { + receiverType != null -> when { + mutable -> kMutableProperty1 + else -> kProperty1 + } + else -> when { + mutable -> kMutableProperty0 + else -> kProperty0 + } + } if (ErrorUtils.isError(classDescriptor)) { return classDescriptor.getDefaultType() diff --git a/core/reflection.jvm/src/kotlin/reflect/KClassExtensions.kt b/core/reflection.jvm/src/kotlin/reflect/KClassExtensions.kt index 30d73543926..ddddc04a511 100644 --- a/core/reflection.jvm/src/kotlin/reflect/KClassExtensions.kt +++ b/core/reflection.jvm/src/kotlin/reflect/KClassExtensions.kt @@ -21,11 +21,11 @@ import kotlin.reflect.jvm.internal.KClassImpl /** * Returns non-extension properties declared in this class. */ -public val KClass.declaredProperties: Collection> +public val KClass.declaredProperties: Collection> get() = (this as KClassImpl).getProperties(declared = true) /** * Returns extension properties declared in this class. */ -public val KClass.declaredExtensionProperties: Collection> +public val KClass.declaredExtensionProperties: Collection> get() = (this as KClassImpl).getExtensionProperties(declared = true) diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KCallableImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KCallableImpl.kt index eb4460b5f53..d98e816c3d7 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KCallableImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KCallableImpl.kt @@ -18,4 +18,4 @@ package kotlin.reflect.jvm.internal import kotlin.reflect.KCallable -trait KCallableImpl : KCallable +interface KCallableImpl : KCallable diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt index 5c534a70b9c..73c98ce0a1a 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt @@ -75,22 +75,22 @@ class KClassImpl(override val jClass: Class) : KCallableContainerImpl(), K } } - override val properties: Collection> + override val properties: Collection> get() = getProperties(declared = false) - override val extensionProperties: Collection> + override val extensionProperties: Collection> get() = getExtensionProperties(declared = false) - fun getProperties(declared: Boolean): Collection> = + fun getProperties(declared: Boolean): Collection> = getProperties(extension = false, declared = declared) { descriptor -> - if (descriptor.isVar()) KMutableMemberPropertyImpl(this, descriptor) - else KMemberPropertyImpl(this, descriptor) + if (descriptor.isVar()) KMutableProperty1Impl(this, descriptor) + else KProperty1Impl(this, descriptor) } - fun getExtensionProperties(declared: Boolean): Collection> = + fun getExtensionProperties(declared: Boolean): Collection> = getProperties(extension = true, declared = declared) { descriptor -> - if (descriptor.isVar()) KMutableMemberExtensionPropertyImpl(this, descriptor) - else KMemberExtensionPropertyImpl(this, descriptor) + if (descriptor.isVar()) KMutableProperty2Impl(this, descriptor) + else KProperty2Impl(this, descriptor) } private fun

> getProperties(extension: Boolean, declared: Boolean, create: (PropertyDescriptor) -> P): Collection

= @@ -104,11 +104,11 @@ class KClassImpl(override val jClass: Class) : KCallableContainerImpl(), K .map(create) .toList() - fun memberProperty(name: String): KMemberProperty = - KMemberPropertyImpl(this, name) + fun memberProperty(name: String): KProperty1 = + KProperty1Impl(this, name, null) - fun mutableMemberProperty(name: String): KMutableMemberProperty = - KMutableMemberPropertyImpl(this, name) + fun mutableMemberProperty(name: String): KMutableProperty1 = + KMutableProperty1Impl(this, name, null) override fun equals(other: Any?): Boolean = other is KClassImpl<*> && jClass == other.jClass diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KMemberPropertyImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KMemberPropertyImpl.kt deleted file mode 100644 index 5a2522d63f5..00000000000 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KMemberPropertyImpl.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2010-2015 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.jvm.internal - -import org.jetbrains.kotlin.descriptors.PropertyDescriptor -import kotlin.reflect.IllegalPropertyAccessException -import kotlin.reflect.KMemberProperty -import kotlin.reflect.KMutableMemberProperty - -open class KMemberPropertyImpl : DescriptorBasedProperty, KMemberProperty, KPropertyImpl { - constructor(container: KClassImpl, name: String) : super(container, name, null) - - constructor(container: KClassImpl, descriptor: PropertyDescriptor) : super(container, descriptor) - - override val name: String get() = descriptor.getName().asString() - - override fun get(instance: T): R { - try { - val getter = getter - @suppress("UNCHECKED_CAST") - return if (getter != null) getter(instance) as R else field!!.get(instance) as R - } - catch (e: IllegalAccessException) { - throw IllegalPropertyAccessException(e) - } - } -} - - -class KMutableMemberPropertyImpl : KMemberPropertyImpl, KMutableMemberProperty, KMutablePropertyImpl { - constructor(container: KClassImpl, name: String) : super(container, name) - - constructor(container: KClassImpl, descriptor: PropertyDescriptor) : super(container, descriptor) - - override fun set(instance: T, value: R) { - try { - val setter = setter - if (setter != null) setter(instance, value) else field!!.set(instance, value) - } - catch (e: IllegalAccessException) { - throw IllegalPropertyAccessException(e) - } - } -} diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPackageImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPackageImpl.kt index 28a9a48a9ca..22c389274ab 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPackageImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPackageImpl.kt @@ -31,17 +31,17 @@ class KPackageImpl(override val jClass: Class<*>) : KCallableContainerImpl(), KP override val scope: JetScope get() = descriptor.memberScope - fun topLevelVariable(name: String): KTopLevelVariable<*> = - KTopLevelVariableImpl(this, name) + fun topLevelVariable(name: String): KProperty0<*> = + KProperty0Impl(this, name) - fun mutableTopLevelVariable(name: String): KMutableTopLevelVariable<*> = - KMutableTopLevelVariableImpl(this, name) + fun mutableTopLevelVariable(name: String): KMutableProperty0<*> = + KMutableProperty0Impl(this, name) - fun topLevelExtensionProperty(name: String, receiver: Class): KTopLevelExtensionProperty = - KTopLevelExtensionPropertyImpl(this, name, receiver) + fun topLevelExtensionProperty(name: String, receiver: Class): KProperty1 = + KProperty1Impl(this, name, receiver) - fun mutableTopLevelExtensionProperty(name: String, receiver: Class): KMutableTopLevelExtensionProperty = - KMutableTopLevelExtensionPropertyImpl(this, name, receiver) + fun mutableTopLevelExtensionProperty(name: String, receiver: Class): KMutableProperty1 = + KMutableProperty1Impl(this, name, receiver) override fun equals(other: Any?): Boolean = other is KPackageImpl && jClass == other.jClass diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KTopLevelVariableImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KProperty0Impl.kt similarity index 79% rename from core/reflection.jvm/src/kotlin/reflect/jvm/internal/KTopLevelVariableImpl.kt rename to core/reflection.jvm/src/kotlin/reflect/jvm/internal/KProperty0Impl.kt index b1758677721..0fa44d92f64 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KTopLevelVariableImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KProperty0Impl.kt @@ -18,10 +18,10 @@ package kotlin.reflect.jvm.internal import java.lang.reflect.Method import kotlin.reflect.IllegalPropertyAccessException -import kotlin.reflect.KMutableTopLevelVariable -import kotlin.reflect.KTopLevelVariable +import kotlin.reflect.KMutableProperty0 +import kotlin.reflect.KProperty0 -open class KTopLevelVariableImpl : DescriptorBasedProperty, KTopLevelVariable, KVariableImpl { +open class KProperty0Impl : DescriptorBasedProperty, KProperty0, KPropertyImpl { constructor(container: KPackageImpl, name: String) : super(container, name, null) override val name: String get() = descriptor.getName().asString() @@ -39,10 +39,10 @@ open class KTopLevelVariableImpl : DescriptorBasedProperty, KTopLevelVari } } -class KMutableTopLevelVariableImpl : KTopLevelVariableImpl, KMutableTopLevelVariable, KMutableVariableImpl { +class KMutableProperty0Impl : KProperty0Impl, KMutableProperty0, KMutablePropertyImpl { constructor(container: KPackageImpl, name: String) : super(container, name) - override val setter: Method get() = super.setter!! + override val setter: Method get() = super.setter!! override fun set(value: R) { try { diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KProperty1Impl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KProperty1Impl.kt new file mode 100644 index 00000000000..e575e316192 --- /dev/null +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KProperty1Impl.kt @@ -0,0 +1,88 @@ +/* + * Copyright 2010-2015 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.jvm.internal + +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import java.lang.reflect.Modifier +import kotlin.reflect.IllegalPropertyAccessException +import kotlin.reflect.KMutableProperty1 +import kotlin.reflect.KProperty1 + +open class KProperty1Impl : DescriptorBasedProperty, KProperty1, KPropertyImpl { + constructor(container: KCallableContainerImpl, name: String, receiverParameterClass: Class<*>?) : super( + container, name, receiverParameterClass + ) + + constructor(container: KCallableContainerImpl, descriptor: PropertyDescriptor) : super(container, descriptor) + + override val name: String get() = descriptor.getName().asString() + + // TODO: consider optimizing this, not to do complex checks on every access + @suppress("UNCHECKED_CAST") + override fun get(receiver: T): R { + try { + val getter = getter ?: + return field!!.get(receiver) as R + + if (Modifier.isStatic(getter.getModifiers())) { + // Workaround the case of platformStatic property in object, getter of which doesn't take a receiver + if (getter.getParameterTypes().isEmpty()) { + return getter.invoke(null) as R + } + + return getter.invoke(null, receiver) as R + } + + return getter.invoke(receiver) as R + } + catch (e: IllegalAccessException) { + throw IllegalPropertyAccessException(e) + } + } +} + + +class KMutableProperty1Impl : KProperty1Impl, KMutableProperty1, KMutablePropertyImpl { + constructor(container: KCallableContainerImpl, name: String, receiverParameterClass: Class<*>?) : super( + container, name, receiverParameterClass + ) + + constructor(container: KCallableContainerImpl, descriptor: PropertyDescriptor) : super(container, descriptor) + + override fun set(receiver: T, value: R) { + try { + val setter = setter ?: + return field!!.set(receiver, value) + + if (Modifier.isStatic(setter.getModifiers())) { + // Workaround the case of platformStatic property in object, setter of which doesn't take a receiver + if (setter.getParameterTypes().size() == 1) { + setter.invoke(null, value) + } + else { + setter.invoke(null, receiver, value) + } + } + else { + setter.invoke(receiver, value) + } + } + catch (e: IllegalAccessException) { + throw IllegalPropertyAccessException(e) + } + } +} diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KMemberExtensionPropertyImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KProperty2Impl.kt similarity index 70% rename from core/reflection.jvm/src/kotlin/reflect/jvm/internal/KMemberExtensionPropertyImpl.kt rename to core/reflection.jvm/src/kotlin/reflect/jvm/internal/KProperty2Impl.kt index 5777671ca62..9a65d8e8e88 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KMemberExtensionPropertyImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KProperty2Impl.kt @@ -20,10 +20,10 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor import java.lang.reflect.Field import java.lang.reflect.Method import kotlin.reflect.IllegalPropertyAccessException -import kotlin.reflect.KMemberExtensionProperty -import kotlin.reflect.KMutableMemberExtensionProperty +import kotlin.reflect.KMutableProperty2 +import kotlin.reflect.KProperty2 -open class KMemberExtensionPropertyImpl : DescriptorBasedProperty, KMemberExtensionProperty, KPropertyImpl { +open class KProperty2Impl : DescriptorBasedProperty, KProperty2, KPropertyImpl { constructor(container: KClassImpl, name: String, receiverParameterClass: Class) : super(container, name, receiverParameterClass) constructor(container: KClassImpl, descriptor: PropertyDescriptor) : super(container, descriptor) @@ -34,10 +34,10 @@ open class KMemberExtensionPropertyImpl : DescriptorBasedProp override val field: Field? get() = null - override fun get(instance: D, extensionReceiver: E): R { + override fun get(receiver1: D, receiver2: E): R { try { @suppress("UNCHECKED_CAST") - return getter.invoke(instance, extensionReceiver) as R + return getter.invoke(receiver1, receiver2) as R } catch (e: IllegalAccessException) { throw IllegalPropertyAccessException(e) @@ -46,19 +46,16 @@ open class KMemberExtensionPropertyImpl : DescriptorBasedProp } -class KMutableMemberExtensionPropertyImpl : - KMemberExtensionPropertyImpl, - KMutableMemberExtensionProperty, - KMutablePropertyImpl { +class KMutableProperty2Impl : KProperty2Impl, KMutableProperty2, KMutablePropertyImpl { constructor(container: KClassImpl, name: String, receiverParameterClass: Class) : super(container, name, receiverParameterClass) constructor(container: KClassImpl, descriptor: PropertyDescriptor) : super(container, descriptor) - override val setter: Method get() = super.setter!! + override val setter: Method get() = super.setter!! - override fun set(instance: D, extensionReceiver: E, value: R) { + override fun set(receiver1: D, receiver2: E, value: R) { try { - setter.invoke(instance, extensionReceiver, value) + setter.invoke(receiver1, receiver2, value) } catch (e: IllegalAccessException) { throw IllegalPropertyAccessException(e) diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt index 42843629643..d6e9f6e87a4 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt @@ -19,13 +19,13 @@ package kotlin.reflect.jvm.internal import java.lang.reflect.* import kotlin.reflect.* -trait KPropertyImpl : KProperty, KCallableImpl { +interface KPropertyImpl : KProperty, KCallableImpl { val field: Field? val getter: Method? } -trait KMutablePropertyImpl : KMutableProperty, KPropertyImpl { +interface KMutablePropertyImpl : KMutableProperty, KPropertyImpl { val setter: Method? } diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KTopLevelExtensionPropertyImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KTopLevelExtensionPropertyImpl.kt deleted file mode 100644 index bae24330fce..00000000000 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KTopLevelExtensionPropertyImpl.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2010-2015 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.jvm.internal - -import java.lang.reflect.Method -import kotlin.reflect.IllegalPropertyAccessException -import kotlin.reflect.KMutableTopLevelExtensionProperty -import kotlin.reflect.KTopLevelExtensionProperty - -open class KTopLevelExtensionPropertyImpl : DescriptorBasedProperty, KTopLevelExtensionProperty, KPropertyImpl { - constructor(container: KPackageImpl, name: String, receiverParameterClass: Class) : super(container, name, receiverParameterClass) - - override val name: String get() = descriptor.getName().asString() - - override val getter: Method get() = super.getter!! - - override fun get(receiver: T): R { - try { - @suppress("UNCHECKED_CAST") - return getter.invoke(null, receiver) as R - } - catch (e: IllegalAccessException) { - throw IllegalPropertyAccessException(e) - } - } -} - -class KMutableTopLevelExtensionPropertyImpl : - KTopLevelExtensionPropertyImpl, - KMutableTopLevelExtensionProperty, - KMutablePropertyImpl { - constructor(container: KPackageImpl, name: String, receiverParameterClass: Class) : super(container, name, receiverParameterClass) - - override val setter: Method get() = super.setter!! - - override fun set(receiver: T, value: R) { - try { - setter.invoke(null, receiver, value) - } - catch (e: IllegalAccessException) { - throw IllegalPropertyAccessException(e) - } - } -} diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KVariableImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KVariableImpl.kt deleted file mode 100644 index 45c7c09d564..00000000000 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KVariableImpl.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2010-2015 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.jvm.internal - -import kotlin.reflect.* - -trait KVariableImpl : KVariable, KPropertyImpl - -trait KMutableVariableImpl : KMutableVariable, KVariableImpl, KMutablePropertyImpl diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java index 239a77fa24e..8d7ef554cba 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java @@ -50,32 +50,32 @@ public class ReflectionFactoryImpl extends ReflectionFactory { // Properties @Override - public KMemberProperty memberProperty(String name, KClass owner) { + public KProperty1 memberProperty(String name, KClass owner) { return ((KClassImpl) owner).memberProperty(name); } @Override - public KMutableMemberProperty mutableMemberProperty(String name, KClass owner) { + public KMutableProperty1 mutableMemberProperty(String name, KClass owner) { return ((KClassImpl) owner).mutableMemberProperty(name); } @Override - public KTopLevelVariable topLevelVariable(String name, KPackage owner) { + public KProperty0 topLevelVariable(String name, KPackage owner) { return ((KPackageImpl) owner).topLevelVariable(name); } @Override - public KMutableTopLevelVariable mutableTopLevelVariable(String name, KPackage owner) { + public KMutableProperty0 mutableTopLevelVariable(String name, KPackage owner) { return ((KPackageImpl) owner).mutableTopLevelVariable(name); } @Override - public KTopLevelExtensionProperty topLevelExtensionProperty(String name, KPackage owner, Class receiver) { + public KProperty1 topLevelExtensionProperty(String name, KPackage owner, Class receiver) { return ((KPackageImpl) owner).topLevelExtensionProperty(name, receiver); } @Override - public KMutableTopLevelExtensionProperty mutableTopLevelExtensionProperty(String name, KPackage owner, Class receiver) { + public KMutableProperty1 mutableTopLevelExtensionProperty(String name, KPackage owner, Class receiver) { return ((KPackageImpl) owner).mutableTopLevelExtensionProperty(name, receiver); } } diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/mapping.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/mapping.kt index e29e44245e5..34f8ef44fb5 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/mapping.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/mapping.kt @@ -41,6 +41,13 @@ public val KPackage.javaFacade: Class<*> get() = (this as KPackageImpl).jClass +/** + * Returns a Java [Field] instance corresponding to the backing field of the given property, + * or `null` if the property has no backing field. + */ +public val KProperty<*>.javaField: Field? + get() = (this as KPropertyImpl<*>).field + /** * Returns a Java [Method] instance corresponding to the getter of the given property, * or `null` if the property has no getter, for example in case of a simple private `val` in a class. @@ -56,45 +63,6 @@ public val KMutableProperty<*>.javaSetter: Method? get() = (this as? KMutablePropertyImpl<*>)?.setter -/** - * Returns a Java [Field] instance corresponding to the backing field of the given top level property, - * or `null` if the property has no backing field. - */ -public val KTopLevelVariable<*>.javaField: Field? - get() = (this as KPropertyImpl<*>).field - -/** - * Returns a Java [Method] instance corresponding to the getter of the given top level property. - */ -public val KTopLevelVariable<*>.javaGetter: Method - get() = (this as KTopLevelVariableImpl<*>).getter - -/** - * Returns a Java [Method] instance corresponding to the setter of the given top level property. - */ -public val KMutableTopLevelVariable<*>.javaSetter: Method - get() = (this as KMutableTopLevelVariableImpl<*>).setter - - -/** - * Returns a Java [Method] instance corresponding to the getter of the given top level extension property. - */ -public val KTopLevelExtensionProperty<*, *>.javaGetter: Method - get() = (this as KTopLevelExtensionPropertyImpl<*, *>).getter - -/** - * Returns a Java [Method] instance corresponding to the setter of the given top level extension property. - */ -public val KMutableTopLevelExtensionProperty<*, *>.javaSetter: Method - get() = (this as KMutableTopLevelExtensionPropertyImpl<*, *>).setter - - -/** - * Returns a Java [Field] instance corresponding to the backing field of the given member property, - * or `null` if the property has no backing field. - */ -public val KMemberProperty<*, *>.javaField: Field? - get() = (this as KPropertyImpl<*>).field // Java reflection -> Kotlin reflection diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/properties.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/properties.kt index 093aa963fa4..a98e358f949 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/properties.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/properties.kt @@ -17,8 +17,8 @@ package kotlin.reflect.jvm import kotlin.reflect.KProperty -import kotlin.reflect.jvm.internal.KMemberPropertyImpl -import kotlin.reflect.jvm.internal.KMutableMemberPropertyImpl +import kotlin.reflect.jvm.internal.KProperty1Impl +import kotlin.reflect.jvm.internal.KMutableProperty1Impl /** * Provides a way to suppress JVM access checks for a property. @@ -34,11 +34,11 @@ import kotlin.reflect.jvm.internal.KMutableMemberPropertyImpl public var KProperty.accessible: Boolean get() { return when (this) { - is KMutableMemberPropertyImpl<*, R> -> + is KMutableProperty1Impl<*, R> -> field?.isAccessible() ?: true && getter?.isAccessible() ?: true && setter?.isAccessible() ?: true - is KMemberPropertyImpl<*, R> -> + is KProperty1Impl<*, R> -> field?.isAccessible() ?: true && getter?.isAccessible() ?: true else -> { @@ -49,12 +49,12 @@ public var KProperty.accessible: Boolean } set(value) { when (this) { - is KMutableMemberPropertyImpl<*, R> -> { + is KMutableProperty1Impl<*, R> -> { field?.setAccessible(value) getter?.setAccessible(value) setter?.setAccessible(value) } - is KMemberPropertyImpl<*, R> -> { + is KProperty1Impl<*, R> -> { field?.setAccessible(value) getter?.setAccessible(value) } diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/Reflection.java b/core/runtime.jvm/src/kotlin/jvm/internal/Reflection.java index 6c48b3d55da..e839eeb1196 100644 --- a/core/runtime.jvm/src/kotlin/jvm/internal/Reflection.java +++ b/core/runtime.jvm/src/kotlin/jvm/internal/Reflection.java @@ -67,27 +67,27 @@ public class Reflection { // Properties - public static KMemberProperty memberProperty(String name, KClass owner) { + public static KProperty1 memberProperty(String name, KClass owner) { return factory.memberProperty(name, owner); } - public static KMutableMemberProperty mutableMemberProperty(String name, KClass owner) { + public static KMutableProperty1 mutableMemberProperty(String name, KClass owner) { return factory.mutableMemberProperty(name, owner); } - public static KTopLevelVariable topLevelVariable(String name, KPackage owner) { + public static KProperty0 topLevelVariable(String name, KPackage owner) { return factory.topLevelVariable(name, owner); } - public static KMutableTopLevelVariable mutableTopLevelVariable(String name, KPackage owner) { + public static KMutableProperty0 mutableTopLevelVariable(String name, KPackage owner) { return factory.mutableTopLevelVariable(name, owner); } - public static KTopLevelExtensionProperty topLevelExtensionProperty(String name, KPackage owner, Class receiver) { + public static KProperty1 topLevelExtensionProperty(String name, KPackage owner, Class receiver) { return factory.topLevelExtensionProperty(name, owner, receiver); } - public static KMutableTopLevelExtensionProperty mutableTopLevelExtensionProperty(String name, KPackage owner, Class receiver) { + public static KMutableProperty1 mutableTopLevelExtensionProperty(String name, KPackage owner, Class receiver) { return factory.mutableTopLevelExtensionProperty(name, owner, receiver); } } diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/ReflectionFactory.java b/core/runtime.jvm/src/kotlin/jvm/internal/ReflectionFactory.java index 431863234fa..13b310e76fa 100644 --- a/core/runtime.jvm/src/kotlin/jvm/internal/ReflectionFactory.java +++ b/core/runtime.jvm/src/kotlin/jvm/internal/ReflectionFactory.java @@ -40,27 +40,27 @@ public class ReflectionFactory { // Properties - public KMemberProperty memberProperty(String name, KClass owner) { + public KProperty1 memberProperty(String name, KClass owner) { throw error(); } - public KMutableMemberProperty mutableMemberProperty(String name, KClass owner) { + public KMutableProperty1 mutableMemberProperty(String name, KClass owner) { throw error(); } - public KTopLevelVariable topLevelVariable(String name, KPackage owner) { + public KProperty0 topLevelVariable(String name, KPackage owner) { throw error(); } - public KMutableTopLevelVariable mutableTopLevelVariable(String name, KPackage owner) { + public KMutableProperty0 mutableTopLevelVariable(String name, KPackage owner) { throw error(); } - public KTopLevelExtensionProperty topLevelExtensionProperty(String name, KPackage owner, Class receiver) { + public KProperty1 topLevelExtensionProperty(String name, KPackage owner, Class receiver) { throw error(); } - public KMutableTopLevelExtensionProperty mutableTopLevelExtensionProperty(String name, KPackage owner, Class receiver) { + public KMutableProperty1 mutableTopLevelExtensionProperty(String name, KPackage owner, Class receiver) { throw error(); } diff --git a/js/js.translator/testData/callableReference/property/cases/kClassInstanceIsInitializedFirst.kt b/js/js.translator/testData/callableReference/property/cases/kClassInstanceIsInitializedFirst.kt index de0f3d9157b..6682058120e 100644 --- a/js/js.translator/testData/callableReference/property/cases/kClassInstanceIsInitializedFirst.kt +++ b/js/js.translator/testData/callableReference/property/cases/kClassInstanceIsInitializedFirst.kt @@ -1,11 +1,11 @@ // This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/. package foo -import kotlin.reflect.KMemberProperty +import kotlin.reflect.KProperty1 class A { companion object { - val ref: KMemberProperty = A::foo + val ref: KProperty1 = A::foo } val foo: String = "OK"