From 7d7672924baafc16ca3ebff0da6d0ed2fbafb143 Mon Sep 17 00:00:00 2001 From: Eugene Vigdorchik Date: Fri, 11 Feb 2005 18:27:26 +0300 Subject: [PATCH] (no message) --- .../refactoring/RefactoringFactory.java | 5 +- .../ChangeMethodSignatureFromUsageFix.java | 22 +------ .../impl/quickfix/MethodParameterFix.java | 3 +- .../daemon/impl/quickfix/MethodReturnFix.java | 3 +- .../quickfix/RemoveUnusedParameterFix.java | 3 +- .../impl/quickfix/SuperMethodReturnFix.java | 3 +- .../UnusedParametersInspection.java | 3 +- .../unusedReturnValue/UnusedReturnValue.java | 3 +- .../refactoring/RefactoringDialog.java | 16 +++++ .../ChangeSignatureDialog.java | 15 +++-- .../ChangeSignatureHandler.java | 21 +------ .../ChangeSignatureProcessor.java | 35 +++++------ .../EncapsulateFieldsDialog.java | 19 +++--- .../EncapsulateFieldsHandler.java | 4 +- .../EncapsulateFieldsProcessor.java | 10 +-- .../InheritanceToDelegationDialog.java | 63 +++++++++++-------- .../InheritanceToDelegationHandler.java | 35 +---------- .../InheritanceToDelegationProcessor.java | 17 +++-- .../inline/InlineConstantFieldHandler.java | 5 +- .../inline/InlineConstantFieldProcessor.java | 50 ++++----------- .../refactoring/inline/InlineFieldDialog.java | 18 +++--- .../inline/InlineMethodDialog.java | 19 +++--- .../inline/InlineMethodHandler.java | 5 +- .../inline/InlineMethodProcessor.java | 39 ++++-------- .../openapi/impl/RefactoringFactoryImpl.java | 7 ++- .../openapi/impl/TypeCookRefactoringImpl.java | 23 +++++-- .../refactoring/ChangeSignatureTest.java | 2 +- .../InheritanceToDelegationTest.java | 9 +-- .../refactoring/inline/InlineMethodTest.java | 12 ++-- 29 files changed, 191 insertions(+), 278 deletions(-) diff --git a/openapi/src/com/intellij/refactoring/RefactoringFactory.java b/openapi/src/com/intellij/refactoring/RefactoringFactory.java index 711235c43697..20d1627aa69e 100644 --- a/openapi/src/com/intellij/refactoring/RefactoringFactory.java +++ b/openapi/src/com/intellij/refactoring/RefactoringFactory.java @@ -60,7 +60,10 @@ public abstract class RefactoringFactory { PsiClass targetClass, String factoryName); - public abstract TypeCookRefactoring createTypeCook(PsiElement[] elements); + public abstract TypeCookRefactoring createTypeCook(PsiElement[] elements, + boolean dropObsoleteCasts, + boolean leaveObjectsRaw, + boolean preserveRawArrays); /** * Creates Introduce Parameter refactoring that replaces local variable with parameter. diff --git a/source/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java b/source/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java index ac2bc69e71a9..c42782697d11 100644 --- a/source/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java +++ b/source/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java @@ -124,8 +124,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction { false, null, method.getName(), method.getReturnType(), - myNewParametersInfo, - BaseRefactoringProcessor.EMPTY_CALLBACK); + myNewParametersInfo); if (ApplicationManager.getApplication().isUnitTestMode()) { processor.testRun(); } @@ -141,24 +140,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction { } else { final List parameterInfos = Arrays.asList(myNewParametersInfo); - final ChangeSignatureDialog.Callback callback = new ChangeSignatureDialog.Callback() { - public void run(final ChangeSignatureDialog dialog) { - new ChangeSignatureProcessor( - project, - method, - false, dialog.getVisibility(), - dialog.getMethodName(), - dialog.getReturnType(), - dialog.getParameters(), - null, - new Runnable() { - public void run() { - dialog.close(DialogWrapper.OK_EXIT_CODE); - } - }, null, null).run(null); - } - }; - ChangeSignatureDialog dialog = new ChangeSignatureDialog(project, method, false, callback); + ChangeSignatureDialog dialog = new ChangeSignatureDialog(project, method, false); dialog.setParameterInfos(parameterInfos); dialog.show(); } diff --git a/source/com/intellij/codeInsight/daemon/impl/quickfix/MethodParameterFix.java b/source/com/intellij/codeInsight/daemon/impl/quickfix/MethodParameterFix.java index ddeca90b1522..76278a1cdb88 100644 --- a/source/com/intellij/codeInsight/daemon/impl/quickfix/MethodParameterFix.java +++ b/source/com/intellij/codeInsight/daemon/impl/quickfix/MethodParameterFix.java @@ -74,8 +74,7 @@ public class MethodParameterFix implements IntentionAction { false, null, method.getName(), method.getReturnType(), - getNewParametersInfo(), - BaseRefactoringProcessor.EMPTY_CALLBACK); + getNewParametersInfo()); if (ApplicationManager.getApplication().isUnitTestMode()) { processor.testRun(); diff --git a/source/com/intellij/codeInsight/daemon/impl/quickfix/MethodReturnFix.java b/source/com/intellij/codeInsight/daemon/impl/quickfix/MethodReturnFix.java index 450ac05bf9ef..bf4af48a3f4e 100644 --- a/source/com/intellij/codeInsight/daemon/impl/quickfix/MethodReturnFix.java +++ b/source/com/intellij/codeInsight/daemon/impl/quickfix/MethodReturnFix.java @@ -60,8 +60,7 @@ public class MethodReturnFix implements IntentionAction { false, null, method.getName(), myReturnType, - RemoveUnusedParameterFix.getNewParametersInfo(method, null), - BaseRefactoringProcessor.EMPTY_CALLBACK); + RemoveUnusedParameterFix.getNewParametersInfo(method, null)); if (ApplicationManager.getApplication().isUnitTestMode()) { processor.testRun(); } diff --git a/source/com/intellij/codeInsight/daemon/impl/quickfix/RemoveUnusedParameterFix.java b/source/com/intellij/codeInsight/daemon/impl/quickfix/RemoveUnusedParameterFix.java index 354519edde5b..685618fb0911 100644 --- a/source/com/intellij/codeInsight/daemon/impl/quickfix/RemoveUnusedParameterFix.java +++ b/source/com/intellij/codeInsight/daemon/impl/quickfix/RemoveUnusedParameterFix.java @@ -53,8 +53,7 @@ public class RemoveUnusedParameterFix implements IntentionAction { false, null, method.getName(), method.getReturnType(), - getNewParametersInfo(method, parameter), - BaseRefactoringProcessor.EMPTY_CALLBACK); + getNewParametersInfo(method, parameter)); if (ApplicationManager.getApplication().isUnitTestMode()) { processor.testRun(); diff --git a/source/com/intellij/codeInsight/daemon/impl/quickfix/SuperMethodReturnFix.java b/source/com/intellij/codeInsight/daemon/impl/quickfix/SuperMethodReturnFix.java index 2dad7844fe37..34e891d53f1b 100644 --- a/source/com/intellij/codeInsight/daemon/impl/quickfix/SuperMethodReturnFix.java +++ b/source/com/intellij/codeInsight/daemon/impl/quickfix/SuperMethodReturnFix.java @@ -62,8 +62,7 @@ public class SuperMethodReturnFix implements IntentionAction { false, null, mySuperMethod.getName(), mySuperMethodType, - ParameterInfo.fromMethod(mySuperMethod), - null); + ParameterInfo.fromMethod(mySuperMethod)); if (ApplicationManager.getApplication().isUnitTestMode()) { processor.testRun(); } else { diff --git a/source/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java b/source/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java index dc7c5b2ca0d9..a314136abc48 100644 --- a/source/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java +++ b/source/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java @@ -197,8 +197,7 @@ public class UnusedParametersInspection extends FilteringInspectionTool { psiMethod, false, null, psiMethod.getName(), psiMethod.getReturnType(), - parameterInfos, - BaseRefactoringProcessor.EMPTY_CALLBACK); + parameterInfos); csp.run(null); } diff --git a/source/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValue.java b/source/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValue.java index 827cd7e25916..ce35153800f5 100644 --- a/source/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValue.java +++ b/source/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValue.java @@ -131,8 +131,7 @@ public class UnusedReturnValue extends DescriptorProviderInspection { psiMethod, false, null, psiMethod.getName(), PsiType.VOID, - infos, - BaseRefactoringProcessor.EMPTY_CALLBACK); + infos); csp.run(null); } diff --git a/source/com/intellij/refactoring/RefactoringDialog.java b/source/com/intellij/refactoring/RefactoringDialog.java index e8b85c565422..6bc04e74c7ee 100644 --- a/source/com/intellij/refactoring/RefactoringDialog.java +++ b/source/com/intellij/refactoring/RefactoringDialog.java @@ -51,10 +51,12 @@ public abstract class RefactoringDialog extends DialogWrapper { private Action myRefactorAction; private Action myPreviewAction; private boolean myCbPreviewResults; + private Project myProject; protected RefactoringDialog(Project project, boolean canBeParent) { super (project, canBeParent); myCbPreviewResults = true; + myProject = project; } final public boolean isPreviewUsages() { @@ -131,6 +133,10 @@ public abstract class RefactoringDialog extends DialogWrapper { return new Action[]{getRefactorAction(), getPreviewAction(), getCancelAction()}; } + public Project getProject() { + return myProject; + } + private class RefactorAction extends AbstractAction { public RefactorAction() { putValue(Action.NAME, "Refactor"); @@ -152,4 +158,14 @@ public abstract class RefactoringDialog extends DialogWrapper { } } + protected void invokeRefactoring(BaseRefactoringProcessor processor) { + final Runnable prepareSuccessfulCallback = new Runnable() { + public void run() { + close(DialogWrapper.OK_EXIT_CODE); + } + }; + processor.setPrepareSuccessfulSwingThreadCallback(prepareSuccessfulCallback); + processor.setPreviewUsages(isPreviewUsages()); + processor.run(null); + } } diff --git a/source/com/intellij/refactoring/changeSignature/ChangeSignatureDialog.java b/source/com/intellij/refactoring/changeSignature/ChangeSignatureDialog.java index c4ca723c9f5e..c103bbac749e 100644 --- a/source/com/intellij/refactoring/changeSignature/ChangeSignatureDialog.java +++ b/source/com/intellij/refactoring/changeSignature/ChangeSignatureDialog.java @@ -48,7 +48,6 @@ public class ChangeSignatureDialog extends RefactoringDialog { "#com.intellij.refactoring.changeSignature.ChangeSignatureDialog"); private Project myProject; private PsiMethod myMethod; - private final Callback myCallback; private final boolean myAllowDelegation; private EditorTextField myNameField; private EditorTextField myReturnTypeField; @@ -67,17 +66,12 @@ public class ChangeSignatureDialog extends RefactoringDialog { private PsiMethod[] myMethodsToPropagateParameters = null; private PsiMethod[] myMethodsToPropagateExceptions = null; - public interface Callback { - void run(ChangeSignatureDialog dialog); - } - - public ChangeSignatureDialog(Project project, PsiMethod method, boolean allowDelegation, Callback callback) { + public ChangeSignatureDialog(Project project, PsiMethod method, boolean allowDelegation) { super(project, true); myProject = project; myMethod = method; myParametersTableModel = new ParameterTableModel(myMethod.getParameterList(), this); myExceptionsTableModel = new ExceptionsTableModel(myMethod.getThrowsList()); - myCallback = callback; myAllowDelegation = allowDelegation; setParameterInfos(getParameterInfos(method)); @@ -520,7 +514,12 @@ public class ChangeSignatureDialog extends RefactoringDialog { Messages.showWarningDialog(myProject, "Recursive propagation of thrown exceptions changes won't be performed", ChangeSignatureHandler.REFACTORING_NAME); myMethodsToPropagateExceptions = null; } - myCallback.run(this); + + invokeRefactoring(new ChangeSignatureProcessor(getProject(), myMethod, isGenerateDelegate(), + getVisibility(), getMethodName(), getReturnType(), + getParameters(), getExceptions(), + getEndPointsToPropagateParameters(), + getEndPointsToPropagateExceptions())); } private String validateAndCommitData() { diff --git a/source/com/intellij/refactoring/changeSignature/ChangeSignatureHandler.java b/source/com/intellij/refactoring/changeSignature/ChangeSignatureHandler.java index 67a5380dfd1c..4626597ecec1 100644 --- a/source/com/intellij/refactoring/changeSignature/ChangeSignatureHandler.java +++ b/source/com/intellij/refactoring/changeSignature/ChangeSignatureHandler.java @@ -74,26 +74,7 @@ public class ChangeSignatureHandler implements RefactoringActionHandler { } final PsiClass containingClass = method.getContainingClass(); - final ChangeSignatureDialog dialog = new ChangeSignatureDialog(project, method, containingClass != null && !containingClass.isInterface(), new ChangeSignatureDialog.Callback() { - public void run(final ChangeSignatureDialog dialog) { - new ChangeSignatureProcessor( - project, - method, - dialog.isGenerateDelegate(), - dialog.getVisibility(), - dialog.getMethodName(), - dialog.getReturnType(), - dialog.getParameters(), - dialog.getExceptions(), - new Runnable() { - public void run() { - dialog.close(DialogWrapper.OK_EXIT_CODE); - } - }, - dialog.getEndPointsToPropagateParameters(), - dialog.getEndPointsToPropagateExceptions()).run(null); - } - }); + final ChangeSignatureDialog dialog = new ChangeSignatureDialog(project, method, containingClass != null && !containingClass.isInterface()); dialog.show(); } diff --git a/source/com/intellij/refactoring/changeSignature/ChangeSignatureProcessor.java b/source/com/intellij/refactoring/changeSignature/ChangeSignatureProcessor.java index 46be31919021..485aa64e7a4d 100644 --- a/source/com/intellij/refactoring/changeSignature/ChangeSignatureProcessor.java +++ b/source/com/intellij/refactoring/changeSignature/ChangeSignatureProcessor.java @@ -60,30 +60,28 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor { private final PsiMethod[] myPropagateExceptionsEndPoints; public ChangeSignatureProcessor(Project project, - PsiMethod method, - final boolean generateDelegate, - String newVisibility, - String newName, - PsiType newType, - ParameterInfo[] parameterInfo, - Runnable prepareSuccessfulCallback) { + PsiMethod method, + final boolean generateDelegate, + String newVisibility, + String newName, + PsiType newType, + ParameterInfo[] parameterInfo) { this(project, method, generateDelegate, newVisibility, newName, newType != null ? CanonicalTypes.createTypeWrapper(newType) : null, - parameterInfo, null, prepareSuccessfulCallback, null, null); + parameterInfo, null, null, null); } public ChangeSignatureProcessor(Project project, - PsiMethod method, - final boolean generateDelegate, - String newVisibility, - String newName, - PsiType newType, - ParameterInfo[] parameterInfo, - ThrownExceptionInfo[] exceptionInfos, - Runnable prepareSuccessfulCallback) { + PsiMethod method, + final boolean generateDelegate, + String newVisibility, + String newName, + PsiType newType, + ParameterInfo[] parameterInfo, + ThrownExceptionInfo[] exceptionInfos) { this(project, method, generateDelegate, newVisibility, newName, newType != null ? CanonicalTypes.createTypeWrapper(newType) : null, - parameterInfo, exceptionInfos, prepareSuccessfulCallback, null, null); + parameterInfo, exceptionInfos, null, null); } public ChangeSignatureProcessor(Project project, @@ -94,10 +92,9 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor { CanonicalTypes.Type newType, ParameterInfo[] parameterInfo, ThrownExceptionInfo[] thrownExceptions, - Runnable prepareSuccessfulCallback, PsiMethod[] propagateParametersEndPoints, PsiMethod[] propagateExceptionsEndPoints) { - super(project, prepareSuccessfulCallback); + super(project); myGenerateDelegate = generateDelegate; myPropagateParametersEndPoints = propagateParametersEndPoints; myPropagateExceptionsEndPoints = propagateExceptionsEndPoints; diff --git a/source/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsDialog.java b/source/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsDialog.java index df7941c355e1..e7d757477451 100644 --- a/source/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsDialog.java +++ b/source/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsDialog.java @@ -37,10 +37,6 @@ public class EncapsulateFieldsDialog extends RefactoringDialog { "#com.intellij.refactoring.encapsulateFields.EncapsulateFieldsDialog" ); - public static interface Callback { - void run(EncapsulateFieldsDialog dialog); - } - private static final int CHECKED_COLUMN = 0; private static final int FIELD_COLUMN = 1; private static final int GETTER_COLUMN = 2; @@ -48,7 +44,6 @@ public class EncapsulateFieldsDialog extends RefactoringDialog { private final Project myProject; private final PsiClass myClass; - private final Callback myCallback; private PsiField[] myFields; private boolean[] myCheckedMarks; @@ -90,11 +85,10 @@ public class EncapsulateFieldsDialog extends RefactoringDialog { myRbFieldProtected.setFocusable(false); } - public EncapsulateFieldsDialog(Project project, PsiClass aClass, final Set preselectedFields, Callback callback) { + public EncapsulateFieldsDialog(Project project, PsiClass aClass, final Set preselectedFields) { super(project, true); myProject = project; myClass = aClass; - myCallback = callback; String title = "Encapsulate Fields"; String qName = myClass.getQualifiedName(); @@ -438,13 +432,14 @@ public class EncapsulateFieldsDialog extends RefactoringDialog { } } String errorString = validateData(); - if (errorString == null) { - myCallback.run(this); - RefactoringSettings settings = RefactoringSettings.getInstance(); - settings.ENCAPSULATE_FIELDS_USE_ACCESSORS_WHEN_ACCESSIBLE = myCbUseAccessorsWhenAccessible.isSelected(); - } else { // were errors + if (errorString != null) { // were errors RefactoringMessageUtil.showErrorMessage("Encapsulate Fields", errorString, HelpID.ENCAPSULATE_FIELDS, myProject); + return; } + + invokeRefactoring(new EncapsulateFieldsProcessor(myProject, this)); + RefactoringSettings settings = RefactoringSettings.getInstance(); + settings.ENCAPSULATE_FIELDS_USE_ACCESSORS_WHEN_ACCESSIBLE = myCbUseAccessorsWhenAccessible.isSelected(); } /** diff --git a/source/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsHandler.java b/source/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsHandler.java index d4ae022e2107..1b9f27629808 100644 --- a/source/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsHandler.java +++ b/source/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsHandler.java @@ -102,9 +102,7 @@ public class EncapsulateFieldsHandler implements RefactoringActionHandler { EncapsulateFieldsDialog dialog = new EncapsulateFieldsDialog( project, aClass, - preselectedFields, - new EncapsulateFieldsProcessor(project) - ); + preselectedFields); dialog.show(); } } \ No newline at end of file diff --git a/source/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsProcessor.java b/source/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsProcessor.java index 71db6e6402fe..75f68c97d669 100644 --- a/source/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsProcessor.java +++ b/source/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsProcessor.java @@ -31,7 +31,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; -public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor implements EncapsulateFieldsDialog.Callback { +public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor { private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.encapsulateFields.EncapsulateFieldsProcessor"); private PsiClass myClass; @@ -41,8 +41,9 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor impleme private HashMap myNameToGetter; private HashMap myNameToSetter; - public EncapsulateFieldsProcessor(Project project) { + public EncapsulateFieldsProcessor(Project project, EncapsulateFieldsDialog dialog) { super(project); + myDialog = dialog; } protected UsageViewDescriptor createUsageViewDescriptor(UsageInfo[] usages, FindUsagesCommand refreshCommand) { @@ -57,11 +58,6 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor impleme return "Encapsulating fields in " + UsageViewUtil.getDescriptiveName(myClass); } - public void run(EncapsulateFieldsDialog dialog) { - myDialog = dialog; - run((Object)null); - } - public void run(Object markerId) { myFields = myDialog.getSelectedFields(); if (myFields.length == 0){ diff --git a/source/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationDialog.java b/source/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationDialog.java index 8265d9801689..f13187726a70 100644 --- a/source/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationDialog.java +++ b/source/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationDialog.java @@ -2,17 +2,13 @@ package com.intellij.refactoring.inheritanceToDelegation; import com.intellij.openapi.help.HelpManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.help.HelpManager; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiManager; -import com.intellij.psi.PsiType; +import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.codeStyle.SuggestedNameInfo; import com.intellij.psi.codeStyle.VariableKind; import com.intellij.refactoring.HelpID; -import com.intellij.refactoring.RefactoringSettings; import com.intellij.refactoring.RefactoringDialog; +import com.intellij.refactoring.RefactoringSettings; import com.intellij.refactoring.ui.ClassCellRenderer; import com.intellij.refactoring.ui.MemberSelectionPanel; import com.intellij.refactoring.ui.NameSuggestionsField; @@ -27,16 +23,12 @@ import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.KeyEvent; +import java.util.ArrayList; public class InheritanceToDelegationDialog extends RefactoringDialog { private PsiClass[] mySuperClasses; - public static interface Callback { - void run(InheritanceToDelegationDialog dialog); - } - private PsiClass myClass; - private Callback myCallback; private HashMap myBasesToMemberInfos; private NameSuggestionsField myFieldNameField; @@ -46,12 +38,13 @@ public class InheritanceToDelegationDialog extends RefactoringDialog { private JComboBox myClassCombo; private Project myProject; - public InheritanceToDelegationDialog(Project project, PsiClass aClass, - PsiClass[] superClasses, HashMap basesToMemberInfos, Callback callback) { + public InheritanceToDelegationDialog(Project project, + PsiClass aClass, + PsiClass[] superClasses, + HashMap basesToMemberInfos) { super(project, true); myProject = project; myClass = aClass; - myCallback = callback; mySuperClasses = superClasses; myBasesToMemberInfos = basesToMemberInfos; @@ -64,7 +57,7 @@ public class InheritanceToDelegationDialog extends RefactoringDialog { } public String getInnerClassName() { - if(myInnerClassNameField != null) { + if (myInnerClassNameField != null) { return myInnerClassNameField.getName(); } else { @@ -81,7 +74,7 @@ public class InheritanceToDelegationDialog extends RefactoringDialog { } public PsiClass getSelectedTargetClass() { - return (PsiClass) myClassCombo.getSelectedItem(); + return (PsiClass)myClassCombo.getSelectedItem(); } @@ -90,9 +83,28 @@ public class InheritanceToDelegationDialog extends RefactoringDialog { } protected void doAction() { - if(!isOKActionEnabled()) return; RefactoringSettings.getInstance().INHERITANCE_TO_DELEGATION_DELEGATE_OTHER = myCbGenerateGetter.isSelected(); - myCallback.run(this); + + final MemberInfo[] selectedMemberInfos = getSelectedMemberInfos(); + final ArrayList implementedInterfaces = new ArrayList(); + final ArrayList delegatedMethods = new ArrayList(); + + for (int i = 0; i < selectedMemberInfos.length; i++) { + MemberInfo memberInfo = selectedMemberInfos[i]; + final PsiElement member = memberInfo.getMember(); + if (member instanceof PsiClass && Boolean.FALSE.equals(memberInfo.getOverrides())) { + implementedInterfaces.add((PsiClass)member); + } + else if (member instanceof PsiMethod) { + delegatedMethods.add((PsiMethod)member); + } + } + invokeRefactoring(new InheritanceToDelegationProcessor(myProject, myClass, + getSelectedTargetClass(), getFieldName(), + getInnerClassName(), + implementedInterfaces.toArray(new PsiClass[implementedInterfaces.size()]), + delegatedMethods.toArray(new PsiMethod[delegatedMethods.size()]), + isGenerateGetter(), isGenerateGetter())); } protected JComponent createNorthPanel() { @@ -118,7 +130,7 @@ public class InheritanceToDelegationDialog extends RefactoringDialog { myClassCombo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { - if(e.getStateChange() == ItemEvent.SELECTED) { + if (e.getStateChange() == ItemEvent.SELECTED) { updateTargetClass(); } } @@ -139,7 +151,7 @@ public class InheritanceToDelegationDialog extends RefactoringDialog { fieldNameLabel.setDisplayedMnemonic('F'); fieldNameLabel.setLabelFor(myFieldNameField.getComponent()); -// if(InheritanceToDelegationUtil.isInnerClassNeeded(myClass, mySuperClass)) { + // if(InheritanceToDelegationUtil.isInnerClassNeeded(myClass, mySuperClass)) { gbc.gridx = 0; gbc.gridy++; gbc.gridwidth = 1; @@ -160,7 +172,7 @@ public class InheritanceToDelegationDialog extends RefactoringDialog { panel.add(myInnerClassNameField.getComponent(), gbc); innerClassNameLabel.setDisplayedMnemonic('I'); innerClassNameLabel.setLabelFor(myInnerClassNameField.getComponent()); -// } + // } return panel; @@ -206,16 +218,17 @@ public class InheritanceToDelegationDialog extends RefactoringDialog { PsiManager psiManager = myClass.getManager(); PsiType superType = psiManager.getElementFactory().createType(targetClass); SuggestedNameInfo suggestedNameInfo = - CodeStyleManager.getInstance(psiManager.getProject()).suggestVariableName(VariableKind.FIELD, null, null, superType); + CodeStyleManager.getInstance(psiManager.getProject()).suggestVariableName(VariableKind.FIELD, null, null, superType); myFieldNameField.setSuggestions(suggestedNameInfo.names); myInnerClassNameField.getComponent().setEnabled(InheritanceToDelegationUtil.isInnerClassNeeded(myClass, targetClass)); myInnerClassNameField.setSuggestions(new String[]{"My" + targetClass.getName()}); - myMemberSelectionPanel.getTable().setMemberInfos((MemberInfo[]) myBasesToMemberInfos.get(targetClass)); + myMemberSelectionPanel.getTable().setMemberInfos((MemberInfo[])myBasesToMemberInfos.get(targetClass)); myMemberSelectionPanel.getTable().fireExternalDataChange(); } private class MyMemberInfoModel implements MemberInfoModel { final HashMap myGraphs; + public MyMemberInfoModel() { myGraphs = new HashMap(); for (int i = 0; i < mySuperClasses.length; i++) { @@ -225,7 +238,7 @@ public class InheritanceToDelegationDialog extends RefactoringDialog { } public boolean isMemberEnabled(MemberInfo memberInfo) { - if(getGraph().getDependent().contains(memberInfo.getMember())) { + if (getGraph().getDependent().contains(memberInfo.getMember())) { return false; } else { @@ -266,7 +279,7 @@ public class InheritanceToDelegationDialog extends RefactoringDialog { } private InterfaceMemberDependencyGraph getGraph() { - return (InterfaceMemberDependencyGraph) myGraphs.get(getSelectedTargetClass()); + return (InterfaceMemberDependencyGraph)myGraphs.get(getSelectedTargetClass()); } } } diff --git a/source/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationHandler.java b/source/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationHandler.java index 328f17f08192..d70a2a5d9bd5 100644 --- a/source/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationHandler.java +++ b/source/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationHandler.java @@ -13,7 +13,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; import com.intellij.psi.*; import com.intellij.refactoring.RefactoringActionHandler; import com.intellij.refactoring.util.RefactoringHierarchyUtil; @@ -24,11 +23,10 @@ import com.intellij.util.containers.HashMap; import java.util.ArrayList; -public class InheritanceToDelegationHandler implements RefactoringActionHandler, InheritanceToDelegationDialog.Callback { +public class InheritanceToDelegationHandler implements RefactoringActionHandler { private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.inheritanceToDelegation.InheritanceToDelegationHandler"); public static final String REFACTORING_NAME = "Replace Inheritance With Delegation"; - private Project myProject; private PsiClass myClass; private static final MemberInfo.Filter MEMBER_INFO_FILTER = new MemberInfo.Filter() { public boolean includeMember(PsiMember element) { @@ -70,7 +68,6 @@ public class InheritanceToDelegationHandler implements RefactoringActionHandler, public void invoke(Project project, PsiElement[] elements, DataContext dataContext) { if (elements.length != 1) return; - myProject = project; myClass = (PsiClass) elements[0]; if (myClass.isInterface()) { @@ -103,8 +100,7 @@ public class InheritanceToDelegationHandler implements RefactoringActionHandler, new InheritanceToDelegationDialog(project, myClass, - bases, basesToMemberInfos, this - ).show(); + bases, basesToMemberInfos).show(); } private MemberInfo[] createBaseClassMemberInfos(PsiClass baseClass) { @@ -124,31 +120,4 @@ public class InheritanceToDelegationHandler implements RefactoringActionHandler, final MemberInfo[] targetClassMemberInfos = memberInfoList.toArray(new MemberInfo[memberInfoList.size()]); return targetClassMemberInfos; } - - public void run(final InheritanceToDelegationDialog dialog) { - final MemberInfo[] selectedMemberInfos = dialog.getSelectedMemberInfos(); - final ArrayList implementedInterfaces = new ArrayList(); - final ArrayList delegatedMethods = new ArrayList(); - - for (int i = 0; i < selectedMemberInfos.length; i++) { - MemberInfo memberInfo = selectedMemberInfos[i]; - final PsiElement member = memberInfo.getMember(); - if (member instanceof PsiClass && Boolean.FALSE.equals(memberInfo.getOverrides())) { - implementedInterfaces.add((PsiClass)member); - } else if (member instanceof PsiMethod) { - delegatedMethods.add((PsiMethod)member); - } - } - new InheritanceToDelegationProcessor(myProject, myClass, - dialog.getSelectedTargetClass(), dialog.getFieldName(), dialog.getInnerClassName(), - implementedInterfaces.toArray(new PsiClass[implementedInterfaces.size()]), - delegatedMethods.toArray(new PsiMethod[delegatedMethods.size()]), - dialog.isGenerateGetter(), dialog.isGenerateGetter(), - dialog.isPreviewUsages(), new Runnable() { - public void run() { - dialog.close(DialogWrapper.CANCEL_EXIT_CODE); - } - } - ).run(null); - } } diff --git a/source/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationProcessor.java b/source/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationProcessor.java index ef5e480ef731..8dabcf2ddac4 100644 --- a/source/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationProcessor.java +++ b/source/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationProcessor.java @@ -50,8 +50,6 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor { private final HashMap myDelegatedMethodsVisibility; private final LinkedHashSet myOverridenMethods; - private boolean myPreviewUsages; - private final PsiClass myBaseClass; private final Set myBaseClassMembers; private final String myFieldName; @@ -69,19 +67,20 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor { public InheritanceToDelegationProcessor(Project project, PsiClass aClass, - PsiClass targetBaseClass, String fieldName, String innerClassName, - PsiClass[] delegatedInterfaces, PsiMethod[] delegatedMethods, - boolean delegateOtherMembers, boolean generateGetter, - boolean previewUsages, - Runnable prepareSuccessfulCallback) { - super(project, prepareSuccessfulCallback); + PsiClass targetBaseClass, + String fieldName, + String innerClassName, + PsiClass[] delegatedInterfaces, + PsiMethod[] delegatedMethods, + boolean delegateOtherMembers, + boolean generateGetter) { + super(project); myClass = aClass; myInnerClassName = innerClassName; myIsDelegateOtherMembers = delegateOtherMembers; myManager = myClass.getManager(); myFactory = myManager.getElementFactory(); - myPreviewUsages = previewUsages; myBaseClass = targetBaseClass; LOG.assertTrue( diff --git a/source/com/intellij/refactoring/inline/InlineConstantFieldHandler.java b/source/com/intellij/refactoring/inline/InlineConstantFieldHandler.java index 3133e2d6a944..4e592fcfddc7 100644 --- a/source/com/intellij/refactoring/inline/InlineConstantFieldHandler.java +++ b/source/com/intellij/refactoring/inline/InlineConstantFieldHandler.java @@ -50,9 +50,8 @@ public class InlineConstantFieldHandler { if (!invokedOnReference && !field.isWritable()) { if (!RefactoringMessageUtil.checkReadOnlyStatus(project, field)) return; } - PsiReferenceExpression element = reference != null ? (PsiReferenceExpression)reference.getElement() : null; - final InlineConstantFieldProcessor processor = new InlineConstantFieldProcessor(field, project, element, editor); - InlineFieldDialog dialog = new InlineFieldDialog(project, field, invokedOnReference, processor); + PsiReferenceExpression refExpression = reference != null ? (PsiReferenceExpression)reference.getElement() : null; + InlineFieldDialog dialog = new InlineFieldDialog(project, field, refExpression); dialog.show(); } } diff --git a/source/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java b/source/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java index f861f2819139..98b9d347f9ee 100644 --- a/source/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java +++ b/source/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java @@ -2,12 +2,7 @@ package com.intellij.refactoring.inline; import com.intellij.codeInsight.ChangeContextUtil; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.LogicalPosition; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.wm.ToolWindowManager; -import com.intellij.openapi.wm.WindowManager; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiSearchHelper; @@ -28,18 +23,17 @@ import java.util.Iterator; /** * @author ven */ -class InlineConstantFieldProcessor extends BaseRefactoringProcessor implements InlineFieldDialog.Callback { +class InlineConstantFieldProcessor extends BaseRefactoringProcessor { private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.inline.InlineConstantFieldProcessor"); private PsiField myField; - private InlineFieldDialog myDialog; private PsiReferenceExpression myRefExpr; - private Editor myEditor; + private final boolean myInlineThisOnly; - public InlineConstantFieldProcessor(PsiField field, Project project, PsiReferenceExpression ref, Editor editor) { + public InlineConstantFieldProcessor(PsiField field, Project project, PsiReferenceExpression ref, boolean isInlineThisOnly) { super(project); myField = field; myRefExpr = ref; - myEditor = editor; + myInlineThisOnly = isInlineThisOnly; } protected UsageViewDescriptor createUsageViewDescriptor(UsageInfo[] usages, FindUsagesCommand refreshCommand) { @@ -48,7 +42,7 @@ class InlineConstantFieldProcessor extends BaseRefactoringProcessor implements I protected UsageInfo[] findUsages() { PsiManager manager = myField.getManager(); - if (myDialog.isInlineThisOnly()) return new UsageInfo[]{new UsageInfo(myRefExpr)}; + if (myInlineThisOnly) return new UsageInfo[]{new UsageInfo(myRefExpr)}; PsiSearchHelper helper = manager.getSearchHelper(); PsiReference[] refs = helper.findReferences(myField, GlobalSearchScope.projectScope(myProject), false); @@ -68,15 +62,6 @@ class InlineConstantFieldProcessor extends BaseRefactoringProcessor implements I } protected void performRefactoring(UsageInfo[] usages) { - int col = -1; - int line = -1; - if (myEditor != null) { - col = myEditor.getCaretModel().getLogicalPosition().column; - line = myEditor.getCaretModel().getLogicalPosition().line; - LogicalPosition pos = new LogicalPosition(0, 0); - myEditor.getCaretModel().moveToLogicalPosition(pos); - } - PsiExpression initializer = myField.getInitializer(); LOG.assertTrue(initializer != null); @@ -114,7 +99,7 @@ class InlineConstantFieldProcessor extends BaseRefactoringProcessor implements I } } - if (!myDialog.isInlineThisOnly()) { + if (!myInlineThisOnly) { try { myField.delete(); } @@ -122,11 +107,6 @@ class InlineConstantFieldProcessor extends BaseRefactoringProcessor implements I LOG.error(e); } } - - if (myEditor != null) { - LogicalPosition pos = new LogicalPosition(line, col); - myEditor.getCaretModel().moveToLogicalPosition(pos); - } } private PsiExpression normalize(PsiExpression expression) { @@ -184,18 +164,17 @@ class InlineConstantFieldProcessor extends BaseRefactoringProcessor implements I } } - if (myDialog != null && conflicts.size() > 0) { + if (conflicts.size() > 0) { ConflictsDialog dialog = new ConflictsDialog(conflicts.toArray(new String[conflicts.size()]), myProject); dialog.show(); - if (!dialog.isOK()) return false; + if (!dialog.isOK()) { + prepareSuccessful(); + return false; + } } - ToolWindowManager.getInstance(myProject).invokeLater(new Runnable() { - public void run() { - myDialog.close(DialogWrapper.CANCEL_EXIT_CODE); - } - }); + prepareSuccessful(); return true; } @@ -206,9 +185,4 @@ class InlineConstantFieldProcessor extends BaseRefactoringProcessor implements I return PsiUtil.isAccessedForWriting(expr); } - - public void run(InlineFieldDialog dialog) { - myDialog = dialog; - this.run((Object)null); - } } diff --git a/source/com/intellij/refactoring/inline/InlineFieldDialog.java b/source/com/intellij/refactoring/inline/InlineFieldDialog.java index 07972bff82b7..f84f2e5557df 100644 --- a/source/com/intellij/refactoring/inline/InlineFieldDialog.java +++ b/source/com/intellij/refactoring/inline/InlineFieldDialog.java @@ -2,39 +2,35 @@ package com.intellij.refactoring.inline; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; import com.intellij.psi.PsiField; +import com.intellij.psi.PsiReferenceExpression; import com.intellij.psi.PsiSubstitutor; import com.intellij.psi.util.PsiFormatUtil; -import com.intellij.refactoring.RefactoringSettings; import com.intellij.refactoring.RefactoringDialog; +import com.intellij.refactoring.RefactoringSettings; import com.intellij.ui.IdeBorderFactory; import javax.swing.*; -import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; public class InlineFieldDialog extends RefactoringDialog implements InlineOptions { public static final String REFACTORING_NAME = "Inline Field"; - public static interface Callback { - void run(InlineFieldDialog dialog); - } + private PsiReferenceExpression myReferenceExpression; private JLabel myFieldNameLabel = new JLabel(); private final PsiField myField; private final boolean myInvokedOnReference; - private final Callback myCallback; private JRadioButton myRbInlineAll; private JRadioButton myRbInlineThisOnly; - public InlineFieldDialog(Project project, PsiField field, boolean invokedOnReference, Callback callback) { + public InlineFieldDialog(Project project, PsiField field, PsiReferenceExpression ref) { super(project, true); myField = field; - myInvokedOnReference = invokedOnReference; - myCallback = callback; + myReferenceExpression = ref; + myInvokedOnReference = myReferenceExpression != null; setTitle(REFACTORING_NAME); @@ -101,7 +97,7 @@ public class InlineFieldDialog extends RefactoringDialog implements InlineOption } protected void doAction() { - myCallback.run(this); + invokeRefactoring(new InlineConstantFieldProcessor(myField, getProject(), myReferenceExpression, isInlineThisOnly())); RefactoringSettings settings = RefactoringSettings.getInstance(); if(myRbInlineThisOnly.isEnabled() && myRbInlineAll.isEnabled()) { settings.INLINE_FIELD_THIS = isInlineThisOnly(); diff --git a/source/com/intellij/refactoring/inline/InlineMethodDialog.java b/source/com/intellij/refactoring/inline/InlineMethodDialog.java index ca8cdb2d962c..eb7bf39875d8 100644 --- a/source/com/intellij/refactoring/inline/InlineMethodDialog.java +++ b/source/com/intellij/refactoring/inline/InlineMethodDialog.java @@ -1,22 +1,25 @@ package com.intellij.refactoring.inline; +import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.psi.PsiJavaCodeReferenceElement; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiSubstitutor; import com.intellij.psi.util.PsiFormatUtil; -import com.intellij.refactoring.RefactoringSettings; import com.intellij.refactoring.RefactoringDialog; +import com.intellij.refactoring.RefactoringSettings; import com.intellij.ui.IdeBorderFactory; import javax.swing.*; -import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; public class InlineMethodDialog extends RefactoringDialog implements InlineOptions { public static final String REFACTORING_NAME = "Inline Method"; + private PsiJavaCodeReferenceElement myReferenceElement; + private final Editor myEditor; + public static interface Callback { void run(InlineMethodDialog dialog); } @@ -25,16 +28,16 @@ public class InlineMethodDialog extends RefactoringDialog implements InlineOptio private final PsiMethod myMethod; private final boolean myInvokedOnReference; - private final Callback myCallback; private JRadioButton myRbInlineAll; private JRadioButton myRbInlineThisOnly; - public InlineMethodDialog(Project project, PsiMethod method, boolean invokedOnReference, Callback callback) { + public InlineMethodDialog(Project project, PsiMethod method, PsiJavaCodeReferenceElement ref, Editor editor) { super(project, true); myMethod = method; - myInvokedOnReference = invokedOnReference; - myCallback = callback; + myReferenceElement = ref; + myEditor = editor; + myInvokedOnReference = ref != null; setTitle(REFACTORING_NAME); @@ -101,7 +104,7 @@ public class InlineMethodDialog extends RefactoringDialog implements InlineOptio } protected void doAction() { - myCallback.run(this); + invokeRefactoring(new InlineMethodProcessor(getProject(), myMethod, myReferenceElement, myEditor, isInlineThisOnly())); RefactoringSettings settings = RefactoringSettings.getInstance(); if(myRbInlineThisOnly.isEnabled() && myRbInlineAll.isEnabled()) { settings.INLINE_METHOD_THIS = isInlineThisOnly(); diff --git a/source/com/intellij/refactoring/inline/InlineMethodHandler.java b/source/com/intellij/refactoring/inline/InlineMethodHandler.java index eb1cf6cc5091..4590711d6488 100644 --- a/source/com/intellij/refactoring/inline/InlineMethodHandler.java +++ b/source/com/intellij/refactoring/inline/InlineMethodHandler.java @@ -58,9 +58,8 @@ class InlineMethodHandler { if (!invokedOnReference && !method.isWritable()) { if (!RefactoringMessageUtil.checkReadOnlyStatus(project, method)) return; } - PsiJavaCodeReferenceElement element = reference != null ? (PsiJavaCodeReferenceElement)reference.getElement() : null; - final InlineMethodProcessor processor = new InlineMethodProcessor(project, method, element, editor); - InlineMethodDialog dialog = new InlineMethodDialog(project, method, invokedOnReference, processor); + PsiJavaCodeReferenceElement refElement = reference != null ? (PsiJavaCodeReferenceElement)reference.getElement() : null; + InlineMethodDialog dialog = new InlineMethodDialog(project, method, refElement, editor); dialog.show(); } diff --git a/source/com/intellij/refactoring/inline/InlineMethodProcessor.java b/source/com/intellij/refactoring/inline/InlineMethodProcessor.java index 91d0d341c137..81feb5401bae 100644 --- a/source/com/intellij/refactoring/inline/InlineMethodProcessor.java +++ b/source/com/intellij/refactoring/inline/InlineMethodProcessor.java @@ -8,9 +8,7 @@ import com.intellij.openapi.editor.LogicalPosition; import com.intellij.openapi.localVcs.LvcsAction; import com.intellij.openapi.localVcs.impl.LvcsIntegration; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.util.Key; -import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.codeStyle.VariableKind; @@ -35,13 +33,13 @@ import com.intellij.util.containers.HashMap; import java.util.*; -public class InlineMethodProcessor extends BaseRefactoringProcessor implements InlineMethodDialog.Callback { +public class InlineMethodProcessor extends BaseRefactoringProcessor { private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.inline.InlineMethodProcessor"); private PsiMethod myMethod; private PsiJavaCodeReferenceElement myReference; private Editor myEditor; - private InlineOptions myDialog; + private final boolean myInlineThisOnly; private PsiManager myManager; private PsiElementFactory myFactory; @@ -55,11 +53,13 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor implements I public InlineMethodProcessor(Project project, PsiMethod method, PsiJavaCodeReferenceElement reference, - Editor editor) { + Editor editor, + boolean isInlineThisOnly) { super(project); myMethod = method; myReference = reference; myEditor = editor; + myInlineThisOnly = isInlineThisOnly; myManager = PsiManager.getInstance(myProject); myFactory = myManager.getElementFactory(); @@ -71,23 +71,12 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor implements I return "Inlining method " + myDescriptiveName; } - public void run(InlineMethodDialog dialog) { - myDialog = dialog; - run((Object)null); - } - - public void testRun(InlineOptions dialog) { - myDialog = dialog; - UsageInfo[] usages = findUsages(); - performRefactoring(usages); - } - protected UsageViewDescriptor createUsageViewDescriptor(UsageInfo[] usages, FindUsagesCommand refreshCommand) { return new InlineViewDescriptor(myMethod, usages, refreshCommand); } protected UsageInfo[] findUsages() { - if (myDialog.isInlineThisOnly()) return new UsageInfo[]{new UsageInfo(myReference)}; + if (myInlineThisOnly) return new UsageInfo[]{new UsageInfo(myReference)}; PsiSearchHelper helper = myManager.getSearchHelper(); PsiReference[] refs = helper.findReferences(myMethod, GlobalSearchScope.projectScope(myProject), true); UsageInfo[] infos = new UsageInfo[refs.length]; @@ -131,19 +120,17 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor implements I } } - if (myDialog != null && conflicts.size() > 0) { + if (conflicts.size() > 0) { ConflictsDialog dialog = new ConflictsDialog(conflicts.toArray(new String[conflicts.size()]), myProject); dialog.show(); - if (!dialog.isOK()) return false; + if (!dialog.isOK()) { + prepareSuccessful(); + return false; + } } - // make sure that dialog is closed in swing thread - ToolWindowManager.getInstance(myProject).invokeLater(new Runnable() { - public void run() { - myDialog.close(DialogWrapper.CANCEL_EXIT_CODE); - } - }); + prepareSuccessful(); return true; } @@ -203,7 +190,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor implements I private void doRefactoring(UsageInfo[] usages) { try { - if (myDialog.isInlineThisOnly()) { + if (myInlineThisOnly) { if (myMethod.isConstructor()) { PsiCall constructorCall = RefactoringUtil.getEnclosingConstructorCall(myReference); if (constructorCall != null) { diff --git a/source/com/intellij/refactoring/openapi/impl/RefactoringFactoryImpl.java b/source/com/intellij/refactoring/openapi/impl/RefactoringFactoryImpl.java index 81e32746e5d1..640bafce9239 100644 --- a/source/com/intellij/refactoring/openapi/impl/RefactoringFactoryImpl.java +++ b/source/com/intellij/refactoring/openapi/impl/RefactoringFactoryImpl.java @@ -109,8 +109,11 @@ public class RefactoringFactoryImpl extends RefactoringFactory implements Projec return new ReplaceConstructorWithFactoryRefactoringImpl(myProject, originalClass, targetClass, factoryName); } - public TypeCookRefactoring createTypeCook(PsiElement[] elements) { - return new TypeCookRefactoringImpl(myProject, elements); + public TypeCookRefactoring createTypeCook(PsiElement[] elements, + boolean dropObsoleteCasts, + boolean leaveObjectsRaw, + boolean preserveRawArrays) { + return new TypeCookRefactoringImpl(myProject, elements, dropObsoleteCasts, leaveObjectsRaw, preserveRawArrays); } public IntroduceParameterRefactoring createIntroduceParameterRefactoring(PsiMethod methodToReplaceIn, diff --git a/source/com/intellij/refactoring/openapi/impl/TypeCookRefactoringImpl.java b/source/com/intellij/refactoring/openapi/impl/TypeCookRefactoringImpl.java index ad1a96f0f51f..90e9b6b8dbce 100644 --- a/source/com/intellij/refactoring/openapi/impl/TypeCookRefactoringImpl.java +++ b/source/com/intellij/refactoring/openapi/impl/TypeCookRefactoringImpl.java @@ -8,6 +8,7 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.refactoring.RefactoringImpl; import com.intellij.refactoring.TypeCookRefactoring; +import com.intellij.refactoring.typeCook.Settings; import com.intellij.refactoring.typeCook.deductive.TypeCookProcessor; import java.util.List; @@ -16,13 +17,27 @@ import java.util.List; * @author dsl */ public class TypeCookRefactoringImpl extends RefactoringImpl implements TypeCookRefactoring { - TypeCookRefactoringImpl(Project project, PsiElement[] elements) { - super(new TypeCookProcessor(project, elements)); + TypeCookRefactoringImpl(Project project, + PsiElement[] elements, + final boolean dropObsoleteCasts, + final boolean leaveObjectsRaw, + final boolean preserveRawArrays) { + super(new TypeCookProcessor(project, elements, new Settings() { + public boolean dropObsoleteCasts() { + return dropObsoleteCasts; + } + + public boolean leaveObjectParameterizedTypesRaw() { + return leaveObjectsRaw; + } + + public boolean preserveRawArrays() { + return preserveRawArrays; + } + })); } public List getElements() { return myProcessor.getElements(); } - - } diff --git a/testSource/com/intellij/refactoring/ChangeSignatureTest.java b/testSource/com/intellij/refactoring/ChangeSignatureTest.java index 5deabf5539ec..76305aa00bd7 100644 --- a/testSource/com/intellij/refactoring/ChangeSignatureTest.java +++ b/testSource/com/intellij/refactoring/ChangeSignatureTest.java @@ -213,7 +213,7 @@ public class ChangeSignatureTest extends CodeInsightTestCase { PsiType newType = newReturnType != null ? factory.createTypeFromText(newReturnType, method) : method.getReturnType(); new ChangeSignatureProcessor(getProject(), method, generateDelegate, newVisibility, newName != null ? newName : method.getName(), - newType, genParams.genParams(method), genExceptions.genExceptions(method), null).testRun(); + newType, genParams.genParams(method), genExceptions.genExceptions(method)).testRun(); checkResultByFile(filePath + ".after"); } diff --git a/testSource/com/intellij/refactoring/InheritanceToDelegationTest.java b/testSource/com/intellij/refactoring/InheritanceToDelegationTest.java index 9e8310f3a0e6..2e0e713062d8 100644 --- a/testSource/com/intellij/refactoring/InheritanceToDelegationTest.java +++ b/testSource/com/intellij/refactoring/InheritanceToDelegationTest.java @@ -126,8 +126,7 @@ public class InheritanceToDelegationTest extends MultiFileTestCase { new InheritanceToDelegationProcessor( myProject, aClass, baseClass, fieldName, innerClassName, delegatedInterfaces, delegatedMethods, delegateOtherMembers, - generateGetter, false, null - ).testRun(); + generateGetter).testRun(); FileDocumentManager.getInstance().saveAllDocuments(); } }; @@ -143,7 +142,6 @@ public class InheritanceToDelegationTest extends MultiFileTestCase { assertNotNull("Class " + className + " not found", aClass); PsiClass baseClass = myPsiManager.findClass(baseClassName); assertNotNull("Base class " + baseClassName + " not found", baseClass); - final PsiMethod[] methods = baseClass.getMethods(); final PsiMethod[] delegatedMethods; final List methodsList = new ArrayList(); for (int i = 0; i < methodNames.length; i++) { @@ -154,7 +152,7 @@ public class InheritanceToDelegationTest extends MultiFileTestCase { methodsList.add(method); } } - delegatedMethods = (PsiMethod[])methodsList.toArray(new PsiMethod[methodsList.size()]); + delegatedMethods = methodsList.toArray(new PsiMethod[methodsList.size()]); final PsiClass[] delegatedInterfaces = new PsiClass[delegatedInterfaceNames.length]; for (int i = 0; i < delegatedInterfaceNames.length; i++) { @@ -166,8 +164,7 @@ public class InheritanceToDelegationTest extends MultiFileTestCase { new InheritanceToDelegationProcessor( myProject, aClass, baseClass, fieldName, innerClassName, delegatedInterfaces, delegatedMethods, delegateOtherMembers, - generateGetter, false, null - ).testRun(); + generateGetter).testRun(); FileDocumentManager.getInstance().saveAllDocuments(); } }; diff --git a/testSource/com/intellij/refactoring/inline/InlineMethodTest.java b/testSource/com/intellij/refactoring/inline/InlineMethodTest.java index 4a11b1b54976..2c4335db655d 100644 --- a/testSource/com/intellij/refactoring/inline/InlineMethodTest.java +++ b/testSource/com/intellij/refactoring/inline/InlineMethodTest.java @@ -3,12 +3,10 @@ package com.intellij.refactoring.inline; import com.intellij.codeInsight.CodeInsightTestCase; import com.intellij.codeInsight.TargetElementUtil; +import com.intellij.idea.IdeaTestUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethod; -import com.intellij.refactoring.inline.InlineMethodProcessor; -import com.intellij.refactoring.inline.InlineOptions; import com.intellij.refactoring.MockInlineMethodOptions; -import com.intellij.idea.IdeaTestUtil; import java.util.Calendar; @@ -89,9 +87,9 @@ public class InlineMethodTest extends CodeInsightTestCase { final boolean condition = InlineMethodProcessor.checkBadReturns((PsiMethod) element); assertFalse("Bad returns found", condition); PsiMethod method = (PsiMethod)element; - final InlineMethodProcessor processor = new InlineMethodProcessor(myProject, method, null, myEditor); - InlineOptions dialog = new MockInlineMethodOptions(); - //new InlineMethodDialog(myProject, method, false, processor); - processor.testRun(dialog); + InlineOptions options = new MockInlineMethodOptions(); + final InlineMethodProcessor processor = new InlineMethodProcessor(myProject, method, null, myEditor, options.isInlineThisOnly()); + //new InlineMethodDialog(myProject, method, false, processor); + processor.testRun(); } }