Fixed smart completion of functions with "::"

#KT-6073 Fixed
This commit is contained in:
Valentin Kipyatkov
2014-10-20 16:13:07 +04:00
parent f2a83cdf29
commit e6dbfac232
7 changed files with 92 additions and 4 deletions
@@ -231,8 +231,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
if (functionExpectedInfos.isEmpty()) return null
fun toLookupElement(descriptor: FunctionDescriptor): LookupElement? {
val functionType = functionType(descriptor)
if (functionType == null) return null
val functionType = functionType(descriptor) ?: return null
val matchedExpectedInfos = functionExpectedInfos.filter { functionType.isSubtypeOf(it.type) }
if (matchedExpectedInfos.isEmpty()) return null
@@ -34,6 +34,8 @@ import org.jetbrains.jet.plugin.completion.*
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies
import org.jetbrains.jet.plugin.completion.handlers.WithTailInsertHandler
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor
class ArtificialElementInsertHandler(
val textBeforeCaret: String, val textAfterCaret: String, val shortenRefs: Boolean) : InsertHandler<LookupElement>{
@@ -155,8 +157,26 @@ fun MutableCollection<LookupElement>.addLookupElementsForNullable(factory: () ->
}
fun functionType(function: FunctionDescriptor): JetType? {
val extensionReceiverType = function.getExtensionReceiverParameter()?.getType()
val memberReceiverType = if (function is ConstructorDescriptor) {
val classDescriptor = function.getContainingDeclaration()
if (classDescriptor.isInner()) {
(classDescriptor.getContainingDeclaration() as? ClassifierDescriptor)?.getDefaultType()
}
else {
null
}
}
else {
(function.getContainingDeclaration() as? ClassifierDescriptor)?.getDefaultType()
}
//TODO: this is to be changed when references to member extensions supported
val receiverType = if (extensionReceiverType != null && memberReceiverType != null)
null
else
extensionReceiverType ?: memberReceiverType
return KotlinBuiltIns.getInstance().getFunctionType(function.getAnnotations(),
null,
receiverType,
function.getValueParameters().map { it.getType() },
function.getReturnType() ?: return null)
}
@@ -0,0 +1,19 @@
class C {
fun foo(s: String): Boolean = true
fun bar() {
listOf("a").filter(<caret>)
}
class object {
fun staticFoo(s: String): Boolean = true
}
}
fun C.extensionFoo(s: String): Boolean = true
fun globalFoo(s: String): Boolean = true
// ABSENT: ::foo
// ABSENT: ::staticFoo
// ABSENT: ::extensionFoo
// EXIST: ::globalFoo
@@ -0,0 +1,19 @@
import kotlin.platform.platformName
class C(i: Int){
class Nested
inner class Inner
fun bar() {
foo(<caret>)
}
}
platformName("foo1")
fun foo(p: () -> C.Nested){}
platformName("foo2")
fun foo(p: () -> C.Inner){}
// EXIST: ::Nested
// ABSENT: ::Inner
@@ -0,0 +1,13 @@
class C {
fun foo(p: C.() -> Unit){}
fun bar() {
foo(<caret>)
}
fun f1(){}
fun C.f2(){}
}
// EXIST: ::f1
// ABSENT: ::f2
@@ -7,5 +7,5 @@ fun bar() {
fun String.f1(){}
fun f2(){}
// EXIST: ::f1
// EXIST: String::f1
// ABSENT: ::f2
@@ -198,6 +198,24 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
doTest(fileName);
}
@TestMetadata("FunctionReference10.kt")
public void testFunctionReference10() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/FunctionReference10.kt");
doTest(fileName);
}
@TestMetadata("FunctionReference11.kt")
public void testFunctionReference11() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/FunctionReference11.kt");
doTest(fileName);
}
@TestMetadata("FunctionReference12.kt")
public void testFunctionReference12() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/FunctionReference12.kt");
doTest(fileName);
}
@TestMetadata("FunctionReference3.kt")
public void testFunctionReference3() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/FunctionReference3.kt");