mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java: preserve comments on "Replace constructor with factory method"
GitOrigin-RevId: b2a8ab6923c29f5f35e50acdf30aa1acc897c844
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b329c2edec
commit
a0aaa369c9
+6
-3
@@ -21,6 +21,7 @@ import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import com.siyeh.ig.psiutils.MethodUtils;
|
||||
import one.util.streamex.StreamEx;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -115,9 +116,11 @@ public final class ReplaceConstructorWithFactoryAction implements ModCommandActi
|
||||
|
||||
for (PsiNewExpression newExpression : writableUsages) {
|
||||
var factoryCall = (PsiMethodCallExpression)factory.createExpressionFromText(factoryName + "()", newExpression);
|
||||
factoryCall.getArgumentList().replace(Objects.requireNonNull(newExpression.getArgumentList()));
|
||||
CommentTracker ct = new CommentTracker();
|
||||
|
||||
factoryCall.getArgumentList().replace(Objects.requireNonNull(ct.markUnchanged(newExpression.getArgumentList())));
|
||||
|
||||
PsiExpression newQualifier = newExpression.getQualifier();
|
||||
PsiExpression newQualifier = ct.markUnchanged(newExpression.getQualifier());
|
||||
|
||||
PsiReferenceExpression factoryCallRef = factoryCall.getMethodExpression();
|
||||
PsiElement resolvedFactoryMethod = factoryCallRef.resolve();
|
||||
@@ -127,7 +130,7 @@ public final class ReplaceConstructorWithFactoryAction implements ModCommandActi
|
||||
Objects.requireNonNull(factoryCallRef.getQualifierExpression()).replace(qualifier);
|
||||
}
|
||||
|
||||
newExpression.replace(factoryCall);
|
||||
ct.replaceAndRestoreComments(newExpression, factoryCall);
|
||||
}
|
||||
updater.rename(factoryMethod, names);
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
class Used {
|
||||
Inner createInner() {
|
||||
return new Inner();
|
||||
}
|
||||
|
||||
class Inner {
|
||||
private Inner() {
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
/*2*/
|
||||
/*3*/
|
||||
/*4*/
|
||||
/*5*/
|
||||
new /*1*/Used().createInner(/*6*/)/*7*/;
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class Used {
|
||||
class Inner<caret> {}
|
||||
public static void main(String[] args) {
|
||||
new /*1*/Used()/*2*/./*3*/new /*4*/Inner/*5*/(/*6*/)/*7*/;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 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;
|
||||
@@ -59,6 +59,7 @@ public class ReplaceConstructorWithFactoryTest extends LightRefactoringTestCase
|
||||
|
||||
public void testDefaultConstructor() { runTest("03", null); }
|
||||
public void testDefaultConstructorWithTypeParams() { runTest("TypeParams", null); }
|
||||
public void testPreserveComments() { runTest(getTestName(false), null); }
|
||||
|
||||
public void testInnerClass() { runTest("04", null); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user