Fix expect declarations available in completion in platform modules

This commit is contained in:
Pavel V. Talanov
2018-03-28 18:06:19 +02:00
parent 549bebbd19
commit c3d2334eed
14 changed files with 136 additions and 2 deletions
@@ -877,6 +877,10 @@ fun main(args: Array<String>) {
testClass<AbstractCompletionIncrementalResolveTest> {
model("incrementalResolve")
}
testClass<AbstractMultiPlatformCompletionTest> {
model("multiPlatform", recursive = false, extension = null)
}
}
//TODO: move these tests into idea-completion module
@@ -43,7 +43,9 @@ import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.util.*
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.MultiTargetPlatform
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.resolve.getMultiTargetPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
@@ -143,7 +145,12 @@ abstract class CompletionSession(
// LookupElementsCollector instantiation is deferred because virtual call to createSorter uses data from derived classes
protected val collector: LookupElementsCollector by lazy(LazyThreadSafetyMode.NONE) {
LookupElementsCollector({ CompletionBenchmarkSink.instance.onFlush(this) }, prefixMatcher, parameters, resultSet, createSorter(), (file as? KtCodeFragment)?.extraCompletionFilter)
LookupElementsCollector(
{ CompletionBenchmarkSink.instance.onFlush(this) },
prefixMatcher, parameters, resultSet,
createSorter(), (file as? KtCodeFragment)?.extraCompletionFilter,
moduleDescriptor.getMultiTargetPlatform() === MultiTargetPlatform.Common
)
}
protected val searchScope: GlobalSearchScope =
@@ -24,6 +24,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.patterns.ElementPattern
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.MemberDescriptor
import org.jetbrains.kotlin.idea.completion.handlers.WithExpressionPrefixInsertHandler
import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
@@ -35,7 +36,8 @@ class LookupElementsCollector(
private val completionParameters: CompletionParameters,
resultSet: CompletionResultSet,
sorter: CompletionSorter,
private val filter: ((LookupElement) -> Boolean)?
private val filter: ((LookupElement) -> Boolean)?,
private val allowExpectDeclarations: Boolean
) {
var bestMatchingDegree = Int.MIN_VALUE
@@ -102,6 +104,10 @@ class LookupElementsCollector(
fun addElement(element: LookupElement, notImported: Boolean = false) {
if (!prefixMatcher.prefixMatches(element)) return
if (!allowExpectDeclarations) {
val descriptor = (element.`object` as? DeclarationLookupObject)?.descriptor
if ((descriptor as? MemberDescriptor)?.isExpect == true) return
}
if (notImported) {
element.putUserData(NOT_IMPORTED_KEY, Unit)
@@ -0,0 +1,11 @@
package test
expect class Foo
fun use() {
Foo<caret>
}
// ABSENT: { lookupString: Foo, module: testModule_JVM }
// ABSENT: { lookupString: Foo, module: testModule_JS }
// EXIST: { lookupString: Foo, module: testModule_Common }
@@ -0,0 +1,3 @@
package test
actual class Foo
@@ -0,0 +1,3 @@
package test
actual class Foo
@@ -0,0 +1,4 @@
package test
expect class FooCl
expect object FooObj
@@ -0,0 +1,13 @@
package test
actual class FooCl
actual object FooObj
fun use() {
Fo<caret>
}
// EXIST: { lookupString: FooCl, module: testModule_JS }
// EXIST: { lookupString: FooObj, module: testModule_JS }
// ABSENT: { lookupString: FooCl, module: testModule_Common }
// ABSENT: { lookupString: FooObj, module: testModule_Common }
@@ -0,0 +1,11 @@
package test
expect fun foo()
fun use() {
foo<caret>
}
// ABSENT: { lookupString: foo, module: testModule_JVM }
// ABSENT: { lookupString: foo, module: testModule_JS }
// EXIST: { lookupString: foo, module: testModule_Common }
@@ -0,0 +1,3 @@
package test
actual fun foo() {}
@@ -0,0 +1,3 @@
package test
actual fun foo() {}
@@ -0,0 +1,3 @@
package test
expect fun foo()
@@ -0,0 +1,12 @@
package test
actual fun foo() {
}
fun use() {
foo<caret>
}
// EXIST: { lookupString: foo, module: testModule_JVM }
// ABSENT: { lookupString: foo, module: testModule_Common }
@@ -0,0 +1,51 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.completion.test;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/idea-completion/testData/multiPlatform")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class MultiPlatformCompletionTestGenerated extends AbstractMultiPlatformCompletionTest {
public void testAllFilesPresentInMultiPlatform() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/multiPlatform"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, false);
}
@TestMetadata("classInCommon")
public void testClassInCommon() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/multiPlatform/classInCommon/");
doTest(fileName);
}
@TestMetadata("classInPlatform")
public void testClassInPlatform() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/multiPlatform/classInPlatform/");
doTest(fileName);
}
@TestMetadata("functionInCommon")
public void testFunctionInCommon() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/multiPlatform/functionInCommon/");
doTest(fileName);
}
@TestMetadata("functionInPlatform")
public void testFunctionInPlatform() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/multiPlatform/functionInPlatform/");
doTest(fileName);
}
}