Better smart completion after "by" for override property with no explicit type specified

This commit is contained in:
Valentin Kipyatkov
2016-04-01 15:52:36 +03:00
parent f85de3aac7
commit 7af67da4ac
3 changed files with 37 additions and 0 deletions
@@ -0,0 +1,30 @@
import kotlin.reflect.KProperty
abstract class Base {
abstract val property: Number
}
class Derived : Base() {
override val property by <caret>
}
class X1 {
operator fun getValue(thisRef: Any, property: KProperty<*>): Number = 1
}
class X2 {
operator fun getValue(thisRef: Any, property: KProperty<*>): String = ""
}
class X3 {
operator fun getValue(thisRef: Any, property: KProperty<*>): Int = ""
}
// EXIST: lazy
// EXIST: { itemText: "Delegates.notNull", tailText:"() (kotlin.properties)", typeText: "ReadWriteProperty<Any?, Number>", attributes:"" }
// EXIST: { itemText: "Delegates.observable", tailText:"(initialValue: Number, crossinline onChange: (KProperty<*>, Number, Number) -> Unit) (kotlin.properties)", typeText: "ReadWriteProperty<Any?, Number>", attributes:"" }
// EXIST: { itemText: "Delegates.vetoable", tailText:"(initialValue: Number, crossinline onChange: (KProperty<*>, Number, Number) -> Boolean) (kotlin.properties)", typeText: "ReadWriteProperty<Any?, Number>", attributes:"" }
// EXIST: X1
// ABSENT: X2
// EXIST: X3
@@ -1540,6 +1540,12 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
doTest(fileName);
}
@TestMetadata("OverrideVal.kt")
public void testOverrideVal() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/propertyDelegate/OverrideVal.kt");
doTest(fileName);
}
@TestMetadata("TopLevelVal.kt")
public void testTopLevelVal() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/propertyDelegate/TopLevelVal.kt");
@@ -615,6 +615,7 @@ class ExpectedInfos(
?: property.builtIns.nullableNothingType.toFuzzyType(emptyList())
val explicitPropertyType = property.fuzzyReturnType()?.check { propertyDeclaration.typeReference != null }
?: property.overriddenDescriptors.singleOrNull()?.fuzzyReturnType() // for override properties use super property type as explicit (if not specified)
val typesWithGetDetector = TypesWithGetValueDetector(scope, indicesHelper, propertyOwnerType, explicitPropertyType)
val typesWithSetDetector = if (property.isVar) TypesWithSetValueDetector(scope, indicesHelper, propertyOwnerType) else null