Remove PropertyMetadata from project and bytecode, migrate code to KProperty

This commit is contained in:
Alexander Udalov
2015-11-20 16:37:47 +03:00
parent fb61dc7e81
commit 7b3b157707
22 changed files with 99 additions and 74 deletions
@@ -484,13 +484,13 @@ public abstract class MemberCodegen<T extends KtElement/* TODO: & JetDeclaration
if (delegatedProperties.isEmpty()) return;
v.newField(NO_ORIGIN, ACC_PRIVATE | ACC_STATIC | ACC_FINAL | ACC_SYNTHETIC, JvmAbi.DELEGATED_PROPERTIES_ARRAY_NAME,
"[" + PROPERTY_METADATA_TYPE, null, null);
"[" + K_PROPERTY_TYPE, null, null);
if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES) return;
InstructionAdapter iv = createOrGetClInitCodegen().v;
iv.iconst(delegatedProperties.size());
iv.newarray(PROPERTY_METADATA_TYPE);
iv.newarray(K_PROPERTY_TYPE);
for (int i = 0, size = delegatedProperties.size(); i < size; i++) {
PropertyDescriptor property =
@@ -529,12 +529,12 @@ public abstract class MemberCodegen<T extends KtElement/* TODO: & JetDeclaration
);
}
value.put(PROPERTY_METADATA_TYPE, iv);
value.put(K_PROPERTY_TYPE, iv);
iv.astore(PROPERTY_METADATA_TYPE);
iv.astore(K_PROPERTY_TYPE);
}
iv.putstatic(thisAsmType.getInternalName(), JvmAbi.DELEGATED_PROPERTIES_ARRAY_NAME, "[" + PROPERTY_METADATA_TYPE);
iv.putstatic(thisAsmType.getInternalName(), JvmAbi.DELEGATED_PROPERTIES_ARRAY_NAME, "[" + K_PROPERTY_TYPE);
}
public String getClassName() {
@@ -58,7 +58,7 @@ import static org.jetbrains.kotlin.codegen.AsmUtil.*;
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isJvmInterface;
import static org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings.*;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.PROPERTY_METADATA_TYPE;
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.K_PROPERTY_TYPE;
import static org.jetbrains.kotlin.resolve.jvm.annotations.AnnotationUtilKt.hasJvmFieldAnnotation;
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
@@ -521,13 +521,15 @@ public class PropertyCodegen {
codegen.tempVariables.put(
resolvedCall.getCall().getValueArguments().get(propertyMetadataArgumentIndex).asElement(),
new StackValue(PROPERTY_METADATA_TYPE) {
new StackValue(K_PROPERTY_TYPE) {
@Override
public void putSelector(@NotNull Type type, @NotNull InstructionAdapter v) {
Field array = StackValue
.field(Type.getType("[" + PROPERTY_METADATA_TYPE), owner, JvmAbi.DELEGATED_PROPERTIES_ARRAY_NAME, true,
StackValue.none());
StackValue.arrayElement(PROPERTY_METADATA_TYPE, array, StackValue.constant(indexInPropertyMetadataArray, Type.INT_TYPE)).put(type, v);
Field array = StackValue.field(
Type.getType("[" + K_PROPERTY_TYPE), owner, JvmAbi.DELEGATED_PROPERTIES_ARRAY_NAME, true, StackValue.none()
);
StackValue.arrayElement(
K_PROPERTY_TYPE, array, StackValue.constant(indexInPropertyMetadataArray, Type.INT_TYPE)
).put(type, v);
}
}
);
@@ -16,6 +16,8 @@
package org.jetbrains.kotlin.container
import kotlin.reflect.KProperty
public fun createContainer(id: String, init: StorageComponentContainer.() -> Unit): StorageComponentContainer {
val c = StorageComponentContainer(id)
c.init()
@@ -24,11 +26,11 @@ public fun createContainer(id: String, init: StorageComponentContainer.() -> Uni
}
public inline fun <reified T : Any> StorageComponentContainer.useImpl() {
registerSingleton(javaClass<T>())
registerSingleton(T::class.java)
}
public inline fun <reified T : Any> ComponentProvider.get(): T {
return getService(javaClass<T>())
return getService(T::class.java)
}
@Suppress("UNCHECKED_CAST")
@@ -40,6 +42,6 @@ public fun StorageComponentContainer.useInstance(instance: Any) {
registerInstance(instance)
}
inline operator fun <reified T : Any> ComponentProvider.getValue(thisRef: Any?, desc: PropertyMetadata): T {
return getService(javaClass<T>())
inline operator fun <reified T : Any> ComponentProvider.getValue(thisRef: Any?, desc: KProperty<*>): T {
return getService(T::class.java)
}
@@ -31,7 +31,6 @@ public class AsmTypes {
public static final Type JAVA_CLASS_TYPE = getType(Class.class);
public static final Type UNIT_TYPE = Type.getObjectType("kotlin/Unit");
public static final Type PROPERTY_METADATA_TYPE = Type.getObjectType("kotlin/PropertyMetadata");
public static final Type LAMBDA = Type.getObjectType("kotlin/jvm/internal/Lambda");
public static final Type FUNCTION_REFERENCE = Type.getObjectType("kotlin/jvm/internal/FunctionReference");
@@ -59,6 +58,7 @@ public class AsmTypes {
public static final Type K_FUNCTION = reflect("KFunction");
public static final Type K_PROPERTY_TYPE = reflect("KProperty");
public static final Type K_PROPERTY0_TYPE = reflect("KProperty0");
public static final Type K_PROPERTY1_TYPE = reflect("KProperty1");
public static final Type K_PROPERTY2_TYPE = reflect("KProperty2");
@@ -25,11 +25,11 @@ class CustomDelegate3 {
operator fun set(thisRef: Any?, prop: KProperty<*>, value: String) {}
}
operator fun OkDelegate.get(thisRef: Any?, prop: <!DEPRECATION!>PropertyMetadata<!>): Int = 4
operator fun OkDelegate.set(thisRef: Any?, prop: <!DEPRECATION!>PropertyMetadata<!>, value: Int) {}
operator fun OkDelegate.get(thisRef: Any?, prop: KProperty<*>): Int = 4
operator fun OkDelegate.set(thisRef: Any?, prop: KProperty<*>, value: Int) {}
operator fun CustomDelegate3.getValue(thisRef: Any?, prop: <!DEPRECATION!>PropertyMetadata<!>): Int = 4
operator fun CustomDelegate3.setValue(thisRef: Any?, prop: <!DEPRECATION!>PropertyMetadata<!>, value: Int) {}
operator fun CustomDelegate3.getValue(thisRef: Any?, prop: KProperty<*>): Int = 4
operator fun CustomDelegate3.setValue(thisRef: Any?, prop: KProperty<*>, value: Int) {}
class Example {
@@ -50,4 +50,4 @@ class Example {
fun requireString(s: String) {}
fun requireInt(n: Int) {}
}
}
@@ -1,9 +1,9 @@
package
public operator fun OkDelegate.get(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.PropertyMetadata): kotlin.Int
public operator fun CustomDelegate3.getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.PropertyMetadata): kotlin.Int
public operator fun OkDelegate.set(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.PropertyMetadata, /*2*/ value: kotlin.Int): kotlin.Unit
public operator fun CustomDelegate3.setValue(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.PropertyMetadata, /*2*/ value: kotlin.Int): kotlin.Unit
public operator fun OkDelegate.get(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.reflect.KProperty<*>): kotlin.Int
public operator fun CustomDelegate3.getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.reflect.KProperty<*>): kotlin.Int
public operator fun OkDelegate.set(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.reflect.KProperty<*>, /*2*/ value: kotlin.Int): kotlin.Unit
public operator fun CustomDelegate3.setValue(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.reflect.KProperty<*>, /*2*/ value: kotlin.Int): kotlin.Unit
public final class CustomDelegate {
public constructor CustomDelegate()
@@ -1,11 +1,13 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
operator fun Any.getValue(x: Any?, y: Any): Any = null!!
class <!CONFLICTING_JVM_DECLARATIONS!>C<!> {
val x by 1
<!CONFLICTING_JVM_DECLARATIONS!>val `$$delegatedProperties`: Array<PropertyMetadata><!> = null!!
<!CONFLICTING_JVM_DECLARATIONS!>val `$$delegatedProperties`: Array<KProperty<*>><!> = null!!
}
val x by 1
<!CONFLICTING_JVM_DECLARATIONS!>val `$$delegatedProperties`: Array<PropertyMetadata><!> = null!!
<!CONFLICTING_JVM_DECLARATIONS!>val `$$delegatedProperties`: Array<KProperty<*>><!> = null!!
@@ -1,12 +1,12 @@
package
public val `$$delegatedProperties`: kotlin.Array<kotlin.PropertyMetadata>
public val `$$delegatedProperties`: kotlin.Array<kotlin.reflect.KProperty<*>>
public val x: kotlin.Any
public operator fun kotlin.Any.getValue(/*0*/ x: kotlin.Any?, /*1*/ y: kotlin.Any): kotlin.Any
public final class C {
public constructor C()
public final val `$$delegatedProperties`: kotlin.Array<kotlin.PropertyMetadata>
public final val `$$delegatedProperties`: kotlin.Array<kotlin.reflect.KProperty<*>>
public final val x: kotlin.Any
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
@@ -44,4 +44,4 @@ class ContainerForTests(container: StorageComponentContainer) {
val typeResolver: TypeResolver by container
val fakeCallResolver: FakeCallResolver by container
val expressionTypingServices: ExpressionTypingServices by container
}
}
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
import org.jetbrains.kotlin.types.*
import java.util.*
import kotlin.reflect.KProperty
val KOTLIN_REFLECT_FQ_NAME = FqName("kotlin.reflect")
@@ -43,7 +44,7 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
}
private object ClassLookup {
operator fun getValue(types: ReflectionTypes, property: PropertyMetadata): ClassDescriptor {
operator fun getValue(types: ReflectionTypes, property: KProperty<*>): ClassDescriptor {
return types.find(property.name.capitalize())
}
}
@@ -75,7 +76,7 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
): KotlinType {
val arguments = KotlinBuiltIns.getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType)
val classDescriptor = getKFunction(arguments.size() - 1 /* return type */)
val classDescriptor = getKFunction(arguments.size - 1 /* return type */)
if (ErrorUtils.isError(classDescriptor)) {
return classDescriptor.defaultType
@@ -19,12 +19,10 @@ package org.jetbrains.kotlin.renderer
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.types.KotlinType
import java.lang.reflect.Modifier
import kotlin.jvm.internal.PropertyReference1Impl
import kotlin.properties.Delegates
import kotlin.properties.ObservableProperty
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KParameter
import kotlin.reflect.KProperty
import kotlin.reflect.KType
internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
public var isLocked: Boolean = false
@@ -43,22 +41,11 @@ internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
if (field.modifiers.and(Modifier.STATIC) != 0) continue
field.isAccessible = true
val property = field.get(this) as? ObservableProperty<*> ?: continue
val value = property.getValue(this, object : KProperty<Any?>, PropertyMetadata {
override val parameters: List<KParameter>
get() = error("Should not be called")
override val returnType: KType
get() = error("Should not be called")
override val getter: KProperty.Getter<Any?>
get() = error("Should not be called")
override val annotations: List<Annotation>
get() = error("Should not be called")
override fun call(vararg args: Any?): Any? = error("Should not be called")
override fun callBy(args: Map<KParameter, Any?>): Any? = error("Should not be called")
override val name = "" /* not used */
})
assert(!field.name.startsWith("is")) { "Fields named is* are not supported here yet" }
val value = property.getValue(
this,
PropertyReference1Impl(DescriptorRendererOptionsImpl::class, field.name, "get" + field.name.capitalize())
)
field.set(copy, copy.property(value as Any))
}
@@ -14,6 +14,22 @@
* limitations under the License.
*/
/*
* 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
@Deprecated("Please use KProperty instead.")
@@ -16,6 +16,8 @@
package org.jetbrains.kotlin.storage
import kotlin.reflect.KProperty
public interface MemoizedFunctionToNotNull<P, R : Any> : Function1<P, R> {
public fun isComputed(key: P): Boolean
}
@@ -32,6 +34,6 @@ public interface NullableLazyValue<T : Any> : Function0<T?> {
public fun isComputed(): Boolean
}
public operator fun <T : Any> NotNullLazyValue<T>.getValue(_this: Any?, p: PropertyMetadata): T = invoke()
public operator fun <T : Any> NotNullLazyValue<T>.getValue(_this: Any?, p: KProperty<*>): T = invoke()
public operator fun <T : Any> NullableLazyValue<T>.getValue(_this: Any?, p: PropertyMetadata): T? = invoke()
public operator fun <T : Any> NullableLazyValue<T>.getValue(_this: Any?, p: KProperty<*>): T? = invoke()
+3 -2
View File
@@ -1,6 +1,7 @@
import pack.oldFun1
import pack.oldFun2 // should not be removed for non-deprecated overload used
import pack.oldFun3
import kotlin.reflect.KProperty
class A private()
@@ -40,8 +41,8 @@ annotation class Fancy(val param: Int)
@Fancy(<caret>i) class D
class CustomDelegate {
operator fun get(thisRef: Any?, prop: PropertyMetadata): String = ""
operator fun set(thisRef: Any?, prop: PropertyMetadata, value: String) {}
operator fun get(thisRef: Any?, prop: KProperty<*>): String = ""
operator fun set(thisRef: Any?, prop: KProperty<*>, value: String) {}
}
class B {
@@ -15,12 +15,14 @@ class BigTest {
// FILE: second.kt
package some
import kotlin.reflect.KProperty
class DelegateImpl<T> {
val value: T = null!!
}
public fun <T> DelegateImpl<T>.getValue(thisRef: Any?, property: PropertyMetadata): T = value
public fun <T> DelegateImpl<T>.setValue(thisRef: Any, propertyMetadata: PropertyMetadata, t: T) {}
public fun <T> DelegateImpl<T>.getValue(thisRef: Any?, property: KProperty<*>): T = value
public fun <T> DelegateImpl<T>.setValue(thisRef: Any, property: KProperty<*>, t: T) {}
@@ -38,5 +40,3 @@ import some.setValue
class BigTest {
var a by <caret>DelegateImpl<Int>()
}
@@ -15,11 +15,13 @@ class BigTest {
// FILE: second.kt
package some
import kotlin.reflect.KProperty
class DelegateImpl<T> {
val value: T = null!!
}
public fun <T> DelegateImpl<T>.getValue(thisRef: Any?, property: PropertyMetadata): T = value
public fun <T> DelegateImpl<T>.getValue(thisRef: Any?, property: KProperty<*>): T = value
@@ -34,4 +36,4 @@ import some.getValue
class BigTest {
val a by <caret>DelegateImpl<Int>()
}
}
@@ -15,12 +15,14 @@ class BigTest {
// FILE: second.kt
package some
import kotlin.reflect.KProperty
class DelegateImpl<T> {
val value: T = null!!
}
operator fun <T> DelegateImpl<T>.getValue(thisRef: Any?, property: PropertyMetadata): T = value
operator fun <T> DelegateImpl<T>.setValue(thisRef: Any, propertyMetadata: PropertyMetadata, t: T) {}
operator fun <T> DelegateImpl<T>.getValue(thisRef: Any?, property: KProperty<*>): T = value
operator fun <T> DelegateImpl<T>.setValue(thisRef: Any, property: KProperty<*>, t: T) {}
@@ -37,5 +39,3 @@ import some.setValue
class BigTest {
var a by <caret>DelegateImpl<Int>()
}
@@ -1,7 +1,9 @@
// "Rename to 'getValue'" "true"
import kotlin.reflect.KProperty
class CustomDelegate
operator fun CustomDelegate.get(thisRef: Any?, prop: PropertyMetadata): String = ""
operator fun CustomDelegate.get(thisRef: Any?, prop: KProperty<*>): String = ""
class Example {
val a: String <caret>by CustomDelegate()
@@ -1,7 +1,9 @@
// "Rename to 'getValue'" "true"
import kotlin.reflect.KProperty
class CustomDelegate
operator fun CustomDelegate.getValue(thisRef: Any?, prop: PropertyMetadata): String = ""
operator fun CustomDelegate.getValue(thisRef: Any?, prop: KProperty<*>): String = ""
class Example {
val a: String by CustomDelegate()
@@ -1,9 +1,11 @@
// "Rename to 'setValue'" "true"
// ERROR: 'get' method convention on type 'CustomDelegate' is deprecated. Rename to 'getValue'
import kotlin.reflect.KProperty
class CustomDelegate {
operator fun get(thisRef: Any?, prop: PropertyMetadata): String = ""
operator fun set(thisRef: Any?, prop: PropertyMetadata, value: String) {}
operator fun get(thisRef: Any?, prop: KProperty<*>): String = ""
operator fun set(thisRef: Any?, prop: KProperty<*>, value: String) {}
}
class Example {
@@ -1,9 +1,11 @@
// "Rename to 'setValue'" "true"
// ERROR: 'get' method convention on type 'CustomDelegate' is deprecated. Rename to 'getValue'
import kotlin.reflect.KProperty
class CustomDelegate {
operator fun get(thisRef: Any?, prop: PropertyMetadata): String = ""
operator fun setValue(thisRef: Any?, prop: PropertyMetadata, value: String) {}
operator fun get(thisRef: Any?, prop: KProperty<*>): String = ""
operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: String) {}
}
class Example {
@@ -16,13 +16,15 @@
package com.google.dart.compiler.backend.js.ast.metadata
import kotlin.reflect.KProperty
internal class MetadataProperty<in T : HasMetadata, R>(val default: R) {
operator fun getValue(thisRef: T, desc: PropertyMetadata): R {
operator fun getValue(thisRef: T, desc: KProperty<*>): R {
if (!thisRef.hasData(desc.name)) return default
return thisRef.getData<R>(desc.name)
}
operator fun setValue(thisRef: T, desc: PropertyMetadata, value: R) {
operator fun setValue(thisRef: T, desc: KProperty<*>, value: R) {
thisRef.setData(desc.name, value)
}
}