mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: fix static import checking in "Unused import" inspection
This commit is contained in:
+9
-2
@@ -103,8 +103,15 @@ class ImportsAreUsedVisitor extends JavaRecursiveElementVisitor {
|
||||
final boolean hasOnDemandImportConflict = ImportUtils.hasOnDemandImportConflict(qualifiedName, myFile);
|
||||
for (PsiImportStatementBase importStatement : importStatements) {
|
||||
if (!importStatement.isOnDemand()) {
|
||||
if (member.equals(importStatement.resolve())) {
|
||||
return importStatement;
|
||||
final PsiJavaCodeReferenceElement reference = importStatement.getImportReference();
|
||||
if (reference == null) {
|
||||
continue;
|
||||
}
|
||||
final JavaResolveResult[] targets = reference.multiResolve(false);
|
||||
for (JavaResolveResult target : targets) {
|
||||
if (member.equals(target.getElement())) {
|
||||
return importStatement;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
+18
@@ -54,6 +54,15 @@ public class UnusedImportInspectionTest extends LightInspectionTestCase {
|
||||
"}");
|
||||
}
|
||||
|
||||
public void testExactStaticImport() {
|
||||
doTest("package a;\n" +
|
||||
"import static java.lang.Math.abs;\n" +
|
||||
"/*Unused import 'import static java.lang.Math.max;'*/import static java.lang.Math.max;/**/\n" +
|
||||
"class Main {{\n" +
|
||||
" abs(1);\n" +
|
||||
"}}");
|
||||
}
|
||||
|
||||
public void testStaticImportOnDemandConflict1() {
|
||||
addEnvironmentClass("package a;" +
|
||||
"public class Parent {" +
|
||||
@@ -183,6 +192,15 @@ public class UnusedImportInspectionTest extends LightInspectionTestCase {
|
||||
"}}");
|
||||
}
|
||||
|
||||
public void testNoConflictInSamePackage() {
|
||||
doTest("package a;" +
|
||||
"/*Unused import 'import java.util.List;'*/import java.util.List;/**/" +
|
||||
"import java.util.*;" +
|
||||
"class X {{" +
|
||||
" List list = new ArrayList();" +
|
||||
"}}");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocalInspectionTool getInspection() {
|
||||
return new UnusedImportInspection();
|
||||
|
||||
Reference in New Issue
Block a user