Java static imports are not classified as imports in Find Usages (IDEA-180332)

This commit is contained in:
Maxim.Mossienko
2017-10-13 15:32:41 +02:00
parent 2f1a9d3de9
commit 418d31e9e8
4 changed files with 19 additions and 0 deletions
@@ -240,6 +240,8 @@ public class JavaUsageTypeProvider implements UsageTypeProviderEx {
}
}
if (PsiTreeUtil.getParentOfType(element, PsiImportStaticStatement.class, false) != null) return UsageType.CLASS_IMPORT;
return null;
}
@@ -0,0 +1,3 @@
import static <caret>Foo.STATIC_FIELD;
public class StaticMethodCallInImport {
}
@@ -0,0 +1,4 @@
import static <caret>Foo.staticMethod;
class StaticMethodUsageInImport {
{ staticMethod(); }
}
@@ -43,6 +43,16 @@ public class JavaUsageTypeProviderTest extends LightCodeInsightFixtureTestCase {
assertUsageType(UsageType.CLASS_STATIC_MEMBER_ACCESS, myFixture.findClass("Foo"));
}
public void testStaticFieldUsageInImport() {
myFixture.configureByFiles("StaticFieldUsageInImport.java", "Foo.java");
assertUsageType(UsageType.CLASS_IMPORT, myFixture.findClass("Foo"));
}
public void testStaticMethodUsageInImport() {
myFixture.configureByFiles("StaticMethodUsageInImport.java", "Foo.java");
assertUsageType(UsageType.CLASS_IMPORT, myFixture.findClass("Foo"));
}
private void assertUsageType(UsageType expected, PsiClass target) {
UsageTarget[] targets = {new PsiElement2UsageTargetAdapter(target)};
PsiElement element = myFixture.getReferenceAtCaretPositionWithAssertion().getElement();