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.)
This commit is contained in:
@@ -2452,14 +2452,14 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> 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());
|
||||
|
||||
+4
-4
@@ -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();
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
+3
@@ -8,6 +8,7 @@ var Int.meaning: Long
|
||||
fun test() {
|
||||
val f = String::countCharacters
|
||||
|
||||
f : KTopLevelExtensionProperty<String, Int>
|
||||
f : KExtensionProperty<String, Int>
|
||||
<!TYPE_MISMATCH!>f<!> : KMutableExtensionProperty<String, Int>
|
||||
f.get("abc") : Int
|
||||
@@ -15,7 +16,9 @@ fun test() {
|
||||
|
||||
val g = Int::meaning
|
||||
|
||||
g : KTopLevelExtensionProperty<Int, Long>
|
||||
g : KExtensionProperty<Int, Long>
|
||||
g : KMutableTopLevelExtensionProperty<Int, Long>
|
||||
g : KMutableExtensionProperty<Int, Long>
|
||||
g.get(0) : Long
|
||||
g.set(1, 0L)
|
||||
|
||||
+4
-1
@@ -4,8 +4,11 @@ val y: String get() = "y"
|
||||
fun testX() {
|
||||
val xx = ::x
|
||||
xx : KMutableTopLevelProperty<Int>
|
||||
xx : KMutableTopLevelVariable<Int>
|
||||
xx : KTopLevelProperty<Int>
|
||||
xx : KTopLevelVariable<Int>
|
||||
xx : KMutableProperty<Int>
|
||||
xx : KMutableVariable<Int>
|
||||
xx : KProperty<Int>
|
||||
xx : KCallable<Int>
|
||||
|
||||
@@ -17,7 +20,7 @@ fun testX() {
|
||||
fun testY() {
|
||||
val yy = ::y
|
||||
<!TYPE_MISMATCH!>yy<!> : KMutableTopLevelProperty<String>
|
||||
yy : KTopLevelProperty<String>
|
||||
yy : KTopLevelVariable<String>
|
||||
<!TYPE_MISMATCH!>yy<!> : KMutableProperty<String>
|
||||
yy : KProperty<String>
|
||||
yy : KCallable<String>
|
||||
|
||||
@@ -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<T, out R> : KExtensionProperty<T, R>, KTopLevelProperty<R>
|
||||
|
||||
public trait KMutableTopLevelExtensionProperty<T, out R> : KTopLevelExtensionProperty<T, R>, KMutableExtensionProperty<T, R>, KMutableTopLevelProperty<R>
|
||||
@@ -16,6 +16,6 @@
|
||||
|
||||
package kotlin.reflect
|
||||
|
||||
public trait KTopLevelProperty<out R> : KVariable<R>
|
||||
public trait KTopLevelProperty<out R> : KProperty<R>
|
||||
|
||||
public trait KMutableTopLevelProperty<R> : KTopLevelProperty<R>, KMutableVariable<R>
|
||||
public trait KMutableTopLevelProperty<R> : KTopLevelProperty<R>, KMutableProperty<R>
|
||||
|
||||
@@ -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<out R> : KVariable<R>, KTopLevelProperty<R>
|
||||
|
||||
public trait KMutableTopLevelVariable<R> : KTopLevelVariable<R>, KMutableVariable<R>, KMutableTopLevelProperty<R>
|
||||
+4
-4
@@ -18,11 +18,11 @@ package kotlin.reflect.jvm.internal
|
||||
|
||||
import java.lang.reflect.*
|
||||
|
||||
open class KExtensionPropertyImpl<T, out R>(
|
||||
open class KTopLevelExtensionPropertyImpl<T, out R>(
|
||||
public override val name: String,
|
||||
protected val owner: KPackageImpl,
|
||||
protected val receiverClass: Class<T>
|
||||
) : KExtensionProperty<T, R>, KPropertyImpl<R> {
|
||||
) : KTopLevelExtensionProperty<T, R>, KPropertyImpl<R> {
|
||||
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<T, out R>(
|
||||
}
|
||||
}
|
||||
|
||||
class KMutableExtensionPropertyImpl<T, R>(
|
||||
class KMutableTopLevelExtensionPropertyImpl<T, R>(
|
||||
name: String,
|
||||
owner: KPackageImpl,
|
||||
receiverClass: Class<T>
|
||||
) : KMutableExtensionProperty<T, R>, KMutablePropertyImpl<R>, KExtensionPropertyImpl<T, R>(name, owner, receiverClass) {
|
||||
) : KMutableTopLevelExtensionProperty<T, R>, KMutablePropertyImpl<R>, KTopLevelExtensionPropertyImpl<T, R>(name, owner, receiverClass) {
|
||||
override val setter: Method = owner.jClass.getMethod(setterName(name), receiverClass, getter.getReturnType()!!)
|
||||
|
||||
override fun set(receiver: T, value: R) {
|
||||
+4
-4
@@ -18,10 +18,10 @@ package kotlin.reflect.jvm.internal
|
||||
|
||||
import java.lang.reflect.*
|
||||
|
||||
open class KTopLevelPropertyImpl<out R>(
|
||||
open class KTopLevelVariableImpl<out R>(
|
||||
public override val name: String,
|
||||
protected val owner: KPackageImpl
|
||||
) : KTopLevelProperty<R>, KVariableImpl<R> {
|
||||
) : KTopLevelVariable<R>, KVariableImpl<R> {
|
||||
// TODO: load the field from the corresponding package part
|
||||
override val field: Field? get() = null
|
||||
|
||||
@@ -33,10 +33,10 @@ open class KTopLevelPropertyImpl<out R>(
|
||||
}
|
||||
}
|
||||
|
||||
class KMutableTopLevelPropertyImpl<R>(
|
||||
class KMutableTopLevelVariableImpl<R>(
|
||||
name: String,
|
||||
owner: KPackageImpl
|
||||
) : KMutableTopLevelProperty<R>, KMutableVariableImpl<R>, KTopLevelPropertyImpl<R>(name, owner) {
|
||||
) : KMutableTopLevelVariable<R>, KMutableVariableImpl<R>, KTopLevelVariableImpl<R>(name, owner) {
|
||||
override val setter: Method = owner.jClass.getMethod(setterName(name), getter.getReturnType()!!)
|
||||
|
||||
override fun set(value: R) {
|
||||
@@ -23,14 +23,14 @@ fun <T> kClass(jClass: Class<T>): KClassImpl<T> =
|
||||
fun kPackage(jClass: Class<*>): KPackageImpl =
|
||||
KPackageImpl(jClass)
|
||||
|
||||
fun topLevelProperty(name: String, owner: KPackageImpl): KTopLevelPropertyImpl<Any?> =
|
||||
KTopLevelPropertyImpl<Any?>(name, owner)
|
||||
fun topLevelVariable(name: String, owner: KPackageImpl): KTopLevelVariableImpl<Any?> =
|
||||
KTopLevelVariableImpl<Any?>(name, owner)
|
||||
|
||||
fun mutableTopLevelProperty(name: String, owner: KPackageImpl): KMutableTopLevelPropertyImpl<Any?> =
|
||||
KMutableTopLevelPropertyImpl<Any?>(name, owner)
|
||||
fun mutableTopLevelVariable(name: String, owner: KPackageImpl): KMutableTopLevelVariableImpl<Any?> =
|
||||
KMutableTopLevelVariableImpl<Any?>(name, owner)
|
||||
|
||||
fun <T> extensionProperty(name: String, owner: KPackageImpl, receiver: Class<T>): KExtensionPropertyImpl<T, Any?> =
|
||||
KExtensionPropertyImpl<T, Any?>(name, owner, receiver)
|
||||
fun <T> topLevelExtensionProperty(name: String, owner: KPackageImpl, receiver: Class<T>): KTopLevelExtensionPropertyImpl<T, Any?> =
|
||||
KTopLevelExtensionPropertyImpl<T, Any?>(name, owner, receiver)
|
||||
|
||||
fun <T> mutableExtensionProperty(name: String, owner: KPackageImpl, receiver: Class<T>): KMutableExtensionPropertyImpl<T, Any?> =
|
||||
KMutableExtensionPropertyImpl<T, Any?>(name, owner, receiver)
|
||||
fun <T> mutableTopLevelExtensionProperty(name: String, owner: KPackageImpl, receiver: Class<T>): KMutableTopLevelExtensionPropertyImpl<T, Any?> =
|
||||
KMutableTopLevelExtensionPropertyImpl<T, Any?>(name, owner, receiver)
|
||||
|
||||
Reference in New Issue
Block a user