add single static import: ensure not available when conflict(IDEA-174983)

when methods (> 1) with same name exist in the containing class
This commit is contained in:
Anna Kozlova
2017-06-26 12:37:13 +03:00
parent 7e3e7e798f
commit ed4a26a905
3 changed files with 19 additions and 0 deletions

View File

@@ -104,6 +104,9 @@ public class AddSingleMemberStaticImportAction extends BaseElementAtCaretIntenti
else return null;
}
}
else if (method == null && call.getMethodExpression().multiResolve(false).length > 0) {
return null;
}
}
else {
final PsiJavaCodeReferenceElement copy = (PsiJavaCodeReferenceElement)refExpr.copy();

View File

@@ -0,0 +1,9 @@
import foo.*;
class MyTest {
{
Assert.assert<caret>True(false);
}
static void assertTrue() {}
static void assertTrue(String message, boolean flag) {}
}

View File

@@ -131,6 +131,13 @@ public class AddSingleStaticImportActionTest extends JavaCodeInsightFixtureTestC
}
}
public void testConflictingNamesInScope() throws Exception {
myFixture.addClass("package foo; public class Assert {public static void assertTrue(boolean b) {}}");
myFixture.configureByFile(getTestName(false) + ".java");
IntentionAction intention = myFixture.getAvailableIntention("Add static import for 'foo.Assert.assertTrue'");
assertNull(intention);
}
public void testProhibitWhenMethodWithIdenticalSignatureAlreadyImportedFromAnotherClass() throws Exception {
myFixture.addClass("package foo; class Foo {public static void foo(int i){}}");
myFixture.addClass("package foo; class Bar {public static void foo(int i){}}");