Insert KProperty<*> when creating property delegate methods in IDE
This commit is contained in:
@@ -128,7 +128,7 @@ public class DelegatedPropertyResolver {
|
||||
|
||||
@NotNull
|
||||
private static JetExpression createExpressionForProperty(@NotNull JetPsiFactory psiFactory) {
|
||||
return psiFactory.createExpression("null as kotlin.reflect.KProperty<*>");
|
||||
return psiFactory.createExpression("null as " + KotlinBuiltIns.FQ_NAMES.kProperty.asSingleFqName().asString() + "<*>");
|
||||
}
|
||||
|
||||
public void resolveDelegatedPropertyPDMethod(
|
||||
|
||||
@@ -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
|
||||
|
||||
+4
-2
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||
|
||||
import com.intellij.util.SmartList
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.psi.JetProperty
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
object CreatePropertyDelegateAccessorsActionFactory : CreateCallableMemberFromUsageFactory<JetExpression>() {
|
||||
@@ -54,7 +55,8 @@ object CreatePropertyDelegateAccessorsActionFactory : CreateCallableMemberFromUs
|
||||
val accessorReceiverType = TypeInfo(element, Variance.IN_VARIANCE)
|
||||
val builtIns = propertyDescriptor.builtIns
|
||||
val thisRefParam = ParameterInfo(TypeInfo(propertyReceiver?.type ?: builtIns.nullableNothingType, Variance.IN_VARIANCE))
|
||||
val metadataParam = ParameterInfo(TypeInfo(builtIns.propertyMetadata.defaultType, Variance.IN_VARIANCE))
|
||||
val kPropertyStarType = ReflectionTypes.createKPropertyStarType(propertyDescriptor.module) ?: return emptyList()
|
||||
val metadataParam = ParameterInfo(TypeInfo(kPropertyStarType, Variance.IN_VARIANCE), "property")
|
||||
|
||||
val callableInfos = SmartList<CallableInfo>()
|
||||
|
||||
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
// "Create member function 'getValue'" "true"
|
||||
class F {
|
||||
fun getValue(x: X, propertyMetadata: PropertyMetadata): Int {
|
||||
fun getValue(x: X, property: KProperty<*>): Int {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -1,10 +1,12 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
// "Create member function 'getValue', function 'setValue'" "true"
|
||||
class F {
|
||||
fun getValue(x: X, propertyMetadata: PropertyMetadata): Int {
|
||||
fun getValue(x: X, property: KProperty<*>): Int {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
fun setValue(x: X, propertyMetadata: PropertyMetadata, i: Int) {
|
||||
fun setValue(x: X, property: KProperty<*>, i: Int) {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
// "Create member function 'getValue'" "true"
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class F {
|
||||
fun setValue(x: X, propertyMetadata: PropertyMetadata, i: Int) { }
|
||||
fun setValue(x: X, property: KProperty<*>, i: Int) { }
|
||||
}
|
||||
|
||||
class X {
|
||||
|
||||
Vendored
+5
-3
@@ -1,8 +1,10 @@
|
||||
// "Create member function 'getValue'" "true"
|
||||
class F {
|
||||
fun setValue(x: X, propertyMetadata: PropertyMetadata, i: Int) { }
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
fun getValue(x: X, propertyMetadata: PropertyMetadata): Int {
|
||||
class F {
|
||||
fun setValue(x: X, property: KProperty<*>, i: Int) { }
|
||||
|
||||
fun getValue(x: X, property: KProperty<*>): Int {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
// "Create member function 'setValue'" "true"
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class F {
|
||||
fun getValue(x: X, propertyMetadata: PropertyMetadata): Int = 1
|
||||
fun getValue(x: X, property: KProperty<*>): Int = 1
|
||||
}
|
||||
|
||||
class X {
|
||||
|
||||
Vendored
+5
-3
@@ -1,8 +1,10 @@
|
||||
// "Create member function 'setValue'" "true"
|
||||
class F {
|
||||
fun getValue(x: X, propertyMetadata: PropertyMetadata): Int = 1
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
fun setValue(x: X, propertyMetadata: PropertyMetadata, i: Int) {
|
||||
class F {
|
||||
fun getValue(x: X, property: KProperty<*>): Int = 1
|
||||
|
||||
fun setValue(x: X, property: KProperty<*>, i: Int) {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user