unnecessarily qualified statically imported elements: do not ignore chained calls (IDEA-124806)

This commit is contained in:
Anna Kozlova
2014-05-06 16:14:29 +04:00
parent 6f548f2a25
commit f0ac2bd244
6 changed files with 27 additions and 2 deletions
@@ -94,7 +94,7 @@ public class UnnecessarilyQualifiedStaticallyImportedElementInspection extends B
if (!(qualifier instanceof PsiJavaCodeReferenceElement)) {
return;
}
if (PsiTreeUtil.getParentOfType(reference, PsiReferenceExpression.class, PsiImportStatementBase.class) != null) {
if (PsiTreeUtil.getParentOfType(reference, PsiImportStatementBase.class) != null) {
return;
}
if (UnnecessarilyQualifiedStaticUsageInspection.isGenericReference(reference, (PsiJavaCodeReferenceElement)qualifier)) return;
@@ -0,0 +1,8 @@
<problems>
<problem>
<file>Test.java</file>
<line>7</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unnecessarily qualified statically imported element</problem_class>
<description>Statically imported element 'foo' is unnecessarily qualified with &lt;code&gt;A&lt;/code&gt; #loc</description>
</problem>
</problems>
@@ -0,0 +1,13 @@
package p;
import static p.A.foo;
class StaticImport {
void example() {
A.foo().toString();
}
}
class A {
static Object foo() {return null;}
}
@@ -21,7 +21,7 @@ public class UnnecessarilyQualifiedStaticallyImportedElementInspectionTest
extends IGInspectionTestCase {
public void test() throws Exception {
doTest("com/siyeh/igtest/style/unnecessarily_qualified_statically_imported_element",
doTest("com/siyeh/igtest/style/unnecessarily_qualified_statically_imported_element/simple",
new UnnecessarilyQualifiedStaticallyImportedElementInspection());
}
@@ -33,6 +33,10 @@ public class UnnecessarilyQualifiedStaticallyImportedElementInspectionTest
doTest(getTestName(true));
}
public void testChainedMethodCall() throws Exception {
doTest(getTestName(true));
}
private void doTest(String testName) throws Exception {
doTest("com/siyeh/igtest/style/unnecessarily_qualified_statically_imported_element/" + testName,
new UnnecessarilyQualifiedStaticallyImportedElementInspection());