diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index e82fd6a4c44..b89a281fea6 100755 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -1036,11 +1036,15 @@ fun main(args: Array) { testGroup("idea/idea-completion/tests", "idea/idea-completion/testData") { testClass { - model("injava", extension = "java") + model("injava", extension = "java", recursive = false) } testClass { - model("injava", extension = "java") + model("injava", extension = "java", recursive = false) + } + + testClass { + model("injava/stdlib", extension = "java", recursive = false) } testClass { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/KotlinShortNamesCache.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/KotlinShortNamesCache.kt index 0a294091b31..293e76726cd 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/KotlinShortNamesCache.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/KotlinShortNamesCache.kt @@ -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 { - val effectiveScope = KotlinSourceFilterScope.sourcesAndLibraries(scope, project) + val effectiveScope = kotlinDeclarationsVisibleFromJavaScope(scope) val allFqNames = HashSet() 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) { dest.addAll(allClassNames) } diff --git a/idea/idea-completion/testData/injava/stdlib/List.java b/idea/idea-completion/testData/injava/stdlib/List.java new file mode 100644 index 00000000000..953c2a0cc86 --- /dev/null +++ b/idea/idea-completion/testData/injava/stdlib/List.java @@ -0,0 +1,9 @@ +public class Testing { + public static void test() { + List + } +} + +// EXIST: EmptyList +// EXIST: { lookupString:List,tailText:" (java.util)" } +// ABSENT: { lookupString:List,tailText:" (kotlin.collections)" } \ No newline at end of file diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/AbstractKotlinStdLibInJavaCompletionTest.kt b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/AbstractKotlinStdLibInJavaCompletionTest.kt new file mode 100644 index 00000000000..9a05e4ae6d8 --- /dev/null +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/AbstractKotlinStdLibInJavaCompletionTest.kt @@ -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 +} \ No newline at end of file diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/CompiledKotlinInJavaCompletionTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/CompiledKotlinInJavaCompletionTestGenerated.java index 7d4f27ff7c6..4e267a656e8 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/CompiledKotlinInJavaCompletionTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/CompiledKotlinInJavaCompletionTestGenerated.java @@ -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") diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinSourceInJavaCompletionTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinSourceInJavaCompletionTestGenerated.java index 508e4b48f92..ee31cb7b330 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinSourceInJavaCompletionTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinSourceInJavaCompletionTestGenerated.java @@ -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") diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinStdLibInJavaCompletionTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinStdLibInJavaCompletionTestGenerated.java new file mode 100644 index 00000000000..695b67ceabf --- /dev/null +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinStdLibInJavaCompletionTestGenerated.java @@ -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); + } +}