mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-refactoring] Inline Parameter: do not erroneously report top-level non-static class references
Fixes IDEA-356746 Confusing warning when I inline array method parameter GitOrigin-RevId: 1964db1b4a09ec7eb1bcbbcd05fcb445862f06b4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4843e1d6e4
commit
9d989b2b7f
+5
-4
@@ -257,9 +257,9 @@ public class InlineParameterExpressionProcessor extends BaseRefactoringProcessor
|
||||
PsiElement anchor = findAnchorForLocalVariableDeclaration(body);
|
||||
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(myMethod.getProject());
|
||||
PsiExpression refExpression = factory.createExpressionFromText(myParameter.getName(), anchor);
|
||||
PsiDeclarationStatement localDeclaration =
|
||||
PsiDeclarationStatement localDeclaration =
|
||||
factory.createVariableDeclarationStatement(myParameter.getName(), myParameter.getType(), refExpression);
|
||||
|
||||
|
||||
localDeclaration = (PsiDeclarationStatement)body.addAfter(localDeclaration, anchor);
|
||||
final PsiLocalVariable declaredVar = (PsiLocalVariable)localDeclaration.getDeclaredElements()[0];
|
||||
PsiUtil.setModifierProperty(declaredVar, PsiModifier.FINAL, myParameter.hasModifierProperty(PsiModifier.FINAL));
|
||||
@@ -347,7 +347,7 @@ public class InlineParameterExpressionProcessor extends BaseRefactoringProcessor
|
||||
} else if (!PsiUtil.isAccessible((PsiMember)element, myMethod, null)) {
|
||||
myConflicts.putValue(expression, JavaRefactoringBundle.message("inline.parameter.depends.on.unavailable.value"));
|
||||
}
|
||||
} else if (element instanceof PsiParameter &&
|
||||
} else if (element instanceof PsiParameter &&
|
||||
PsiTreeUtil.isAncestor(((PsiParameter)element).getDeclarationScope(), myInitializer, true)) {
|
||||
boolean bound = false;
|
||||
for (PsiParameter parameter : myMethod.getParameterList().getParameters()) {
|
||||
@@ -387,7 +387,8 @@ public class InlineParameterExpressionProcessor extends BaseRefactoringProcessor
|
||||
super.visitReferenceElement(reference);
|
||||
if (myMethod.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
final PsiElement resolved = reference.resolve();
|
||||
if (resolved instanceof PsiClass && !((PsiClass)resolved).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
if (resolved instanceof PsiClass cls &&
|
||||
(PsiUtil.isInnerClass(cls) || PsiUtil.isLocalClass(cls))) {
|
||||
myConflicts.putValue(reference, JavaRefactoringBundle.message("inline.parameter.depends.on.non.static.class"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class Test {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(use(new Object[]{"1", "2", "3"}));
|
||||
}
|
||||
|
||||
public static String use(Object[] arr<caret>) {
|
||||
return Arrays.toString(arr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class Test {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(use());
|
||||
}
|
||||
|
||||
public static String use() {
|
||||
return Arrays.toString(new Object[]{"1", "2", "3"});
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -188,7 +188,7 @@ public class InlineParameterTest extends LightRefactoringTestCase {
|
||||
public void testRefNewTopLevel() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
|
||||
public void testConflictingFieldName() {
|
||||
doTest(true);
|
||||
}
|
||||
@@ -326,6 +326,10 @@ public class InlineParameterTest extends LightRefactoringTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testArrayInitializer() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
private void doTest(final boolean createLocal) {
|
||||
getProject().putUserData(InlineParameterExpressionProcessor.CREATE_LOCAL_FOR_TESTS, createLocal);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user