Find Usages: Fix reference matching for declarations located in libraries
#KT-5762 Fixed
This commit is contained in:
@@ -40,7 +40,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
|||||||
public val PsiReference.unwrappedTargets: Set<PsiElement>
|
public val PsiReference.unwrappedTargets: Set<PsiElement>
|
||||||
get() {
|
get() {
|
||||||
fun PsiElement.adjust(): PsiElement? {
|
fun PsiElement.adjust(): PsiElement? {
|
||||||
val target = unwrapped
|
val target = unwrapped?.getOriginalElement()
|
||||||
return when {
|
return when {
|
||||||
target is JetPropertyAccessor -> target.getNonStrictParentOfType<JetProperty>()
|
target is JetPropertyAccessor -> target.getNonStrictParentOfType<JetProperty>()
|
||||||
target is JetObjectDeclaration && target.isClassObject() -> target.getNonStrictParentOfType<JetClass>()
|
target is JetObjectDeclaration && target.isClassObject() -> target.getNonStrictParentOfType<JetClass>()
|
||||||
@@ -55,7 +55,7 @@ public val PsiReference.unwrappedTargets: Set<PsiElement>
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fun PsiReference.matchesTarget(target: PsiElement): Boolean {
|
public fun PsiReference.matchesTarget(target: PsiElement): Boolean {
|
||||||
val unwrapped = target.unwrapped
|
val unwrapped = target.unwrapped?.getOriginalElement()
|
||||||
return when {
|
return when {
|
||||||
unwrapped in unwrappedTargets ->
|
unwrapped in unwrappedTargets ->
|
||||||
true
|
true
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// PSI_ELEMENT: com.intellij.psi.PsiClass
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// FIND_BY_MIRROR_ELEMENT
|
||||||
|
fun test() {
|
||||||
|
<caret>System.exit(0)
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Nested class/object (6: 5) System.exit(0)
|
||||||
@@ -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().<caret>width = 1
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Value write (8: 17) Dimension().width = 1
|
||||||
@@ -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().<caret>setSize(1.0, 2.0)
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Function call (8: 17) Dimension().setSize(1.0, 2.0)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// PSI_ELEMENT: com.intellij.psi.PsiField
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// FIND_BY_MIRROR_ELEMENT
|
||||||
|
fun test() {
|
||||||
|
System.<caret>out.println()
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Receiver (6: 12) System.out.println()
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// PSI_ELEMENT: com.intellij.psi.PsiMethod
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// FIND_BY_MIRROR_ELEMENT
|
||||||
|
fun test() {
|
||||||
|
System.<caret>exit(0)
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Function call (6: 12) System.exit(0)
|
||||||
@@ -328,6 +328,10 @@ public abstract class AbstractJetFindUsagesTest extends JetLightCodeInsightFixtu
|
|||||||
InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_REF")
|
InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_REF")
|
||||||
? TargetElementUtilBase.findTargetElement(myFixture.getEditor(), TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED)
|
? TargetElementUtilBase.findTargetElement(myFixture.getEditor(), TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED)
|
||||||
: myFixture.getElementAtCaret();
|
: 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);
|
T caretElement = PsiTreeUtil.getParentOfType(originalElement, caretElementClass, false);
|
||||||
assertNotNull(String.format("Element with type '%s' wasn't found at caret position", caretElementClass), caretElement);
|
assertNotNull(String.format("Element with type '%s' wasn't found at caret position", caretElementClass), caretElement);
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import java.util.regex.Pattern;
|
|||||||
public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
|
public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
|
||||||
@TestMetadata("idea/testData/findUsages/kotlin")
|
@TestMetadata("idea/testData/findUsages/kotlin")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@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)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public static class Kotlin extends AbstractJetFindUsagesTest {
|
public static class Kotlin extends AbstractJetFindUsagesTest {
|
||||||
public void testAllFilesPresentInKotlin() throws Exception {
|
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")
|
@TestMetadata("idea/testData/findUsages/kotlin/unresolvedAnnotation")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user