Deprecate PropertyMetadata, use KProperty<*> for delegated properties instead

This commit is contained in:
Alexander Udalov
2015-10-12 21:42:18 +03:00
parent 3c74f48f91
commit ec1b4776fe
145 changed files with 536 additions and 379 deletions
+1 -7
View File
@@ -19,16 +19,10 @@ package kotlin
/**
* Represents a property in a Kotlin class.
*/
@Deprecated("Please use KProperty instead.", ReplaceWith("KProperty<*>", "kotlin.reflect.KProperty"))
public interface PropertyMetadata {
/**
* The name of the property.
*/
public val name: String
}
/**
* @suppress
*/
public data class PropertyMetadataImpl(override val name: String): PropertyMetadata {
override fun toString() = "PropertyMetadata(name=$name)"
}
@@ -41,7 +41,7 @@ import java.io.InputStream;
import java.util.*;
import static kotlin.CollectionsKt.*;
import static kotlin.SetsKt.*;
import static kotlin.SetsKt.setOf;
import static org.jetbrains.kotlin.builtins.PrimitiveType.*;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName;
@@ -702,11 +702,6 @@ public abstract class KotlinBuiltIns {
return getBuiltInClassByName("PropertyMetadata");
}
@NotNull
public ClassDescriptor getPropertyMetadataImpl() {
return getBuiltInClassByName("PropertyMetadataImpl");
}
@NotNull
public AnnotationDescriptor createExtensionAnnotation() {
return new AnnotationDescriptorImpl(getBuiltInClassByName(FQ_NAMES.extension.shortName()).getDefaultType(),
@@ -22,6 +22,9 @@ import java.lang.reflect.Modifier
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
@@ -35,12 +38,27 @@ internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
public fun copy(): DescriptorRendererOptionsImpl {
val copy = DescriptorRendererOptionsImpl()
//TODO: use Kotlin reflection when it's ready
for (field in this.javaClass.getDeclaredFields()) {
if (field.getModifiers().and(Modifier.STATIC) != 0) continue
field.setAccessible(true)
//TODO: use Kotlin reflection
for (field in this.javaClass.declaredFields) {
if (field.modifiers.and(Modifier.STATIC) != 0) continue
field.isAccessible = true
val property = field.get(this) as? ObservableProperty<*> ?: continue
val value = property.getValue(this, PropertyMetadataImpl("")/* not used*/)
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 */
})
field.set(copy, copy.property(value as Any))
}
@@ -21,10 +21,13 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.name.FqNameUnsafe
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
import org.jetbrains.kotlin.types.typeUtil.*
import org.jetbrains.kotlin.util.OperatorNameConventions.GET
import org.jetbrains.kotlin.util.OperatorNameConventions.SET
@@ -35,7 +38,6 @@ import org.jetbrains.kotlin.util.OperatorNameConventions.NEXT
import org.jetbrains.kotlin.util.OperatorNameConventions.HAS_NEXT
import org.jetbrains.kotlin.util.OperatorNameConventions.EQUALS
import org.jetbrains.kotlin.util.OperatorNameConventions.COMPARE_TO
import org.jetbrains.kotlin.util.OperatorNameConventions.UNARY_OPERATION_NAMES
import org.jetbrains.kotlin.util.OperatorNameConventions.BINARY_OPERATION_NAMES
import org.jetbrains.kotlin.util.OperatorNameConventions.ASSIGNMENT_OPERATIONS
import org.jetbrains.kotlin.util.OperatorNameConventions.COMPONENT_REGEX
@@ -64,8 +66,8 @@ object OperatorChecks {
valueParameters.size >= 2 && lastIsOk
}
GET_VALUE == name -> noDefaultsAndVarargs && valueParameters.size >= 2 && valueParameters[1].isPropertyMetadata
SET_VALUE == name -> noDefaultsAndVarargs && valueParameters.size >= 3 && valueParameters[1].isPropertyMetadata
GET_VALUE == name -> noDefaultsAndVarargs && valueParameters.size >= 2 && valueParameters[1].isKProperty
SET_VALUE == name -> noDefaultsAndVarargs && valueParameters.size >= 3 && valueParameters[1].isKProperty
INVOKE == name -> isMemberOrExtension
CONTAINS == name -> singleValueParameter && noDefaultsAndVarargs && returnsBoolean
@@ -100,8 +102,11 @@ object OperatorChecks {
}
}
private val ValueParameterDescriptor.isPropertyMetadata: Boolean
get() = builtIns.propertyMetadata.defaultType.isSubtypeOf(type.makeNotNullable())
private val ValueParameterDescriptor.isKProperty: Boolean
get() {
val kProperty = module.findClassAcrossModuleDependencies(ClassId.topLevel(FqName("kotlin.reflect.KProperty")))
return kProperty!!.defaultType.isSubtypeOf(type.makeNotNullable())
}
private val FunctionDescriptor.isMember: Boolean
get() = containingDeclaration is ClassDescriptor
@@ -0,0 +1,20 @@
/*
* 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.")
data class PropertyMetadataImpl(override val name: String) : PropertyMetadata