diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/references/referenceUtil.kt b/idea/idea-analysis/src/org/jetbrains/jet/plugin/references/referenceUtil.kt index 8d1a08ac59f..bdcb40c9f33 100644 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/references/referenceUtil.kt +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/references/referenceUtil.kt @@ -40,7 +40,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType public val PsiReference.unwrappedTargets: Set get() { fun PsiElement.adjust(): PsiElement? { - val target = unwrapped + val target = unwrapped?.getOriginalElement() return when { target is JetPropertyAccessor -> target.getNonStrictParentOfType() target is JetObjectDeclaration && target.isClassObject() -> target.getNonStrictParentOfType() @@ -55,7 +55,7 @@ public val PsiReference.unwrappedTargets: Set } public fun PsiReference.matchesTarget(target: PsiElement): Boolean { - val unwrapped = target.unwrapped + val unwrapped = target.unwrapped?.getOriginalElement() return when { unwrapped in unwrappedTargets -> true diff --git a/idea/testData/findUsages/kotlin/library/LibraryClassUsages.0.kt b/idea/testData/findUsages/kotlin/library/LibraryClassUsages.0.kt new file mode 100644 index 00000000000..70d2760a3d7 --- /dev/null +++ b/idea/testData/findUsages/kotlin/library/LibraryClassUsages.0.kt @@ -0,0 +1,7 @@ +// PSI_ELEMENT: com.intellij.psi.PsiClass +// OPTIONS: usages +// FIND_BY_REF +// FIND_BY_MIRROR_ELEMENT +fun test() { + System.exit(0) +} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryClassUsages.results.txt b/idea/testData/findUsages/kotlin/library/LibraryClassUsages.results.txt new file mode 100644 index 00000000000..a76bc46e444 --- /dev/null +++ b/idea/testData/findUsages/kotlin/library/LibraryClassUsages.results.txt @@ -0,0 +1 @@ +Nested class/object (6: 5) System.exit(0) \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryFieldUsages.0.kt b/idea/testData/findUsages/kotlin/library/LibraryFieldUsages.0.kt new file mode 100644 index 00000000000..d7ec5f2b2fe --- /dev/null +++ b/idea/testData/findUsages/kotlin/library/LibraryFieldUsages.0.kt @@ -0,0 +1,9 @@ +// PSI_ELEMENT: com.intellij.psi.PsiField +// OPTIONS: usages +// FIND_BY_REF +// FIND_BY_MIRROR_ELEMENT +import java.awt.Dimension + +fun test() { + Dimension().width = 1 +} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryFieldUsages.results.txt b/idea/testData/findUsages/kotlin/library/LibraryFieldUsages.results.txt new file mode 100644 index 00000000000..1f976341332 --- /dev/null +++ b/idea/testData/findUsages/kotlin/library/LibraryFieldUsages.results.txt @@ -0,0 +1 @@ +Value write (8: 17) Dimension().width = 1 \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryMethodUsages.0.kt b/idea/testData/findUsages/kotlin/library/LibraryMethodUsages.0.kt new file mode 100644 index 00000000000..4646d65eecc --- /dev/null +++ b/idea/testData/findUsages/kotlin/library/LibraryMethodUsages.0.kt @@ -0,0 +1,9 @@ +// PSI_ELEMENT: com.intellij.psi.PsiMethod +// OPTIONS: usages +// FIND_BY_REF +// FIND_BY_MIRROR_ELEMENT +import java.awt.Dimension + +fun test() { + Dimension().setSize(1.0, 2.0) +} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryMethodUsages.results.txt b/idea/testData/findUsages/kotlin/library/LibraryMethodUsages.results.txt new file mode 100644 index 00000000000..5d28a340adb --- /dev/null +++ b/idea/testData/findUsages/kotlin/library/LibraryMethodUsages.results.txt @@ -0,0 +1 @@ +Function call (8: 17) Dimension().setSize(1.0, 2.0) \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.0.kt b/idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.0.kt new file mode 100644 index 00000000000..64eb241ef44 --- /dev/null +++ b/idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.0.kt @@ -0,0 +1,7 @@ +// PSI_ELEMENT: com.intellij.psi.PsiField +// OPTIONS: usages +// FIND_BY_REF +// FIND_BY_MIRROR_ELEMENT +fun test() { + System.out.println() +} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.results.txt b/idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.results.txt new file mode 100644 index 00000000000..2003de82d8c --- /dev/null +++ b/idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.results.txt @@ -0,0 +1 @@ +Receiver (6: 12) System.out.println() \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.0.kt b/idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.0.kt new file mode 100644 index 00000000000..130444998c8 --- /dev/null +++ b/idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.0.kt @@ -0,0 +1,7 @@ +// PSI_ELEMENT: com.intellij.psi.PsiMethod +// OPTIONS: usages +// FIND_BY_REF +// FIND_BY_MIRROR_ELEMENT +fun test() { + System.exit(0) +} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.results.txt b/idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.results.txt new file mode 100644 index 00000000000..e6b937caf67 --- /dev/null +++ b/idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.results.txt @@ -0,0 +1 @@ +Function call (6: 12) System.exit(0) \ 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 a7271365a75..aeb8f02de84 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractJetFindUsagesTest.java +++ b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractJetFindUsagesTest.java @@ -328,6 +328,10 @@ public abstract class AbstractJetFindUsagesTest extends JetLightCodeInsightFixtu InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_REF") ? TargetElementUtilBase.findTargetElement(myFixture.getEditor(), TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED) : myFixture.getElementAtCaret(); + if (InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_MIRROR_ELEMENT")) { + assert originalElement instanceof PsiCompiledElement : "PsiCompiledElement is expected: " + originalElement; + originalElement = ((PsiCompiledElement)originalElement).getMirror(); + } 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/JetFindUsagesTestGenerated.java b/idea/tests/org/jetbrains/kotlin/findUsages/JetFindUsagesTestGenerated.java index 74d7780811e..4269db51398 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/JetFindUsagesTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/findUsages/JetFindUsagesTestGenerated.java @@ -33,7 +33,7 @@ import java.util.regex.Pattern; public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest { @TestMetadata("idea/testData/findUsages/kotlin") @TestDataPath("$PROJECT_ROOT") - @InnerTestClasses({Kotlin.Conventions.class, Kotlin.FindClassUsages.class, Kotlin.FindFunctionUsages.class, Kotlin.FindObjectUsages.class, Kotlin.FindPackageUsages.class, Kotlin.FindParameterUsages.class, Kotlin.FindPropertyUsages.class, Kotlin.FindTypeParameterUsages.class, Kotlin.FindWithFilteringImports.class, Kotlin.FindWithStructuralGrouping.class, Kotlin.UnresolvedAnnotation.class}) + @InnerTestClasses({Kotlin.Conventions.class, Kotlin.FindClassUsages.class, Kotlin.FindFunctionUsages.class, Kotlin.FindObjectUsages.class, Kotlin.FindPackageUsages.class, Kotlin.FindParameterUsages.class, Kotlin.FindPropertyUsages.class, Kotlin.FindTypeParameterUsages.class, Kotlin.FindWithFilteringImports.class, Kotlin.FindWithStructuralGrouping.class, Kotlin.Library.class, Kotlin.UnresolvedAnnotation.class}) @RunWith(JUnit3RunnerWithInners.class) public static class Kotlin extends AbstractJetFindUsagesTest { public void testAllFilesPresentInKotlin() throws Exception { @@ -844,6 +844,45 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest { } } + @TestMetadata("idea/testData/findUsages/kotlin/library") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Library extends AbstractJetFindUsagesTest { + public void testAllFilesPresentInLibrary() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/kotlin/library"), Pattern.compile("^(.+)\\.0\\.kt$"), true); + } + + @TestMetadata("LibraryClassUsages.0.kt") + public void testLibraryClassUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/library/LibraryClassUsages.0.kt"); + doTest(fileName); + } + + @TestMetadata("LibraryFieldUsages.0.kt") + public void testLibraryFieldUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/library/LibraryFieldUsages.0.kt"); + doTest(fileName); + } + + @TestMetadata("LibraryMethodUsages.0.kt") + public void testLibraryMethodUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/library/LibraryMethodUsages.0.kt"); + doTest(fileName); + } + + @TestMetadata("LibraryStaticFieldUsages.0.kt") + public void testLibraryStaticFieldUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.0.kt"); + doTest(fileName); + } + + @TestMetadata("LibraryStaticMethodUsages.0.kt") + public void testLibraryStaticMethodUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.0.kt"); + doTest(fileName); + } + } + @TestMetadata("idea/testData/findUsages/kotlin/unresolvedAnnotation") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)