Overload callable references are now supported - changed code accordingly
This commit is contained in:
+11
-13
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
|||||||
import org.jetbrains.kotlin.types.JetType
|
import org.jetbrains.kotlin.types.JetType
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||||
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
|
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptySet
|
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptySet
|
||||||
@@ -164,7 +165,7 @@ class SmartCompletion(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) {
|
if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) {
|
||||||
toCallableReferenceLookupElement(descriptor)?.let { result.add(it) }
|
result.addCallableReferenceLookupElements(descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -315,8 +316,8 @@ class SmartCompletion(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toCallableReferenceLookupElement(descriptor: DeclarationDescriptor): LookupElement? {
|
private fun MutableCollection<LookupElement>.addCallableReferenceLookupElements(descriptor: DeclarationDescriptor) {
|
||||||
if (callableTypeExpectedInfo.isEmpty()) return null
|
if (callableTypeExpectedInfo.isEmpty()) return
|
||||||
|
|
||||||
fun toLookupElement(descriptor: CallableDescriptor): LookupElement? {
|
fun toLookupElement(descriptor: CallableDescriptor): LookupElement? {
|
||||||
val callableReferenceType = descriptor.callableReferenceType(resolutionFacade) ?: return null
|
val callableReferenceType = descriptor.callableReferenceType(resolutionFacade) ?: return null
|
||||||
@@ -345,24 +346,21 @@ class SmartCompletion(
|
|||||||
|
|
||||||
when (descriptor) {
|
when (descriptor) {
|
||||||
is CallableDescriptor -> {
|
is CallableDescriptor -> {
|
||||||
if (descriptor.dispatchReceiverParameter != null || descriptor.extensionReceiverParameter != null) {
|
// members and extensions are not supported after "::" currently
|
||||||
return null // members and extensions are not supported after "::" currently
|
if (descriptor.dispatchReceiverParameter == null && descriptor.extensionReceiverParameter == null) {
|
||||||
|
addIfNotNull(toLookupElement(descriptor))
|
||||||
}
|
}
|
||||||
return toLookupElement(descriptor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is ClassDescriptor -> {
|
is ClassDescriptor -> {
|
||||||
if (descriptor.modality != Modality.ABSTRACT && !descriptor.isInner) {
|
if (descriptor.modality != Modality.ABSTRACT && !descriptor.isInner) {
|
||||||
val constructors = descriptor.getConstructors().filter(visibilityFilter)
|
descriptor.constructors
|
||||||
if (constructors.size() == 1) {
|
.filter(visibilityFilter)
|
||||||
//TODO: this code is to be changed if overloads to start work after ::
|
.map { toLookupElement(it) }
|
||||||
return toLookupElement(constructors.single())
|
.filterNotNullTo(this)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildForAsTypePosition(): Collection<LookupElement>? {
|
private fun buildForAsTypePosition(): Collection<LookupElement>? {
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ fun bar(){
|
|||||||
foo(<caret>)
|
foo(<caret>)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ABSENT: ::Date
|
// EXIST: ::Date
|
||||||
|
|||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
class A {
|
||||||
|
fun foo(p: (Int) -> Any){}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo(<caret>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B() {
|
||||||
|
constructor(p: Int) : this(){}
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: ::B
|
||||||
+6
@@ -673,6 +673,12 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("NoQualifierMultipleConstructors.kt")
|
||||||
|
public void testNoQualifierMultipleConstructors() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/callableReference/NoQualifierMultipleConstructors.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("NoQualifierPropertyExpected.kt")
|
@TestMetadata("NoQualifierPropertyExpected.kt")
|
||||||
public void testNoQualifierPropertyExpected() throws Exception {
|
public void testNoQualifierPropertyExpected() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/callableReference/NoQualifierPropertyExpected.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/callableReference/NoQualifierPropertyExpected.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user