mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
Java: "Open in editor" checkbox for Replace constructor with builder (IDEA-358746)
GitOrigin-RevId: 72f2bf32432a2b623ab562cefac5568904fb5cee
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4d537236e4
commit
7e0038ce14
@@ -74,7 +74,7 @@ public class ReplaceConstructorWithBuilderDialog extends RefactoringDialog {
|
||||
private static final String SETTER_PREFIX_KEY = "ConstructorWithBuilder.SetterPrefix";
|
||||
|
||||
protected ReplaceConstructorWithBuilderDialog(@NotNull Project project, PsiMethod[] constructors) {
|
||||
super(project, false);
|
||||
super(project, false, true);
|
||||
myConstructors = constructors;
|
||||
myParametersMap = new LinkedHashMap<>();
|
||||
mySetterPrefix = PropertiesComponent.getInstance(project).getValue(SETTER_PREFIX_KEY, "set");
|
||||
@@ -130,7 +130,7 @@ public class ReplaceConstructorWithBuilderDialog extends RefactoringDialog {
|
||||
MoveDestination destination =
|
||||
((DestinationFolderComboBox)myDestinationCb).selectDirectory(new PackageWrapper(myConstructors[0].getManager(), packageName), false);
|
||||
invokeRefactoring(new ReplaceConstructorWithBuilderProcessor(getProject(), myConstructors, myParametersMap, className, packageName,
|
||||
destination, createNewBuilder));
|
||||
destination, createNewBuilder, isOpenInEditor()));
|
||||
}
|
||||
|
||||
private void showErrorDialog(@NlsContexts.DialogMessage String message) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package com.intellij.refactoring.replaceConstructorWithBuilder;
|
||||
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.ide.util.EditorHelper;
|
||||
import com.intellij.ide.util.PackageUtil;
|
||||
import com.intellij.java.refactoring.JavaRefactoringBundle;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -52,23 +53,25 @@ public class ReplaceConstructorWithBuilderProcessor extends FixableUsagesRefacto
|
||||
private final boolean myCreateNewBuilderClass;
|
||||
private final PsiElementFactory myElementFactory;
|
||||
private final MoveDestination myMoveDestination;
|
||||
|
||||
private final boolean myOpenInEditor;
|
||||
|
||||
public ReplaceConstructorWithBuilderProcessor(Project project,
|
||||
PsiMethod[] constructors,
|
||||
Map<String, ParameterData> parametersMap,
|
||||
@NotNull String className,
|
||||
String packageName,
|
||||
MoveDestination moveDestination, boolean createNewBuilderClass) {
|
||||
MoveDestination moveDestination,
|
||||
boolean createNewBuilderClass,
|
||||
boolean openInEditor) {
|
||||
super(project);
|
||||
myMoveDestination = moveDestination;
|
||||
myElementFactory = JavaPsiFacade.getElementFactory(myProject);
|
||||
myConstructors = constructors;
|
||||
myParametersMap = parametersMap;
|
||||
|
||||
myClassName = className;
|
||||
myPackageName = packageName;
|
||||
myMoveDestination = moveDestination;
|
||||
myCreateNewBuilderClass = createNewBuilderClass;
|
||||
myOpenInEditor = openInEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -154,6 +157,10 @@ public class ReplaceConstructorWithBuilderProcessor extends FixableUsagesRefacto
|
||||
VisibilityUtil.escalateVisibility(containingClass, builderClass);
|
||||
containingClass = containingClass.getContainingClass();
|
||||
}
|
||||
|
||||
if (myOpenInEditor) {
|
||||
EditorHelper.openInEditor(builderClass);
|
||||
}
|
||||
}
|
||||
|
||||
private void createSetter(PsiClass builderClass, ParameterData parameterData, PsiField field) {
|
||||
|
||||
@@ -68,22 +68,19 @@ public class ReplaceConstructorWithBuilderTest extends LightMultiFileTestCase {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
private void doTest(final boolean createNewBuilderClass) {
|
||||
private void doTest(boolean createNewBuilderClass) {
|
||||
doTest(createNewBuilderClass, null);
|
||||
}
|
||||
|
||||
private void doTest(final boolean createNewBuilderClass, final Map<String, String> expectedDefaults) {
|
||||
private void doTest(boolean createNewBuilderClass, Map<String, String> expectedDefaults) {
|
||||
doTest(createNewBuilderClass, expectedDefaults, null);
|
||||
}
|
||||
|
||||
private void doTest(final boolean createNewBuilderClass, final Map<String, String> expectedDefaults, final String conflicts) {
|
||||
private void doTest(boolean createNewBuilderClass, Map<String, String> expectedDefaults, String conflicts) {
|
||||
doTest(createNewBuilderClass, expectedDefaults, conflicts, "");
|
||||
}
|
||||
|
||||
private void doTest(final boolean createNewBuilderClass,
|
||||
final Map<String, String> expectedDefaults,
|
||||
final String conflicts,
|
||||
final String packageName) {
|
||||
private void doTest(boolean createNew, Map<String, String> expectedDefaults, String conflicts, String packageName) {
|
||||
doTest(() -> {
|
||||
final PsiClass aClass = myFixture.findClass("Test");
|
||||
|
||||
@@ -100,7 +97,9 @@ public class ReplaceConstructorWithBuilderTest extends LightMultiFileTestCase {
|
||||
}
|
||||
}
|
||||
try {
|
||||
new ReplaceConstructorWithBuilderProcessor(getProject(), constructors, map, "Builder", packageName, null, createNewBuilderClass).run();
|
||||
final ReplaceConstructorWithBuilderProcessor processor =
|
||||
new ReplaceConstructorWithBuilderProcessor(getProject(), constructors, map, "Builder", packageName, null, createNew, false);
|
||||
processor.run();
|
||||
if (conflicts != null) {
|
||||
fail("Conflicts were not detected: " + conflicts);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user