Property types supported in smart completion without "::"

This commit is contained in:
Valentin Kipyatkov
2015-10-02 12:44:04 +03:00
parent aaf507121f
commit b0d31fc86d
4 changed files with 32 additions and 5 deletions
@@ -76,6 +76,8 @@ class SmartCompletion(
public val expectedInfos: Collection<ExpectedInfo> = calcExpectedInfos(expressionWithType)
private val callableTypeExpectedInfo = expectedInfos.filterCallableExpected()
public val smartCastCalculator: SmartCastCalculator by lazy(LazyThreadSafetyMode.NONE) {
SmartCastCalculator(bindingContext, resolutionFacade.moduleDescriptor, expression)
}
@@ -162,7 +164,7 @@ class SmartCompletion(
}
if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) {
toFunctionReferenceLookupElement(descriptor, expectedInfos.filterFunctionExpected())?.let { result.add(it) }
toCallableReferenceLookupElement(descriptor, callableTypeExpectedInfo)?.let { result.add(it) }
}
return result
@@ -313,11 +315,11 @@ class SmartCompletion(
return null
}
private fun toFunctionReferenceLookupElement(descriptor: DeclarationDescriptor,
private fun toCallableReferenceLookupElement(descriptor: DeclarationDescriptor,
functionExpectedInfos: Collection<ExpectedInfo>): LookupElement? {
if (functionExpectedInfos.isEmpty()) return null
fun toLookupElement(descriptor: FunctionDescriptor): LookupElement? {
fun toLookupElement(descriptor: CallableDescriptor): LookupElement? {
val callableReferenceType = descriptor.callableReferenceType(resolutionFacade) ?: return null
val matchedExpectedInfos = functionExpectedInfos.filter { it.matchingSubstitutor(callableReferenceType) != null }
@@ -342,10 +344,10 @@ class SmartCompletion(
.addTailAndNameSimilarity(matchedExpectedInfos)
}
if (descriptor is SimpleFunctionDescriptor) {
if (descriptor is CallableDescriptor) {
return toLookupElement(descriptor)
}
else if (descriptor is ClassDescriptor && descriptor.getModality() != Modality.ABSTRACT) {
else if (descriptor is ClassDescriptor && descriptor.modality != Modality.ABSTRACT) {
val constructors = descriptor.getConstructors().filter(visibilityFilter)
if (constructors.size() == 1) {
//TODO: this code is to be changed if overloads to start work after ::
@@ -321,3 +321,6 @@ fun DeclarationDescriptor.fuzzyTypesForSmartCompletion(
fun Collection<ExpectedInfo>.filterFunctionExpected()
= filter { it.fuzzyType != null && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it.fuzzyType!!.type) }
fun Collection<ExpectedInfo>.filterCallableExpected()
= filter { it.fuzzyType != null && ReflectionTypes.isCallableType(it.fuzzyType!!.type) }
@@ -0,0 +1,16 @@
import kotlin.reflect.KProperty
fun foo(property: KProperty<Int>) {
}
fun bar() {
foo(<caret>)
}
val vInt = 0
val vString = ""
fun fInt() = 0
// EXIST: { lookupString: "::vInt", itemText: "::vInt", tailText: " (<root>)", typeText: "Int" }
// ABSENT: ::vString
// ABSENT: ::fInt
@@ -673,6 +673,12 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
doTest(fileName);
}
@TestMetadata("NoQualifierPropertyExpected.kt")
public void testNoQualifierPropertyExpected() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/callableReference/NoQualifierPropertyExpected.kt");
doTest(fileName);
}
@TestMetadata("NonEmptyQualifier1.kt")
public void testNonEmptyQualifier1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/callableReference/NonEmptyQualifier1.kt");