mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 22:09:38 +07:00
IDEA-129604 (Structural Search: use static import if possible breaks code)
This commit is contained in:
@@ -477,7 +477,17 @@ public class JavaReplaceHandler extends StructuralReplaceHandler {
|
||||
return;
|
||||
}
|
||||
super.visitReferenceExpression(expression);
|
||||
if (offset + expression.getTextLength() < finalStartOffset)
|
||||
if (offset + expression.getTextLength() < finalStartOffset) {
|
||||
return;
|
||||
}
|
||||
final PsiElement target = expression.resolve();
|
||||
if (!(target instanceof PsiMember)) {
|
||||
return;
|
||||
}
|
||||
final PsiMember member = (PsiMember)target;
|
||||
if (!member.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
return;
|
||||
}
|
||||
if (expression.getQualifierExpression() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1810,13 +1810,17 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase {
|
||||
}
|
||||
|
||||
public void testUseStaticImport() {
|
||||
final String in = "class X {{ Math.abs(-1); }}";
|
||||
String in = "class X {{ Math.abs(-1); }}";
|
||||
final String what = "Math.abs('a)";
|
||||
final String by = "Math.abs($a$)";
|
||||
options.setToUseStaticImport(true);
|
||||
|
||||
final String expected = "import static java.lang.Math.abs;class X {{ abs(-1); }}";
|
||||
String expected = "import static java.lang.Math.abs;class X {{ abs(-1); }}";
|
||||
assertEquals("Replacing with static import", expected, replacer.testReplace(in, what, by, options, true));
|
||||
|
||||
in = "class X { void m(java.util.Random r) { Math.abs(r.nextInt()); }}";
|
||||
expected = "import static java.lang.Math.abs;class X { void m(java.util.Random r) { abs(r.nextInt()); }}";
|
||||
assertEquals("don't add broken static imports", expected, replacer.testReplace(in, what, by, options, true));
|
||||
}
|
||||
|
||||
public void testUseStaticStarImport() {
|
||||
|
||||
Reference in New Issue
Block a user