Make sure java completion doesn't suggest classes from builtIns
Fix an undesirable sideeffect of previous changes
This commit is contained in:
@@ -1036,11 +1036,15 @@ fun main(args: Array<String>) {
|
||||
|
||||
testGroup("idea/idea-completion/tests", "idea/idea-completion/testData") {
|
||||
testClass<AbstractCompiledKotlinInJavaCompletionTest> {
|
||||
model("injava", extension = "java")
|
||||
model("injava", extension = "java", recursive = false)
|
||||
}
|
||||
|
||||
testClass<AbstractKotlinSourceInJavaCompletionTest> {
|
||||
model("injava", extension = "java")
|
||||
model("injava", extension = "java", recursive = false)
|
||||
}
|
||||
|
||||
testClass<AbstractKotlinStdLibInJavaCompletionTest> {
|
||||
model("injava/stdlib", extension = "java", recursive = false)
|
||||
}
|
||||
|
||||
testClass<AbstractBasicCompletionWeigherTest> {
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.caches
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiField
|
||||
import com.intellij.psi.PsiMethod
|
||||
@@ -31,6 +33,7 @@ import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
|
||||
import org.jetbrains.kotlin.asJava.getAccessorLightMethods
|
||||
import org.jetbrains.kotlin.asJava.getAccessorNamesCandidatesByPropertyName
|
||||
import org.jetbrains.kotlin.fileClasses.javaFileFacadeFqName
|
||||
import org.jetbrains.kotlin.idea.decompiler.builtIns.KotlinBuiltInFileType
|
||||
import org.jetbrains.kotlin.idea.stubindex.*
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.load.java.getPropertyNamesCandidatesByAccessorName
|
||||
@@ -56,7 +59,7 @@ class KotlinShortNamesCache(private val project: Project) : PsiShortNamesCache()
|
||||
* Return class names form kotlin sources in given scope which should be visible as Java classes.
|
||||
*/
|
||||
override fun getClassesByName(name: String, scope: GlobalSearchScope): Array<PsiClass> {
|
||||
val effectiveScope = KotlinSourceFilterScope.sourcesAndLibraries(scope, project)
|
||||
val effectiveScope = kotlinDeclarationsVisibleFromJavaScope(scope)
|
||||
val allFqNames = HashSet<FqName?>()
|
||||
|
||||
KotlinClassShortNameIndex.getInstance().get(name, project, effectiveScope)
|
||||
@@ -85,6 +88,16 @@ class KotlinShortNamesCache(private val project: Project) : PsiShortNamesCache()
|
||||
return result.toTypedArray()
|
||||
}
|
||||
|
||||
private fun kotlinDeclarationsVisibleFromJavaScope(scope: GlobalSearchScope): GlobalSearchScope {
|
||||
val noBuiltInsScope: GlobalSearchScope = object : GlobalSearchScope(project) {
|
||||
override fun isSearchInModuleContent(aModule: Module) = true
|
||||
override fun compare(file1: VirtualFile, file2: VirtualFile) = 0
|
||||
override fun isSearchInLibraries() = true
|
||||
override fun contains(file: VirtualFile) = file.fileType != KotlinBuiltInFileType
|
||||
}
|
||||
return KotlinSourceFilterScope.sourceAndClassFiles(scope, project).intersectWith(noBuiltInsScope)
|
||||
}
|
||||
|
||||
override fun getAllClassNames(dest: HashSet<String>) {
|
||||
dest.addAll(allClassNames)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
public class Testing {
|
||||
public static void test() {
|
||||
List<caret>
|
||||
}
|
||||
}
|
||||
|
||||
// EXIST: EmptyList
|
||||
// EXIST: { lookupString:List,tailText:"<E> (java.util)" }
|
||||
// ABSENT: { lookupString:List,tailText:"<E> (kotlin.collections)" }
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.completion.test
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
|
||||
abstract class AbstractKotlinStdLibInJavaCompletionTest : KotlinFixtureCompletionBaseTestCase() {
|
||||
override fun getPlatform() = JvmPlatform
|
||||
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
override fun defaultCompletionType() = CompletionType.BASIC
|
||||
}
|
||||
+1
-1
@@ -33,7 +33,7 @@ import java.util.regex.Pattern;
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class CompiledKotlinInJavaCompletionTestGenerated extends AbstractCompiledKotlinInJavaCompletionTest {
|
||||
public void testAllFilesPresentInInjava() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/injava"), Pattern.compile("^(.+)\\.java$"), TargetBackend.ANY, true);
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/injava"), Pattern.compile("^(.+)\\.java$"), TargetBackend.ANY, false);
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotationParameter.java")
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ import java.util.regex.Pattern;
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class KotlinSourceInJavaCompletionTestGenerated extends AbstractKotlinSourceInJavaCompletionTest {
|
||||
public void testAllFilesPresentInInjava() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/injava"), Pattern.compile("^(.+)\\.java$"), TargetBackend.ANY, true);
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/injava"), Pattern.compile("^(.+)\\.java$"), TargetBackend.ANY, false);
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotationParameter.java")
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
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/injava/stdlib")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class KotlinStdLibInJavaCompletionTestGenerated extends AbstractKotlinStdLibInJavaCompletionTest {
|
||||
public void testAllFilesPresentInStdlib() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/injava/stdlib"), Pattern.compile("^(.+)\\.java$"), TargetBackend.ANY, false);
|
||||
}
|
||||
|
||||
@TestMetadata("List.java")
|
||||
public void testList() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/injava/stdlib/List.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user