Extension SAM-adapters shown in completion
This commit is contained in:
+16
-3
@@ -42,7 +42,8 @@ import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import java.util.*
|
||||
import java.util.HashSet
|
||||
import java.util.LinkedHashSet
|
||||
|
||||
public class ReferenceVariantsHelper(
|
||||
private val context: BindingContext,
|
||||
@@ -185,11 +186,23 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
if (!kindFilter.excludes.contains(DescriptorKindExclude.Extensions)) {
|
||||
for (extension in resolutionScope.getSyntheticExtensionProperties(receiverTypes)) {
|
||||
if (nameFilter(extension.getName()) && kindFilter.accepts(extension)) {
|
||||
fun processExtension(extension: CallableDescriptor) {
|
||||
if (nameFilter(extension.name) && kindFilter.accepts(extension)) {
|
||||
addAll(extension.substituteExtensionIfCallable(receiverValue, callType, context, dataFlowInfo, containingDeclaration))
|
||||
}
|
||||
}
|
||||
|
||||
if (kindFilter.acceptsKinds(DescriptorKindFilter.VARIABLES_MASK)) {
|
||||
for (extension in resolutionScope.getSyntheticExtensionProperties(receiverTypes)) {
|
||||
processExtension(extension)
|
||||
}
|
||||
}
|
||||
|
||||
if (kindFilter.acceptsKinds(DescriptorKindFilter.FUNCTIONS_MASK)) {
|
||||
for (extension in resolutionScope.getSyntheticExtensionFunctions(receiverTypes)) {
|
||||
processExtension(extension)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
@@ -263,6 +264,9 @@ public class LookupElementFactory(
|
||||
element = element.appendTailText(" (from $from)", true)
|
||||
}
|
||||
|
||||
// no need to show them as extensions
|
||||
original is SamAdapterExtensionFunctionDescriptor -> {}
|
||||
|
||||
extensionReceiver != null -> {
|
||||
val receiverPresentation = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(extensionReceiver.type)
|
||||
element = element.appendTailText(" for $receiverPresentation", true)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
fun foo() {
|
||||
javax.swing.SwingUtilities.invoke<caret>
|
||||
}
|
||||
|
||||
// EXIST_JAVA_ONLY: { lookupString: "invokeLater", itemText: "invokeLater", tailText: "(Runnable!)", typeText: "Unit" }
|
||||
// EXIST_JAVA_ONLY: { lookupString: "invokeLater", itemText: "invokeLater", tailText: " {...} ((() -> Unit)!)", typeText: "Unit" }
|
||||
@@ -0,0 +1,6 @@
|
||||
import lib.JavaClass
|
||||
|
||||
fun test() = JavaClass().<caret>
|
||||
|
||||
// EXIST: { lookupString: "execute", itemText: "execute", tailText: "(Runnable!)", typeText: "Unit" }
|
||||
// EXIST: { lookupString: "execute", itemText: "execute", tailText: " {...} ((() -> Unit)!)", typeText: "Unit" }
|
||||
@@ -0,0 +1,5 @@
|
||||
package lib;
|
||||
|
||||
public class JavaClass {
|
||||
public void execute(Runnable runnable) {}
|
||||
}
|
||||
+6
@@ -769,6 +769,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SAMAdaptersStatic.kt")
|
||||
public void testSAMAdaptersStatic() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/SAMAdaptersStatic.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SafeCallAfterNullable.kt")
|
||||
public void testSafeCallAfterNullable() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/SafeCallAfterNullable.kt");
|
||||
|
||||
+6
@@ -769,6 +769,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SAMAdaptersStatic.kt")
|
||||
public void testSAMAdaptersStatic() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/SAMAdaptersStatic.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SafeCallAfterNullable.kt")
|
||||
public void testSafeCallAfterNullable() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/SafeCallAfterNullable.kt");
|
||||
|
||||
+6
@@ -47,6 +47,12 @@ public class JvmWithLibBasicCompletionTestGenerated extends AbstractJvmWithLibBa
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SAMAdapters.kt")
|
||||
public void testSAMAdapters() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/custom/SAMAdapters.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("TopLevelNonImportedExtFun.kt")
|
||||
public void testTopLevelNonImportedExtFun() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/custom/TopLevelNonImportedExtFun.kt");
|
||||
|
||||
Reference in New Issue
Block a user