[java-intentions] Ignore array creations

#IDEA-377378 Fixed

GitOrigin-RevId: 5341d608d7deef08a4bfe7bf699091f960790493
This commit is contained in:
Louis Vignier
2025-08-20 22:04:25 +00:00
committed by intellij-monorepo-bot
parent 985dcb373a
commit 2c6c9d7c1d
4 changed files with 36 additions and 1 deletions
@@ -119,6 +119,10 @@ public final class ReplaceConstructorWithFactoryAction implements ModCommandActi
PsiUtil.setModifierProperty(wrConstructor, getMinimalAccessLevel(constructorOrClass, usages.otherUsages), true);
for (PsiNewExpression newExpression : writableUsages) {
if (newExpression.isArrayCreation()) {
continue;
}
var factoryCall = (PsiMethodCallExpression)factory.createExpressionFromText(factoryName + "()", newExpression);
CommentTracker ct = new CommentTracker();
@@ -0,0 +1,17 @@
class List<T> {
T t;
private List() {
}
static <T> List<T> createList() {
return new List<T>();
}
}
class Test {
void foo (){
List x = List.createList();
List[] y = new List [10];
}
}
@@ -0,0 +1,10 @@
class List<T> {
T t;
}
class Test {
void foo (){
List x = new List<T>();
List[] y = new List [10];
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.refactoring;
import com.intellij.JavaTestUtil;
@@ -131,6 +131,10 @@ public class ReplaceConstructorWithFactoryTest extends LightRefactoringTestCase
assertNotAvailable("RedCodeFromIDEA376351");
}
public void testArrayCreation() {
runTest("ArrayCreation", null);
}
private void assertNotAvailable(String name) {
configureByFile("/refactoring/replaceConstructorWithFactory/before" + name + ".java");
ReplaceConstructorWithFactoryAction action = new ReplaceConstructorWithFactoryAction();