mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
Java: make "change new operator type" fix available in more cases
GitOrigin-RevId: f9bbcf2e699c1597484f1e9170855a19e6e5475b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5258e278e7
commit
33a9df4fea
@@ -33,7 +33,7 @@ public final class ChangeNewOperatorTypeFix implements IntentionAction {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return QuickFixBundle.message("change.new.operator.type.text", new PsiExpressionTrimRenderer.RenderFunction().fun(myExpression),
|
||||
return QuickFixBundle.message("change.new.operator.type.text", PsiExpressionTrimRenderer.render(myExpression),
|
||||
myType.getPresentableText(), myType instanceof PsiArrayType ? "" : "()");
|
||||
}
|
||||
|
||||
@@ -48,9 +48,7 @@ public final class ChangeNewOperatorTypeFix implements IntentionAction {
|
||||
return myType.isValid()
|
||||
&& myExpression.isValid()
|
||||
&& BaseIntentionAction.canModify(myExpression)
|
||||
&& !TypeConversionUtil.isPrimitiveAndNotNull(myType)
|
||||
&& (myType instanceof PsiArrayType || myExpression.getArgumentList() != null)
|
||||
;
|
||||
&& !TypeConversionUtil.isPrimitiveAndNotNull(myType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,10 +92,11 @@ public final class ChangeNewOperatorTypeFix implements IntentionAction {
|
||||
final PsiAnonymousClass anonymousClass = originalExpression.getAnonymousClass();
|
||||
newExpression = (PsiNewExpression)factory.createExpressionFromText("new " + toType.getCanonicalText() + "()" + (anonymousClass != null ? "{}" : ""), originalExpression);
|
||||
PsiExpressionList argumentList = originalExpression.getArgumentList();
|
||||
if (argumentList == null) return;
|
||||
final PsiExpressionList newArgumentList = newExpression.getArgumentList();
|
||||
assert newArgumentList != null;
|
||||
newArgumentList.replace(commentTracker.markUnchanged(argumentList));
|
||||
if (argumentList != null) {
|
||||
final PsiExpressionList newArgumentList = newExpression.getArgumentList();
|
||||
assert newArgumentList != null;
|
||||
newArgumentList.replace(commentTracker.markUnchanged(argumentList));
|
||||
}
|
||||
|
||||
if (anonymousClass != null) {
|
||||
PsiAnonymousClass newAnonymousClass = newExpression.getAnonymousClass();
|
||||
@@ -161,11 +160,10 @@ public final class ChangeNewOperatorTypeFix implements IntentionAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rType == null || newType.getCanonicalText().equals(rType.getCanonicalText())) return;
|
||||
final PsiClass aClass = PsiTypesUtil.getPsiClass(newType);
|
||||
if (aClass != null && (aClass.isEnum() || aClass.isAnnotationType())) return;
|
||||
PsiNewExpression newExpression = (PsiNewExpression)expression;
|
||||
final PsiJavaCodeReferenceElement reference = newExpression.getClassReference();
|
||||
if (reference != null && reference.getText().equals(newType.getCanonicalText())) return;
|
||||
highlightInfo.registerFix(new ChangeNewOperatorTypeFix(newType, newExpression), null, null, null, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Change 'new Integer[10]' to 'new Integer()'" "true"
|
||||
|
||||
class X {
|
||||
|
||||
Integer x() {
|
||||
return new Integer();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Change 'new Integer[] {1}' to 'new Integer()'" "true"
|
||||
|
||||
class X {
|
||||
|
||||
Integer x() {
|
||||
return new Integer();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Change 'new Integer[10]' to 'new Integer()'" "true"
|
||||
|
||||
class X {
|
||||
|
||||
Integer x() {
|
||||
return <caret>new Integer[10];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Change 'new Integer[] {1}' to 'new Integer()'" "true"
|
||||
|
||||
class X {
|
||||
|
||||
Integer x() {
|
||||
return <caret>new Integer[] { 1 };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Change 'new C()' to 'new C()'" "false"
|
||||
|
||||
class X {
|
||||
|
||||
C x() {
|
||||
class C {}
|
||||
return new<caret> C();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Change 'new C[10]' to 'new C[]'" "false"
|
||||
|
||||
class X {
|
||||
|
||||
C[] x() {
|
||||
class C {}
|
||||
return <caret>new C[10];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user