Insert KProperty<*> when creating property delegate methods in IDE
This commit is contained in:
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.descriptors.annotations.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
@@ -157,7 +158,9 @@ public abstract class KotlinBuiltIns {
|
||||
public final FqName mutableSet = fqName("MutableSet");
|
||||
public final FqName mutableMap = fqName("MutableMap");
|
||||
|
||||
public final FqNameUnsafe kClass = new FqName("kotlin.reflect.KClass").toUnsafe();
|
||||
public final FqNameUnsafe kClass = reflect("KClass");
|
||||
public final FqNameUnsafe kCallable = reflect("KCallable");
|
||||
public final ClassId kProperty = ClassId.topLevel(reflect("KProperty").toSafe());
|
||||
|
||||
public final Map<FqNameUnsafe, PrimitiveType> fqNameToPrimitiveType;
|
||||
public final Map<FqNameUnsafe, PrimitiveType> arrayClassFqNameToPrimitiveType;
|
||||
@@ -180,6 +183,11 @@ public abstract class KotlinBuiltIns {
|
||||
return BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier(simpleName));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static FqNameUnsafe reflect(@NotNull String simpleName) {
|
||||
return ReflectionTypesKt.getKOTLIN_REFLECT_FQ_NAME().child(Name.identifier(simpleName)).toUnsafe();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static FqName annotationName(@NotNull String simpleName) {
|
||||
return ANNOTATION_PACKAGE_FQ_NAME.child(Name.identifier(simpleName));
|
||||
@@ -697,11 +705,6 @@ public abstract class KotlinBuiltIns {
|
||||
return getAnnotation().getDefaultType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getPropertyMetadata() {
|
||||
return getBuiltInClassByName("PropertyMetadata");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AnnotationDescriptor createExtensionAnnotation() {
|
||||
return new AnnotationDescriptorImpl(getBuiltInClassByName(FQ_NAMES.extension.shortName()).getDefaultType(),
|
||||
|
||||
@@ -22,10 +22,10 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import java.util.*
|
||||
|
||||
@@ -115,8 +115,6 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
||||
return containingPackage != null && containingPackage.fqName == KOTLIN_REFLECT_FQ_NAME
|
||||
}
|
||||
|
||||
private val K_CALLABLE_FQ_NAME = FqNameUnsafe("kotlin.reflect.KCallable")
|
||||
|
||||
public fun isCallableType(type: JetType): Boolean =
|
||||
KotlinBuiltIns.isFunctionOrExtensionFunctionType(type) || isKCallableType(type)
|
||||
|
||||
@@ -126,7 +124,15 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
||||
|
||||
private fun isExactKCallableType(type: JetType): Boolean {
|
||||
val descriptor = type.constructor.declarationDescriptor
|
||||
return descriptor is ClassDescriptor && DescriptorUtils.getFqName(descriptor) == K_CALLABLE_FQ_NAME
|
||||
return descriptor is ClassDescriptor && DescriptorUtils.getFqName(descriptor) == KotlinBuiltIns.FQ_NAMES.kCallable
|
||||
}
|
||||
|
||||
public fun createKPropertyStarType(module: ModuleDescriptor): JetType? {
|
||||
val kPropertyClass = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.kProperty) ?: return null
|
||||
return JetTypeImpl.create(
|
||||
Annotations.EMPTY, kPropertyClass, false,
|
||||
listOf(StarProjectionImpl(kPropertyClass.typeConstructor.parameters.single()))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,17 +17,15 @@
|
||||
package org.jetbrains.kotlin.util
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||
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.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
|
||||
@@ -103,10 +101,7 @@ object OperatorChecks {
|
||||
}
|
||||
|
||||
private val ValueParameterDescriptor.isKProperty: Boolean
|
||||
get() {
|
||||
val kProperty = module.findClassAcrossModuleDependencies(ClassId.topLevel(FqName("kotlin.reflect.KProperty")))
|
||||
return kProperty!!.defaultType.isSubtypeOf(type.makeNotNullable())
|
||||
}
|
||||
get() = ReflectionTypes.createKPropertyStarType(module)?.isSubtypeOf(type.makeNotNullable()) ?: false
|
||||
|
||||
private val FunctionDescriptor.isMember: Boolean
|
||||
get() = containingDeclaration is ClassDescriptor
|
||||
|
||||
Reference in New Issue
Block a user