Smart completion after "by" works for getValue/setValue in generic class
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.descriptors;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.ReadOnly;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.kotlin.types.KotlinType;
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ public interface CallableDescriptor extends DeclarationDescriptorWithVisibility,
|
|||||||
ReceiverParameterDescriptor getDispatchReceiverParameter();
|
ReceiverParameterDescriptor getDispatchReceiverParameter();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ReadOnly
|
||||||
List<TypeParameterDescriptor> getTypeParameters();
|
List<TypeParameterDescriptor> getTypeParameters();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
class X<T>(t: T) {
|
||||||
|
operator fun getValue(thisRef: C<T>, property: KProperty<*>): T = throw Exception()
|
||||||
|
}
|
||||||
|
|
||||||
|
class C<T> {
|
||||||
|
val property by <caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: lazy
|
||||||
|
// EXIST: { itemText: "X", tailText: "(t: T) (<root>)" }
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
class X<T>(t: T) {
|
||||||
|
operator fun getValue(thisRef: C<T>, property: KProperty<*>): T = throw Exception()
|
||||||
|
}
|
||||||
|
|
||||||
|
class C<T> {
|
||||||
|
val property: T by <caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: lazy
|
||||||
|
// EXIST: { itemText: "X", tailText: "(t: T) (<root>)" }
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
class X<T>(t: T) {
|
||||||
|
operator fun getValue(thisRef: C<String, T>, property: KProperty<*>): T = throw Exception()
|
||||||
|
}
|
||||||
|
|
||||||
|
class C<T1, T2> {
|
||||||
|
val property: T2 by <caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: lazy
|
||||||
|
// ABSENT: X
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
class X<T>(t: T) {
|
||||||
|
operator fun getValue(thisRef: C<T>, property: KProperty<*>): T = throw Exception()
|
||||||
|
operator fun setValue(thisRef: C<T>, property: KProperty<*>, t: T) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class C<T> {
|
||||||
|
var property by <caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: { itemText: "X", tailText: "(t: T) (<root>)" }
|
||||||
+24
@@ -1534,11 +1534,35 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ValInGenericClass1.kt")
|
||||||
|
public void testValInGenericClass1() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/propertyDelegate/ValInGenericClass1.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ValInGenericClass2.kt")
|
||||||
|
public void testValInGenericClass2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/propertyDelegate/ValInGenericClass2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ValInGenericClass3.kt")
|
||||||
|
public void testValInGenericClass3() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/propertyDelegate/ValInGenericClass3.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("VarInClass.kt")
|
@TestMetadata("VarInClass.kt")
|
||||||
public void testVarInClass() throws Exception {
|
public void testVarInClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/propertyDelegate/VarInClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/propertyDelegate/VarInClass.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("VarInGenericClass.kt")
|
||||||
|
public void testVarInGenericClass() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/propertyDelegate/VarInGenericClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/idea-completion/testData/smart/smartCasts")
|
@TestMetadata("idea/idea-completion/testData/smart/smartCasts")
|
||||||
|
|||||||
@@ -64,7 +64,14 @@ abstract class TypesWithOperatorDetector(
|
|||||||
private fun MutableCollection<FunctionDescriptor>.addSuitableOperators(functions: Collection<FunctionDescriptor>): MutableCollection<FunctionDescriptor> {
|
private fun MutableCollection<FunctionDescriptor>.addSuitableOperators(functions: Collection<FunctionDescriptor>): MutableCollection<FunctionDescriptor> {
|
||||||
for (function in functions) {
|
for (function in functions) {
|
||||||
if (!function.isValidOperator()) continue
|
if (!function.isValidOperator()) continue
|
||||||
val substitutor = checkIsSuitableByType(function, function.typeParameters) ?: continue
|
|
||||||
|
var freeParameters = function.typeParameters
|
||||||
|
val containingClass = function.containingDeclaration as? ClassDescriptor
|
||||||
|
if (containingClass != null) {
|
||||||
|
freeParameters += containingClass.typeConstructor.parameters
|
||||||
|
}
|
||||||
|
|
||||||
|
val substitutor = checkIsSuitableByType(function, freeParameters) ?: continue
|
||||||
add(function.substitute(substitutor))
|
add(function.substitute(substitutor))
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
|
|||||||
Reference in New Issue
Block a user