Pass KProperty instances to property delegates
Inherit KProperty from PropertyMetadata, cache corresponding KProperty objects instead of PropertyMetadataImpl objects, add support for properties with 2 receivers
This commit is contained in:
@@ -24,7 +24,7 @@ package kotlin.reflect
|
||||
*
|
||||
* @param R the type of the property.
|
||||
*/
|
||||
public interface KProperty<out R> : KCallable<R> {
|
||||
public interface KProperty<out R> : KCallable<R>, PropertyMetadata {
|
||||
/** The getter of this property, used to obtain the value of the property. */
|
||||
public val getter: Getter<R>
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public final class JvmAbi {
|
||||
private static final String SET_PREFIX = "set";
|
||||
|
||||
public static final String DELEGATED_PROPERTY_NAME_SUFFIX = "$delegate";
|
||||
public static final String PROPERTY_METADATA_ARRAY_NAME = "$propertyMetadata";
|
||||
public static final String DELEGATED_PROPERTIES_ARRAY_NAME = "$delegatedProperties";
|
||||
public static final String ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX = "$annotations";
|
||||
|
||||
public static final String INSTANCE_FIELD = "INSTANCE";
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package kotlin.reflect.jvm.internal
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import kotlin.jvm.internal.MutablePropertyReference2
|
||||
import kotlin.jvm.internal.PropertyReference2
|
||||
import kotlin.reflect.KMutableProperty2
|
||||
import kotlin.reflect.KProperty2
|
||||
|
||||
@@ -34,7 +36,7 @@ internal open class KProperty2Impl<D, E, out R> : DescriptorBasedProperty<R>, KP
|
||||
}
|
||||
}
|
||||
|
||||
internal class KMutableProperty2Impl<D, E, R> : KProperty2Impl<D, E, R>, KMutableProperty2<D, E, R>, KMutablePropertyImpl<R> {
|
||||
internal open class KMutableProperty2Impl<D, E, R> : KProperty2Impl<D, E, R>, KMutableProperty2<D, E, R>, KMutablePropertyImpl<R> {
|
||||
constructor(container: KDeclarationContainerImpl, name: String, signature: String) : super(container, name, signature)
|
||||
|
||||
constructor(container: KDeclarationContainerImpl, descriptor: PropertyDescriptor) : super(container, descriptor)
|
||||
@@ -47,3 +49,32 @@ internal class KMutableProperty2Impl<D, E, R> : KProperty2Impl<D, E, R>, KMutabl
|
||||
override fun invoke(receiver1: D, receiver2: E, value: R): Unit = property.set(receiver1, receiver2, value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal class KProperty2FromReferenceImpl(
|
||||
val reference: PropertyReference2
|
||||
) : KProperty2Impl<Any?, Any?, Any?>(
|
||||
reference.owner as KDeclarationContainerImpl,
|
||||
reference.name,
|
||||
reference.signature
|
||||
) {
|
||||
override val name: String get() = reference.name
|
||||
|
||||
override fun get(receiver1: Any?, receiver2: Any?): Any? = reference.get(receiver1, receiver2)
|
||||
}
|
||||
|
||||
internal class KMutableProperty2FromReferenceImpl(
|
||||
val reference: MutablePropertyReference2
|
||||
) : KMutableProperty2Impl<Any?, Any?, Any?>(
|
||||
reference.owner as KDeclarationContainerImpl,
|
||||
reference.name,
|
||||
reference.signature
|
||||
) {
|
||||
override val name: String get() = reference.name
|
||||
|
||||
override fun get(receiver1: Any?, receiver2: Any?): Any? = reference.get(receiver1, receiver2)
|
||||
|
||||
override fun set(receiver1: Any?, receiver2: Any?, value: Any?) {
|
||||
reference.set(receiver1, receiver2, value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,14 +70,12 @@ public class ReflectionFactoryImpl extends ReflectionFactory {
|
||||
|
||||
@Override
|
||||
public KProperty2 property2(PropertyReference2 p) {
|
||||
// TODO: support member extension property references
|
||||
return p;
|
||||
return new KProperty2FromReferenceImpl(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KMutableProperty2 mutableProperty2(MutablePropertyReference2 p) {
|
||||
// TODO: support member extension property references
|
||||
return p;
|
||||
return new KMutableProperty2FromReferenceImpl(p);
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
|
||||
Reference in New Issue
Block a user