mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-70469 "Highlight Usages in File" doesn't work too nicely with static imports
This commit is contained in:
+11
-3
@@ -252,9 +252,17 @@ public class PsiImportStaticReferenceElementImpl extends CompositePsiElement imp
|
||||
@Override
|
||||
public boolean isReferenceTo(PsiElement element) {
|
||||
final String name = getReferenceName();
|
||||
return name != null &&
|
||||
element instanceof PsiNamedElement &&
|
||||
name.equals(((PsiNamedElement)element).getName()) && element.getManager().areElementsEquivalent(resolve(), element);
|
||||
if (name == null || !(element instanceof PsiNamedElement) || !name.equals(((PsiNamedElement)element).getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (JavaResolveResult result : multiResolve(false)) {
|
||||
if (getManager().areElementsEquivalent(result.getElement(), element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+38
@@ -147,6 +147,44 @@ public class HighlightUsagesHandlerTest extends LightCodeInsightFixtureTestCase
|
||||
myFixture.configureFromExistingVirtualFile(file)
|
||||
}
|
||||
|
||||
public void "test statically imported overloads from usage"() {
|
||||
myFixture.addClass("""
|
||||
class Foo {
|
||||
static void foo(int a) {}
|
||||
static void foo(int a, int b) {}
|
||||
}""")
|
||||
myFixture.configureByText 'Bar.java', '''
|
||||
import static Foo.foo;
|
||||
|
||||
class Bar {
|
||||
{
|
||||
<caret>foo(1);
|
||||
}
|
||||
}
|
||||
'''
|
||||
ctrlShiftF7()
|
||||
assertRangeText 'foo', 'foo'
|
||||
}
|
||||
|
||||
public void "test statically imported overloads from import"() {
|
||||
myFixture.addClass("""
|
||||
class Foo {
|
||||
static void foo(int a) {}
|
||||
static void foo(int a, int b) {}
|
||||
}""")
|
||||
myFixture.configureByText 'Bar.java', '''
|
||||
import static Foo.fo<caret>o;
|
||||
|
||||
class Bar {
|
||||
{
|
||||
foo(1);
|
||||
}
|
||||
}
|
||||
'''
|
||||
ctrlShiftF7()
|
||||
assertRangeText 'foo', 'foo', 'foo' //import highlighted twice: for each overloaded usage target
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return JavaTestUtil.relativeJavaTestDataPath
|
||||
|
||||
Reference in New Issue
Block a user