Property types supported in smart completion without "::"
This commit is contained in:
+7
-5
@@ -76,6 +76,8 @@ class SmartCompletion(
|
|||||||
|
|
||||||
public val expectedInfos: Collection<ExpectedInfo> = calcExpectedInfos(expressionWithType)
|
public val expectedInfos: Collection<ExpectedInfo> = calcExpectedInfos(expressionWithType)
|
||||||
|
|
||||||
|
private val callableTypeExpectedInfo = expectedInfos.filterCallableExpected()
|
||||||
|
|
||||||
public val smartCastCalculator: SmartCastCalculator by lazy(LazyThreadSafetyMode.NONE) {
|
public val smartCastCalculator: SmartCastCalculator by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
SmartCastCalculator(bindingContext, resolutionFacade.moduleDescriptor, expression)
|
SmartCastCalculator(bindingContext, resolutionFacade.moduleDescriptor, expression)
|
||||||
}
|
}
|
||||||
@@ -162,7 +164,7 @@ class SmartCompletion(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) {
|
if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) {
|
||||||
toFunctionReferenceLookupElement(descriptor, expectedInfos.filterFunctionExpected())?.let { result.add(it) }
|
toCallableReferenceLookupElement(descriptor, callableTypeExpectedInfo)?.let { result.add(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -313,11 +315,11 @@ class SmartCompletion(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toFunctionReferenceLookupElement(descriptor: DeclarationDescriptor,
|
private fun toCallableReferenceLookupElement(descriptor: DeclarationDescriptor,
|
||||||
functionExpectedInfos: Collection<ExpectedInfo>): LookupElement? {
|
functionExpectedInfos: Collection<ExpectedInfo>): LookupElement? {
|
||||||
if (functionExpectedInfos.isEmpty()) return null
|
if (functionExpectedInfos.isEmpty()) return null
|
||||||
|
|
||||||
fun toLookupElement(descriptor: FunctionDescriptor): LookupElement? {
|
fun toLookupElement(descriptor: CallableDescriptor): LookupElement? {
|
||||||
val callableReferenceType = descriptor.callableReferenceType(resolutionFacade) ?: return null
|
val callableReferenceType = descriptor.callableReferenceType(resolutionFacade) ?: return null
|
||||||
|
|
||||||
val matchedExpectedInfos = functionExpectedInfos.filter { it.matchingSubstitutor(callableReferenceType) != null }
|
val matchedExpectedInfos = functionExpectedInfos.filter { it.matchingSubstitutor(callableReferenceType) != null }
|
||||||
@@ -342,10 +344,10 @@ class SmartCompletion(
|
|||||||
.addTailAndNameSimilarity(matchedExpectedInfos)
|
.addTailAndNameSimilarity(matchedExpectedInfos)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor is SimpleFunctionDescriptor) {
|
if (descriptor is CallableDescriptor) {
|
||||||
return toLookupElement(descriptor)
|
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)
|
val constructors = descriptor.getConstructors().filter(visibilityFilter)
|
||||||
if (constructors.size() == 1) {
|
if (constructors.size() == 1) {
|
||||||
//TODO: this code is to be changed if overloads to start work after ::
|
//TODO: this code is to be changed if overloads to start work after ::
|
||||||
|
|||||||
@@ -321,3 +321,6 @@ fun DeclarationDescriptor.fuzzyTypesForSmartCompletion(
|
|||||||
fun Collection<ExpectedInfo>.filterFunctionExpected()
|
fun Collection<ExpectedInfo>.filterFunctionExpected()
|
||||||
= filter { it.fuzzyType != null && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it.fuzzyType!!.type) }
|
= filter { it.fuzzyType != null && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it.fuzzyType!!.type) }
|
||||||
|
|
||||||
|
fun Collection<ExpectedInfo>.filterCallableExpected()
|
||||||
|
= filter { it.fuzzyType != null && ReflectionTypes.isCallableType(it.fuzzyType!!.type) }
|
||||||
|
|
||||||
|
|||||||
+16
@@ -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
|
||||||
+6
@@ -673,6 +673,12 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("NonEmptyQualifier1.kt")
|
||||||
public void testNonEmptyQualifier1() throws Exception {
|
public void testNonEmptyQualifier1() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/callableReference/NonEmptyQualifier1.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/callableReference/NonEmptyQualifier1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user