diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 804830856b0..76c5d1e92c3 100644 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.codegen.flags.AbstractWriteFlagsTest import org.jetbrains.kotlin.codegen.generated.AbstractBlackBoxCodegenTest import org.jetbrains.kotlin.codegen.generated.AbstractBlackBoxInlineCodegenTest import org.jetbrains.kotlin.findUsages.AbstractJetFindUsagesTest +import org.jetbrains.kotlin.findUsages.AbstractKotlinFindUsagesInLibrarySourceTest import org.jetbrains.kotlin.formatter.AbstractJetFormatterTest import org.jetbrains.kotlin.formatter.AbstractJetTypingIndentationTestBase import org.jetbrains.kotlin.generators.tests.generator.* @@ -497,6 +498,10 @@ fun main(args: Array) { model("findUsages/java", pattern = """^(.+)\.0\.java$""") } + testClass(javaClass()) { + model("findUsages/librarySources", pattern = """^(.+)\.0\.kt$""") + } + testClass(javaClass()) { model("refactoring/move", extension = "test", singleClass = true) } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JavaResolveExtension.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JavaResolveExtension.kt index 529af2bea92..95cfd9a5edf 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JavaResolveExtension.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JavaResolveExtension.kt @@ -46,12 +46,13 @@ public object JavaResolveExtension : CacheExtension<(PsiElement) -> Pair resolver.resolveConstructor(JavaConstructorImpl(this)) - else -> resolver.resolveMethod(JavaMethodImpl(this)) + method.isConstructor() -> resolver.resolveConstructor(JavaConstructorImpl(method)) + else -> resolver.resolveMethod(JavaMethodImpl(method)) } - assert(methodDescriptor != null) { "No descriptor found for " + getText() } + assert(methodDescriptor != null) { "No descriptor found for " + method.getText() } return methodDescriptor!! } diff --git a/idea/testData/findUsages/_library/library/Foo.java b/idea/testData/findUsages/_library/library/Foo.java new file mode 100644 index 00000000000..22bd292c275 --- /dev/null +++ b/idea/testData/findUsages/_library/library/Foo.java @@ -0,0 +1,18 @@ +package library; + +public class Foo { + public int x; + public static int X; + + public Foo(int n) { + + } + + public void bar(int n) { + + } + + public static void baz(int n) { + + } +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryClassUsages.0.kt b/idea/testData/findUsages/librarySources/LibraryClassUsages.0.kt new file mode 100644 index 00000000000..e13dd51c382 --- /dev/null +++ b/idea/testData/findUsages/librarySources/LibraryClassUsages.0.kt @@ -0,0 +1,11 @@ +// PSI_ELEMENT: com.intellij.psi.PsiClass +// OPTIONS: usages +// FIND_BY_REF +// FIND_BY_NAVIGATION_ELEMENT +package usages + +import library.Foo + +fun test() { + val foo: Foo +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryClassUsages.results.txt b/idea/testData/findUsages/librarySources/LibraryClassUsages.results.txt new file mode 100644 index 00000000000..04929d95f2f --- /dev/null +++ b/idea/testData/findUsages/librarySources/LibraryClassUsages.results.txt @@ -0,0 +1,2 @@ +Local variable declaration (10: 14) val foo: Foo +Usage in import (7: 16) import library.Foo \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryConstructorUsages.0.kt b/idea/testData/findUsages/librarySources/LibraryConstructorUsages.0.kt new file mode 100644 index 00000000000..ea2916aad98 --- /dev/null +++ b/idea/testData/findUsages/librarySources/LibraryConstructorUsages.0.kt @@ -0,0 +1,11 @@ +// PSI_ELEMENT: com.intellij.psi.PsiMethod +// OPTIONS: usages +// FIND_BY_REF +// FIND_BY_NAVIGATION_ELEMENT +package usages + +import library.Foo + +fun test() { + Foo(1) +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryConstructorUsages.results.txt b/idea/testData/findUsages/librarySources/LibraryConstructorUsages.results.txt new file mode 100644 index 00000000000..e5ed6ddd7c2 --- /dev/null +++ b/idea/testData/findUsages/librarySources/LibraryConstructorUsages.results.txt @@ -0,0 +1 @@ +New instance creation (10: 5) Foo(1) \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryFieldUsages.0.kt b/idea/testData/findUsages/librarySources/LibraryFieldUsages.0.kt new file mode 100644 index 00000000000..950de36492e --- /dev/null +++ b/idea/testData/findUsages/librarySources/LibraryFieldUsages.0.kt @@ -0,0 +1,11 @@ +// PSI_ELEMENT: com.intellij.psi.PsiField +// OPTIONS: usages +// FIND_BY_REF +// FIND_BY_NAVIGATION_ELEMENT +package usages + +import library.Foo + +fun test() { + Foo().x = 1 +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryFieldUsages.results.txt b/idea/testData/findUsages/librarySources/LibraryFieldUsages.results.txt new file mode 100644 index 00000000000..d9142005099 --- /dev/null +++ b/idea/testData/findUsages/librarySources/LibraryFieldUsages.results.txt @@ -0,0 +1 @@ +Value write (10: 11) Foo().x = 1 \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryMethodUsages.0.kt b/idea/testData/findUsages/librarySources/LibraryMethodUsages.0.kt new file mode 100644 index 00000000000..d635467383f --- /dev/null +++ b/idea/testData/findUsages/librarySources/LibraryMethodUsages.0.kt @@ -0,0 +1,11 @@ +// PSI_ELEMENT: com.intellij.psi.PsiMethod +// OPTIONS: usages +// FIND_BY_REF +// FIND_BY_NAVIGATION_ELEMENT +package usages + +import library.Foo + +fun test() { + Foo().bar(1) +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryMethodUsages.results.txt b/idea/testData/findUsages/librarySources/LibraryMethodUsages.results.txt new file mode 100644 index 00000000000..6f3f7ae387b --- /dev/null +++ b/idea/testData/findUsages/librarySources/LibraryMethodUsages.results.txt @@ -0,0 +1 @@ +Function call (10: 11) Foo().bar(1) \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.0.kt b/idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.0.kt new file mode 100644 index 00000000000..99bc0c05624 --- /dev/null +++ b/idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.0.kt @@ -0,0 +1,11 @@ +// PSI_ELEMENT: com.intellij.psi.PsiField +// OPTIONS: usages +// FIND_BY_REF +// FIND_BY_NAVIGATION_ELEMENT +package usages + +import library.Foo + +fun test() { + Foo.X = 1 +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.results.txt b/idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.results.txt new file mode 100644 index 00000000000..6a8a6b5d2a1 --- /dev/null +++ b/idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.results.txt @@ -0,0 +1 @@ +Value write (10: 9) Foo.X = 1 \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.0.kt b/idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.0.kt new file mode 100644 index 00000000000..e2c89664759 --- /dev/null +++ b/idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.0.kt @@ -0,0 +1,11 @@ +// PSI_ELEMENT: com.intellij.psi.PsiMethod +// OPTIONS: usages +// FIND_BY_REF +// FIND_BY_NAVIGATION_ELEMENT +package usages + +import library.Foo + +fun test() { + Foo.baz(1) +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.results.txt b/idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.results.txt new file mode 100644 index 00000000000..7ed17660478 --- /dev/null +++ b/idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.results.txt @@ -0,0 +1 @@ +Function call (10: 9) Foo.baz(1) \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractJetFindUsagesTest.java b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractJetFindUsagesTest.java index 2cd81ad0afa..acf605e2d81 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractJetFindUsagesTest.java +++ b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractJetFindUsagesTest.java @@ -330,10 +330,22 @@ public abstract class AbstractJetFindUsagesTest extends JetLightCodeInsightFixtu ? TargetElementUtilBase.findTargetElement(myFixture.getEditor(), TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.NEW_AS_CONSTRUCTOR) : myFixture.getElementAtCaret(); - if (InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_MIRROR_ELEMENT")) { + boolean findByMirrorElement = InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_MIRROR_ELEMENT"); + boolean findByNavigationElement = InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_NAVIGATION_ELEMENT"); + if (findByMirrorElement && findByNavigationElement) { + fail("Incompatible directives"); + } + + if (findByMirrorElement) { assert originalElement instanceof PsiCompiledElement : "PsiCompiledElement is expected: " + originalElement; originalElement = ((PsiCompiledElement)originalElement).getMirror(); } + + if (findByNavigationElement) { + assert originalElement != null : "Original element is not found"; + originalElement = originalElement.getNavigationElement(); + } + T caretElement = PsiTreeUtil.getParentOfType(originalElement, caretElementClass, false); assertNotNull(String.format("Element with type '%s' wasn't found at caret position", caretElementClass), caretElement); diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesInLibrarySourceTest.kt b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesInLibrarySourceTest.kt new file mode 100644 index 00000000000..82f23feb6fb --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractKotlinFindUsagesInLibrarySourceTest.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2015 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.findUsages + +import com.intellij.psi.PsiElement +import com.intellij.testFramework.LightProjectDescriptor +import org.jetbrains.kotlin.idea.test.JdkAndMockLibraryProjectDescriptor +import org.jetbrains.kotlin.idea.test.PluginTestCaseBase + +public abstract class AbstractKotlinFindUsagesInLibrarySourceTest: AbstractJetFindUsagesTest() { + override fun getProjectDescriptor() = + JdkAndMockLibraryProjectDescriptor(PluginTestCaseBase.getTestDataPathBase() + "/findUsages/_library", true) +} diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/KotlinFindUsagesInLibrarySourceTestGenerated.java b/idea/tests/org/jetbrains/kotlin/findUsages/KotlinFindUsagesInLibrarySourceTestGenerated.java new file mode 100644 index 00000000000..ff14c613d34 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/findUsages/KotlinFindUsagesInLibrarySourceTestGenerated.java @@ -0,0 +1,73 @@ +/* + * Copyright 2010-2015 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.findUsages; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.JetTestUtils; +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/testData/findUsages/librarySources") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class KotlinFindUsagesInLibrarySourceTestGenerated extends AbstractKotlinFindUsagesInLibrarySourceTest { + public void testAllFilesPresentInLibrarySources() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/librarySources"), Pattern.compile("^(.+)\\.0\\.kt$"), true); + } + + @TestMetadata("LibraryClassUsages.0.kt") + public void testLibraryClassUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryClassUsages.0.kt"); + doTest(fileName); + } + + @TestMetadata("LibraryConstructorUsages.0.kt") + public void testLibraryConstructorUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryConstructorUsages.0.kt"); + doTest(fileName); + } + + @TestMetadata("LibraryFieldUsages.0.kt") + public void testLibraryFieldUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryFieldUsages.0.kt"); + doTest(fileName); + } + + @TestMetadata("LibraryMethodUsages.0.kt") + public void testLibraryMethodUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryMethodUsages.0.kt"); + doTest(fileName); + } + + @TestMetadata("LibraryStaticFieldUsages.0.kt") + public void testLibraryStaticFieldUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.0.kt"); + doTest(fileName); + } + + @TestMetadata("LibraryStaticMethodUsages.0.kt") + public void testLibraryStaticMethodUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.0.kt"); + doTest(fileName); + } +}