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:
@@ -10,14 +10,12 @@ package com.intellij.refactoring.introduceParameter;
|
||||
|
||||
import com.intellij.openapi.help.HelpManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.IntroduceParameterRefactoring;
|
||||
import com.intellij.refactoring.RefactoringSettings;
|
||||
import com.intellij.refactoring.RefactoringDialog;
|
||||
import com.intellij.refactoring.RefactoringSettings;
|
||||
import com.intellij.refactoring.ui.*;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.NonFocusableCheckBox;
|
||||
@@ -33,14 +31,14 @@ public class IntroduceParameterDialog extends RefactoringDialog {
|
||||
private TypeSelector myTypeSelector;
|
||||
private NameSuggestionsManager myNameSuggestionsManager;
|
||||
|
||||
public static interface Callback {
|
||||
void run(IntroduceParameterDialog dialog);
|
||||
}
|
||||
|
||||
private Project myProject;
|
||||
private List myClassMembersList;
|
||||
private int myOccurenceNumber;
|
||||
private final boolean myIsInvokedOnDeclaration;
|
||||
private final PsiMethod myMethodToSearchFor;
|
||||
private final PsiMethod myMethodToReplaceIn;
|
||||
private PsiExpression myExpression;
|
||||
private PsiLocalVariable myLocalVar;
|
||||
private boolean myIsLocalVariable;
|
||||
private boolean myHasInitializer;
|
||||
|
||||
@@ -57,24 +55,30 @@ public class IntroduceParameterDialog extends RefactoringDialog {
|
||||
|
||||
private ButtonGroup myReplaceFieldsWithGettersButtonGroup = new ButtonGroup();
|
||||
|
||||
private Callback myCallback;
|
||||
private final NameSuggestionsGenerator myNameSuggestionsGenerator;
|
||||
private final TypeSelectorManager myTypeSelectorManager;
|
||||
|
||||
|
||||
IntroduceParameterDialog(Project project, List localVarsList,
|
||||
List parameterList, List classMembersList, int occurenceNumber,
|
||||
boolean isInvokedOnDeclaration, boolean isLocalVariable,
|
||||
boolean hasInitializer, Callback callback, NameSuggestionsGenerator generator,
|
||||
TypeSelectorManager typeSelectorManager) {
|
||||
IntroduceParameterDialog(Project project,
|
||||
List classMembersList,
|
||||
int occurenceNumber,
|
||||
PsiLocalVariable onLocalVariable,
|
||||
PsiExpression onExpression,
|
||||
NameSuggestionsGenerator generator,
|
||||
TypeSelectorManager typeSelectorManager,
|
||||
PsiMethod methodToSearchFor,
|
||||
PsiMethod methodToReplaceIn) {
|
||||
super(project, true);
|
||||
myProject = project;
|
||||
myClassMembersList = classMembersList;
|
||||
myOccurenceNumber = occurenceNumber;
|
||||
myIsInvokedOnDeclaration = isInvokedOnDeclaration;
|
||||
myIsLocalVariable = isLocalVariable;
|
||||
myHasInitializer = hasInitializer;
|
||||
myCallback = callback;
|
||||
myExpression = onExpression;
|
||||
myLocalVar = onLocalVariable;
|
||||
myMethodToReplaceIn = methodToReplaceIn;
|
||||
myIsInvokedOnDeclaration = onExpression != null;
|
||||
myMethodToSearchFor = methodToSearchFor;
|
||||
myIsLocalVariable = onLocalVariable != null;
|
||||
myHasInitializer = onLocalVariable != null && onLocalVariable.getInitializer() != null;
|
||||
myNameSuggestionsGenerator = generator;
|
||||
myTypeSelectorManager = typeSelectorManager;
|
||||
|
||||
@@ -116,8 +120,7 @@ public class IntroduceParameterDialog extends RefactoringDialog {
|
||||
if(myCbUseInitializer != null) {
|
||||
return myCbUseInitializer.isSelected();
|
||||
}
|
||||
else
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getParameterName() {
|
||||
@@ -341,8 +344,6 @@ public class IntroduceParameterDialog extends RefactoringDialog {
|
||||
}
|
||||
|
||||
protected void doAction() {
|
||||
if (!isOKActionEnabled()) return;
|
||||
|
||||
final RefactoringSettings settings = RefactoringSettings.getInstance();
|
||||
settings.INTRODUCE_PARAMETER_REPLACE_FIELDS_WITH_GETTERS =
|
||||
getReplaceFieldsWithGetters();
|
||||
@@ -353,7 +354,24 @@ public class IntroduceParameterDialog extends RefactoringDialog {
|
||||
}
|
||||
|
||||
myNameSuggestionsManager.nameSelected();
|
||||
myCallback.run(this);
|
||||
|
||||
boolean isDeleteLocalVariable = false;
|
||||
|
||||
PsiExpression parameterInitializer = myExpression;
|
||||
if (myLocalVar != null) {
|
||||
if (isUseInitializer()) {
|
||||
parameterInitializer = myLocalVar.getInitializer(); }
|
||||
isDeleteLocalVariable = isDeleteLocalVariable();
|
||||
}
|
||||
|
||||
final IntroduceParameterProcessor processor = new IntroduceParameterProcessor(
|
||||
myProject, myMethodToReplaceIn, myMethodToSearchFor,
|
||||
parameterInitializer, myExpression,
|
||||
myLocalVar, isDeleteLocalVariable,
|
||||
getParameterName(), isReplaceAllOccurences(),
|
||||
getReplaceFieldsWithGetters(), isDeclareFinal(),
|
||||
getSelectedType());
|
||||
invokeRefactoring(processor);
|
||||
myParameterNameField.requestFocusInWindow();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,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.openapi.util.Pair;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
@@ -27,9 +26,9 @@ import com.intellij.psi.codeStyle.SuggestedNameInfo;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.IntroduceHandlerBase;
|
||||
import com.intellij.refactoring.IntroduceParameterRefactoring;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.IntroduceHandlerBase;
|
||||
import com.intellij.refactoring.introduceField.ElementToWorkOn;
|
||||
import com.intellij.refactoring.ui.NameSuggestionsGenerator;
|
||||
import com.intellij.refactoring.ui.TypeSelectorManager;
|
||||
@@ -43,7 +42,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class IntroduceParameterHandler extends IntroduceHandlerBase implements RefactoringActionHandler, IntroduceParameterDialog.Callback {
|
||||
public class IntroduceParameterHandler extends IntroduceHandlerBase implements RefactoringActionHandler {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.introduceParameter.IntroduceParameterHandler");
|
||||
private static final String REFACTORING_NAME = "Introduce Parameter";
|
||||
private PsiExpression myParameterInitializer;
|
||||
@@ -168,7 +167,6 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R
|
||||
Util.analyzeExpression(expr, localVars, classMemberRefs, params);
|
||||
}
|
||||
|
||||
boolean previewUsages = false;
|
||||
String parameterName = "anObject";
|
||||
boolean replaceAllOccurences = true;
|
||||
boolean isDeleteLocalVariable = true;
|
||||
@@ -192,33 +190,23 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R
|
||||
new TypeSelectorManagerImpl(project, initializerType, expr, occurences) :
|
||||
new TypeSelectorManagerImpl(project, initializerType, occurences));
|
||||
|
||||
final IntroduceParameterDialog dialog =
|
||||
new IntroduceParameterDialog(
|
||||
myProject, localVars, params, classMemberRefs,
|
||||
occurences.length,
|
||||
expr == null, myLocalVar != null,
|
||||
(myLocalVar != null) && (myLocalVar.getInitializer() != null),
|
||||
this,
|
||||
new NameSuggestionsGenerator() {
|
||||
public SuggestedNameInfo getSuggestedNameInfo(PsiType type) {
|
||||
return CodeStyleManager.getInstance(myProject).suggestVariableName(VariableKind.PARAMETER, propName, expr, initializerType);
|
||||
}
|
||||
new IntroduceParameterDialog(
|
||||
myProject, classMemberRefs,
|
||||
occurences.length,
|
||||
myLocalVar, expr,
|
||||
new NameSuggestionsGenerator() {
|
||||
public SuggestedNameInfo getSuggestedNameInfo(PsiType type) {
|
||||
return CodeStyleManager.getInstance(myProject).suggestVariableName(VariableKind.PARAMETER, propName, expr, initializerType);
|
||||
}
|
||||
|
||||
public Pair<LookupItemPreferencePolicy, Set<LookupItem>> completeVariableName(String prefix,
|
||||
PsiType type) {
|
||||
LinkedHashSet<LookupItem> set = new LinkedHashSet<LookupItem>();
|
||||
LookupItemPreferencePolicy policy = CompletionUtil.completeVariableName(myProject, set, prefix, type, VariableKind.PARAMETER);
|
||||
return new Pair<LookupItemPreferencePolicy, Set<LookupItem>> (policy, set);
|
||||
}
|
||||
},
|
||||
typeSelectorManager);
|
||||
dialog.show();
|
||||
|
||||
if (!dialog.isOK()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
public Pair<LookupItemPreferencePolicy, Set<LookupItem>> completeVariableName(String prefix,
|
||||
PsiType type) {
|
||||
LinkedHashSet<LookupItem> set = new LinkedHashSet<LookupItem>();
|
||||
LookupItemPreferencePolicy policy = CompletionUtil.completeVariableName(myProject, set, prefix, type, VariableKind.PARAMETER);
|
||||
return new Pair<LookupItemPreferencePolicy, Set<LookupItem>> (policy, set);
|
||||
}
|
||||
},
|
||||
typeSelectorManager, myMethodToSearchFor, myMethod).show();
|
||||
}
|
||||
|
||||
new IntroduceParameterProcessor(
|
||||
@@ -226,7 +214,7 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R
|
||||
myParameterInitializer, myExpressionToSearchFor,
|
||||
myLocalVar, isDeleteLocalVariable,
|
||||
parameterName, replaceAllOccurences,
|
||||
IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, null, null).run(null);
|
||||
IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, null).run(null);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -236,33 +224,6 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public void run(final IntroduceParameterDialog dialog) {
|
||||
boolean isDeleteLocalVariable = false;
|
||||
|
||||
if (myLocalVar != null) {
|
||||
if (dialog.isUseInitializer()) {
|
||||
PsiExpression varInitializer = myLocalVar.getInitializer();
|
||||
if (varInitializer != null) {
|
||||
myParameterInitializer = varInitializer;
|
||||
}
|
||||
}
|
||||
isDeleteLocalVariable = dialog.isDeleteLocalVariable();
|
||||
}
|
||||
|
||||
new IntroduceParameterProcessor(
|
||||
myProject, myMethod, myMethodToSearchFor,
|
||||
myParameterInitializer, myExpressionToSearchFor,
|
||||
myLocalVar, isDeleteLocalVariable,
|
||||
dialog.getParameterName(), dialog.isReplaceAllOccurences(),
|
||||
dialog.getReplaceFieldsWithGetters(), dialog.isDeclareFinal(),
|
||||
dialog.getSelectedType(), new Runnable() {
|
||||
public void run() {
|
||||
dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
|
||||
}
|
||||
}).run(null);
|
||||
}
|
||||
|
||||
|
||||
private static List<PsiMethod> getEnclosingMethods(PsiMethod nearest) {
|
||||
List<PsiMethod> enclosingMethods = new ArrayList<PsiMethod>();
|
||||
enclosingMethods.add(nearest);
|
||||
|
||||
+12
-13
@@ -66,19 +66,18 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor {
|
||||
* if expressionToSearch is null, search for localVariable
|
||||
*/
|
||||
public IntroduceParameterProcessor(Project project,
|
||||
PsiMethod methodToReplaceIn,
|
||||
PsiMethod methodToSearchFor,
|
||||
PsiExpression parameterInitializer,
|
||||
PsiExpression expressionToSearch,
|
||||
PsiLocalVariable localVariable,
|
||||
boolean removeLocalVariable,
|
||||
String parameterName,
|
||||
boolean replaceAllOccurences,
|
||||
int replaceFieldsWithGetters,
|
||||
boolean declareFinal,
|
||||
PsiType forcedType,
|
||||
Runnable prepareSuccessfulCallback) {
|
||||
super(project, prepareSuccessfulCallback);
|
||||
PsiMethod methodToReplaceIn,
|
||||
PsiMethod methodToSearchFor,
|
||||
PsiExpression parameterInitializer,
|
||||
PsiExpression expressionToSearch,
|
||||
PsiLocalVariable localVariable,
|
||||
boolean removeLocalVariable,
|
||||
String parameterName,
|
||||
boolean replaceAllOccurences,
|
||||
int replaceFieldsWithGetters,
|
||||
boolean declareFinal,
|
||||
PsiType forcedType) {
|
||||
super(project);
|
||||
|
||||
myMethodToReplaceIn = methodToReplaceIn;
|
||||
myMethodToSearchFor = methodToSearchFor;
|
||||
|
||||
@@ -40,10 +40,9 @@ public class MakeMethodStaticProcessor extends BaseRefactoringProcessor {
|
||||
private Settings mySettings;
|
||||
|
||||
public MakeMethodStaticProcessor(Project project,
|
||||
PsiMethod method,
|
||||
Settings settings,
|
||||
Runnable prepareSuccessfulCallback) {
|
||||
super(project, prepareSuccessfulCallback);
|
||||
PsiMethod method,
|
||||
Settings settings) {
|
||||
super(project);
|
||||
myMethod = method;
|
||||
mySettings = settings;
|
||||
myMethodClass = method.getContainingClass();
|
||||
|
||||
@@ -29,8 +29,7 @@ public class IntroduceParameterRefactoringImpl extends RefactoringImpl<Introduce
|
||||
super(
|
||||
new IntroduceParameterProcessor(project, methodToReplaceIn, methodToSearchFor,
|
||||
parameterInitializer, expressionToSearch, localVariable, removeLocalVariable, parameterName, replaceAllOccurences,
|
||||
REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, declareFinal, null,
|
||||
BaseRefactoringProcessor.EMPTY_CALLBACK));
|
||||
REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, declareFinal, null));
|
||||
}
|
||||
|
||||
IntroduceParameterRefactoringImpl(Project project,
|
||||
|
||||
@@ -28,8 +28,7 @@ public class MakeMethodStaticRefactoringImpl extends RefactoringImpl<MakeMethodS
|
||||
PsiField[] fields,
|
||||
String[] names) {
|
||||
super(new MakeMethodStaticProcessor(project, method,
|
||||
new Settings(replaceUsages, classParameterName, fields, names),
|
||||
BaseRefactoringProcessor.EMPTY_CALLBACK));
|
||||
new Settings(replaceUsages, classParameterName, fields, names)));
|
||||
}
|
||||
|
||||
public PsiMethod getMethod() {
|
||||
|
||||
@@ -221,7 +221,7 @@ public class IntroduceParameterTest extends CodeInsightTestCase {
|
||||
new IntroduceParameterProcessor(
|
||||
myProject, method, methodToSearchFor, expr, expr, null, true, parameterName, replaceAllOccurences,
|
||||
replaceFieldsWithGetters,
|
||||
declareFinal, null, null).testRun();
|
||||
declareFinal, null).testRun();
|
||||
|
||||
myEditor.getSelectionModel().removeSelection();
|
||||
return true;
|
||||
@@ -249,8 +249,7 @@ public class IntroduceParameterTest extends CodeInsightTestCase {
|
||||
parameterInitializer, null, localVariable, removeLocalVariable,
|
||||
localVariable.getName(), replaceAllOccurences,
|
||||
IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE,
|
||||
declareFinal, null, null
|
||||
).testRun();
|
||||
declareFinal, null).testRun();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public class MakeMethodStaticTest extends CodeInsightTestCase {
|
||||
new MakeMethodStaticProcessor(
|
||||
myProject,
|
||||
method,
|
||||
new Settings(true, addClassParameter ? "anObject" : null, null), null).testRun();
|
||||
new Settings(true, addClassParameter ? "anObject" : null, null)).testRun();
|
||||
}
|
||||
|
||||
private void performWithFields() {
|
||||
@@ -168,7 +168,6 @@ public class MakeMethodStaticTest extends CodeInsightTestCase {
|
||||
method,
|
||||
new Settings(true, addClassParameter ? "anObject" : null,
|
||||
(ParameterTablePanel.VariableData[])parametersForFields.toArray(
|
||||
new ParameterTablePanel.VariableData[parametersForFields.size()])),
|
||||
null).testRun();
|
||||
new ParameterTablePanel.VariableData[parametersForFields.size()]))).testRun();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user