mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
(no message)
This commit is contained in:
@@ -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.
|
||||
|
||||
+2
-20
@@ -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<ParameterInfo> 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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -197,8 +197,7 @@ public class UnusedParametersInspection extends FilteringInspectionTool {
|
||||
psiMethod,
|
||||
false, null, psiMethod.getName(),
|
||||
psiMethod.getReturnType(),
|
||||
parameterInfos,
|
||||
BaseRefactoringProcessor.EMPTY_CALLBACK);
|
||||
parameterInfos);
|
||||
|
||||
csp.run(null);
|
||||
}
|
||||
|
||||
@@ -131,8 +131,7 @@ public class UnusedReturnValue extends DescriptorProviderInspection {
|
||||
psiMethod,
|
||||
false, null, psiMethod.getName(),
|
||||
PsiType.VOID,
|
||||
infos,
|
||||
BaseRefactoringProcessor.EMPTY_CALLBACK);
|
||||
infos);
|
||||
|
||||
csp.run(null);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -102,9 +102,7 @@ public class EncapsulateFieldsHandler implements RefactoringActionHandler {
|
||||
EncapsulateFieldsDialog dialog = new EncapsulateFieldsDialog(
|
||||
project,
|
||||
aClass,
|
||||
preselectedFields,
|
||||
new EncapsulateFieldsProcessor(project)
|
||||
);
|
||||
preselectedFields);
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
@@ -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<String,PsiMethod> myNameToGetter;
|
||||
private HashMap<String,PsiMethod> 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){
|
||||
|
||||
+38
-25
@@ -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<PsiClass> implementedInterfaces = new ArrayList<PsiClass>();
|
||||
final ArrayList<PsiMethod> delegatedMethods = new ArrayList<PsiMethod>();
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-33
@@ -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<PsiClass> implementedInterfaces = new ArrayList<PsiClass>();
|
||||
final ArrayList<PsiMethod> delegatedMethods = new ArrayList<PsiMethod>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-9
@@ -50,8 +50,6 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
|
||||
private final HashMap<PsiMethod,String> myDelegatedMethodsVisibility;
|
||||
private final LinkedHashSet<PsiMethod> myOverridenMethods;
|
||||
|
||||
private boolean myPreviewUsages;
|
||||
|
||||
private final PsiClass myBaseClass;
|
||||
private final Set<Object> 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(
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<TypeCookProcessor> 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<PsiElement> getElements() {
|
||||
return myProcessor.getElements();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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<PsiMethod> methodsList = new ArrayList<PsiMethod>();
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user