mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
unused imports: don't warn if resolve produces no results but multi resolve does (IDEA-206347)
This commit is contained in:
+9
@@ -164,6 +164,15 @@ class RefCountHolder {
|
||||
if (resolveScope instanceof PsiImportStatementBase) {
|
||||
registerImportStatement(ref, (PsiImportStatementBase)resolveScope);
|
||||
}
|
||||
else if (refElement == null && ref instanceof PsiJavaReference) {
|
||||
for (JavaResolveResult result : ((PsiJavaReference)ref).multiResolve(true)) {
|
||||
resolveScope = result.getCurrentFileResolveScope();
|
||||
if (resolveScope instanceof PsiImportStatementBase) {
|
||||
registerImportStatement(ref, (PsiImportStatementBase)resolveScope);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void registerImportStatement(@NotNull PsiReference ref, @NotNull PsiImportStatementBase importStatement) {
|
||||
|
||||
+7
-1
@@ -71,7 +71,13 @@ class ImportsAreUsedVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
}
|
||||
// during typing there can be incomplete code
|
||||
final JavaResolveResult resolveResult = reference.advancedResolve(true);
|
||||
final PsiElement element = resolveResult.getElement();
|
||||
PsiElement element = resolveResult.getElement();
|
||||
if (element == null) {
|
||||
JavaResolveResult[] results = reference.multiResolve(false);
|
||||
if (results.length > 0) {
|
||||
element = results[0].getElement();
|
||||
}
|
||||
}
|
||||
if (!(element instanceof PsiMember)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import static a.A.foo;
|
||||
class Test {
|
||||
{
|
||||
foo(<error descr="Cannot resolve method 'unresolvedMethodCall()'">unresolvedMethodCall</error>());
|
||||
}
|
||||
}
|
||||
@@ -92,6 +92,14 @@ public class UnusedImportsTest extends LightCodeInsightFixtureTestCase {
|
||||
myFixture.checkHighlighting(true,false, false);
|
||||
}
|
||||
|
||||
public void testUnresolvedReferencesInsideAmbiguousCallToImportedMethod() {
|
||||
myFixture.addClass("package a; public class A {\n" +
|
||||
" public static void foo(Object o) {}\n" +
|
||||
" public static void foo(String s) {}\n" +
|
||||
"}");
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
myFixture.checkHighlighting(true, false, false);
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
<problems/>
|
||||
+15
@@ -83,6 +83,21 @@ public class UnusedImportGlobalInspectionTest extends LightCodeInsightFixtureTes
|
||||
"}}");
|
||||
}
|
||||
|
||||
|
||||
public void testUnresolvedReferencesInsideAmbiguousCallToImportedMethod() {
|
||||
myFixture.addClass("package a; public class A {\n" +
|
||||
" public static void foo(Object o) {}\n" +
|
||||
" public static void foo(String s) {}\n" +
|
||||
"}");
|
||||
doTest("import static a.A.foo;\n" +
|
||||
"class Test {\n" +
|
||||
" {\n" +
|
||||
" foo(<error descr=\"Cannot resolve method 'unresolvedMethodCall()'\">unresolvedMethodCall</error>());\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
}
|
||||
|
||||
|
||||
public void testNoHighlightingInInvalidCode() {
|
||||
myFixture.configureByText("a.java",
|
||||
"import<EOLError></EOLError>\n" +
|
||||
|
||||
Reference in New Issue
Block a user