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
@@ -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()