[java-refactoring] InlineToAnonymousClass: better support of arrays

GitOrigin-RevId: ddb42b302f70a8b44aca06fc9c643f009ea1c3da
This commit is contained in:
Tagir Valeev
2023-03-02 14:22:33 +00:00
committed by intellij-monorepo-bot
parent 2c0d7c5469
commit ae09e7920c
4 changed files with 21 additions and 2 deletions
@@ -322,7 +322,7 @@ public class InlineToAnonymousClassHandler extends JavaInlineActionHandler {
if (parentElement instanceof PsiThisExpression) {
return JavaBundle.message("class.cannot.be.inlined.because.it.is.used.as.a.this.qualifier");
}
if (parentElement instanceof PsiNewExpression newExpression) {
if (parentElement instanceof PsiNewExpression newExpression && !newExpression.isArrayCreation()) {
final PsiMethod[] constructors = aClass.getConstructors();
if (constructors.length == 0) {
PsiExpressionList newArgumentList = newExpression.getArgumentList();
@@ -0,0 +1,9 @@
class A {
void test() {
Inner[] data = new Inner[]{new Inner(5)};
}
static class Inner<caret> {
Inner(int x) {}
}
}
@@ -0,0 +1,6 @@
class A {
void test() {
Object[] data = new Object[]{new Object()};
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.refactoring.inline;
import com.intellij.JavaTestUtil;
@@ -170,6 +170,10 @@ public class InlineToAnonymousClassTest extends LightRefactoringTestCase {
doTest(false, false);
}
public void testArrayInitializer2() {
doTest(false, false);
}
public void testVarargs() {
doTest(false, false);
}