introduce constant: resolve name conflict caused by static import (IDEA-235318)

GitOrigin-RevId: 3da9946d105c483e95b26cf46a6a23bfce97322e
This commit is contained in:
Anna Kozlova
2020-03-18 06:31:42 +00:00
committed by intellij-monorepo-bot
parent 458e66b69f
commit 56f5c96346
4 changed files with 28 additions and 1 deletions
@@ -296,9 +296,10 @@ class IntroduceConstantDialog extends DialogWrapper {
codeStyleManager.suggestVariableName(VariableKind.STATIC_FINAL_FIELD, propertyName, psiExpression, type);
if (psiExpression != null) {
String[] names = nameInfo.names;
PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(psiExpression.getProject()).getResolveHelper();
for (int i = 0, namesLength = names.length; i < namesLength; i++) {
String name = names[i];
if (parentClass.findFieldByName(name, false) != null) {
if (resolveHelper.resolveAccessibleReferencedVariable(name, parentClass) != null) {
names[i] = codeStyleManager.suggestUniqueVariableName(name, psiExpression, true);
}
}
@@ -0,0 +1,10 @@
package p;
import static p.Foo.FOO;
class Foo {
public static final String FOO = "foo";
}
class Test {
public void method() {
String f<caret>oo = new String(FOO);
}
}
@@ -0,0 +1,12 @@
package p;
import static p.Foo.FOO;
class Foo {
public static final String FOO = "foo";
}
class Test {
public static final String FOO1 = new String(FOO);
public void method() {
}
}
@@ -70,6 +70,10 @@ public class InplaceIntroduceConstantTest extends AbstractJavaInplaceIntroduceTe
doTest(null);
}
public void testConflictingConstantNameStaticallyImported() {
doTest(null);
}
public void testNoConflictingConstantName() {
doTest(null);
}