mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
Java: avoid incorrect warnings when Inlining Parameter (IDEA-345199)
GitOrigin-RevId: 489422cffc7aecacd07468009da620a5732ce5ba
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b9b2735045
commit
d9bb6a9b0b
+12
-17
@@ -332,21 +332,23 @@ public class InlineParameterExpressionProcessor extends BaseRefactoringProcessor
|
||||
public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) {
|
||||
super.visitReferenceExpression(expression);
|
||||
final PsiElement element = expression.resolve();
|
||||
if (element instanceof PsiMember member && !member.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
if (element instanceof PsiMember member && !member.hasModifierProperty(PsiModifier.STATIC) && !(member instanceof PsiClass)) {
|
||||
if (myMethod.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
myConflicts.putValue(expression, JavaRefactoringBundle.message("inline.parameter.dependency.unavailable.in.parameter.method",
|
||||
RefactoringUIUtil.getDescription(element, false)));
|
||||
}
|
||||
}
|
||||
if (element instanceof PsiMethod || element instanceof PsiField) {
|
||||
else if (element instanceof PsiMethod || element instanceof PsiField) {
|
||||
if (!mySameClass && !((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
myConflicts.putValue(expression, JavaRefactoringBundle.message("inline.parameter.depends.on.non.static",
|
||||
RefactoringUIUtil.getDescription(element, true)));
|
||||
} else if (!PsiUtil.isAccessible((PsiMember)element, myMethod, null)) {
|
||||
}
|
||||
else if (!PsiUtil.isAccessible((PsiMember)element, myMethod, null)) {
|
||||
myConflicts.putValue(expression, JavaRefactoringBundle.message("inline.parameter.dependency.unavailable.in.parameter.method",
|
||||
RefactoringUIUtil.getDescription(element, true)));
|
||||
}
|
||||
} else if (element instanceof PsiParameter param && PsiTreeUtil.isAncestor(param.getDeclarationScope(), myInitializer, true)) {
|
||||
}
|
||||
else if (element instanceof PsiParameter param && PsiTreeUtil.isAncestor(param.getDeclarationScope(), myInitializer, true)) {
|
||||
boolean bound = false;
|
||||
for (PsiParameter parameter : myMethod.getParameterList().getParameters()) {
|
||||
if (parameter == myParameter) continue;
|
||||
@@ -381,24 +383,17 @@ public class InlineParameterExpressionProcessor extends BaseRefactoringProcessor
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitReferenceElement(@NotNull PsiJavaCodeReferenceElement reference) {
|
||||
super.visitReferenceElement(reference);
|
||||
if (myMethod.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
final PsiElement resolved = reference.resolve();
|
||||
if (resolved instanceof PsiClass cls && (PsiUtil.isInnerClass(cls) || PsiUtil.isLocalClass(cls))) {
|
||||
myConflicts.putValue(reference, JavaRefactoringBundle.message("inline.parameter.depends.on.non.static.class",
|
||||
RefactoringUIUtil.getDescription(resolved, true)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNewExpression(@NotNull PsiNewExpression expression) {
|
||||
super.visitNewExpression(expression);
|
||||
final PsiJavaCodeReferenceElement reference = expression.getClassOrAnonymousClassReference();
|
||||
if (reference != null && reference.resolve() instanceof PsiClass aClass) {
|
||||
if (!PsiUtil.isAccessible(aClass, myMethod, null)) {
|
||||
if (!expression.isArrayCreation() && myMethod.hasModifierProperty(PsiModifier.STATIC) &&
|
||||
(PsiUtil.isInnerClass(aClass) || PsiUtil.isLocalClass(aClass))) {
|
||||
myConflicts.putValue(reference, JavaRefactoringBundle.message("inline.parameter.depends.on.non.static.class",
|
||||
RefactoringUIUtil.getDescription(aClass, true)));
|
||||
}
|
||||
else if (!PsiUtil.isAccessible(aClass, myMethod, null)) {
|
||||
myConflicts.putValue(expression, JavaRefactoringBundle.message("inline.parameter.dependency.unavailable.in.parameter.method",
|
||||
RefactoringUIUtil.getDescription(aClass, true)));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
class MyUpdate {
|
||||
|
||||
public static MyUpdate createUpdate(Container <caret>extensionsContainer) {
|
||||
System.out.println("extensionsContainer = " + extensionsContainer);
|
||||
return new MyUpdate();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
MyUpdate.createUpdate(Container.empty());
|
||||
}
|
||||
}
|
||||
|
||||
class Container {
|
||||
public static Container empty() {
|
||||
return new Container();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
class MyUpdate {
|
||||
|
||||
public static MyUpdate createUpdate() {
|
||||
System.out.println("extensionsContainer = " + Container.empty());
|
||||
return new MyUpdate();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
MyUpdate.createUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
class Container {
|
||||
public static Container empty() {
|
||||
return new Container();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class ExpData {
|
||||
|
||||
private Object provideObject() {
|
||||
return new Object();
|
||||
}
|
||||
|
||||
public static void useStatic(Object p) {
|
||||
System.out.println(p);
|
||||
}
|
||||
|
||||
public void context() {
|
||||
inlineE(new DD[10]);
|
||||
}
|
||||
|
||||
public static void inlineE(Object <caret>subj) {
|
||||
useStatic(subj);
|
||||
}
|
||||
|
||||
class DD {}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
public class ExpData {
|
||||
|
||||
private Object provideObject() {
|
||||
return new Object();
|
||||
}
|
||||
|
||||
public static void useStatic(Object p) {
|
||||
System.out.println(p);
|
||||
}
|
||||
|
||||
public void context() {
|
||||
inlineE();
|
||||
}
|
||||
|
||||
public static void inlineE() {
|
||||
useStatic(new DD[10]);
|
||||
}
|
||||
|
||||
class DD {}
|
||||
}
|
||||
@@ -249,6 +249,14 @@ public class InlineParameterTest extends LightRefactoringTestCase {
|
||||
assertEquals("Parameter initializer depends on non-static class <b><code>ExpData.DD</code></b> which is not accessible inside the parameter's method", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testRefNonStaticClassArray() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
public void testNoWarning() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
public void testRefThisFromStatic() {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user