From c08c00a43d2b41266008ba650dcfe0f8c0d09d97 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 20 Oct 2011 13:20:03 +0200 Subject: [PATCH] inplace introduce: reinit default type before show dialog on the second key stroke; correct undo chain --- .../IntroduceConstantHandler.java | 11 ++++++----- .../introduceField/IntroduceFieldHandler.java | 15 ++++++++------- .../AbstractJavaInplaceIntroducer.java | 2 +- .../IntroduceParameterHandler.java | 18 ++++++++++-------- .../inplace/AbstractInplaceIntroducer.java | 9 +++++++-- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java index 242cf0c19f4e..78c73c0b537a 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java @@ -93,7 +93,7 @@ public class IntroduceConstantHandler extends BaseExpressionToFieldHandler { protected Settings showRefactoringDialog(Project project, - Editor editor, + final Editor editor, PsiClass parentClass, PsiExpression expr, PsiType type, @@ -150,31 +150,32 @@ public class IntroduceConstantHandler extends BaseExpressionToFieldHandler { String enteredName = null; boolean replaceAllOccurrences = true; - final TypeSelectorManagerImpl typeSelectorManager = new TypeSelectorManagerImpl(project, type, containingMethod, expr, occurrences); if (editor != null && editor.getSettings().isVariableInplaceRenameEnabled() && (expr == null || expr.isPhysical())) { final AbstractInplaceIntroducer activeIntroducer = AbstractInplaceIntroducer.getActiveIntroducer(editor); if (activeIntroducer == null) { myInplaceIntroduceConstantPopup = - new InplaceIntroduceConstantPopup(project, editor, parentClass, expr, localVariable, occurrences, typeSelectorManager, + new InplaceIntroduceConstantPopup(project, editor, parentClass, expr, localVariable, occurrences, + new TypeSelectorManagerImpl(project, type, containingMethod, expr, occurrences), anchorElement, anchorElementIfAll, expr != null ? createOccurrenceManager(expr, parentClass) : null); if (myInplaceIntroduceConstantPopup.startInplaceIntroduceTemplate() ){ return null; } } else { - AbstractInplaceIntroducer.stopIntroduce(editor); + activeIntroducer.stopIntroduce(editor); expr = (PsiExpression)activeIntroducer.getExpr(); localVariable = (PsiLocalVariable)activeIntroducer.getLocalVariable(); occurrences = (PsiExpression[])activeIntroducer.getOccurrences(); enteredName = activeIntroducer.getInputName(); replaceAllOccurrences = activeIntroducer.isReplaceAllOccurrences(); + type = ((InplaceIntroduceConstantPopup)activeIntroducer).getType(); } } final IntroduceConstantDialog dialog = new IntroduceConstantDialog(project, parentClass, expr, localVariable, localVariable != null, occurrences, getParentClass(), - typeSelectorManager, enteredName); + new TypeSelectorManagerImpl(project, type, containingMethod, expr, occurrences), enteredName); dialog.setReplaceAllOccurrences(replaceAllOccurrences); dialog.show(); if (!dialog.isOK()) { diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java index fa7fb3b81aa2..77284b936479 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java @@ -25,6 +25,7 @@ import com.intellij.psi.util.PsiUtil; import com.intellij.refactoring.HelpID; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer; +import com.intellij.refactoring.introduceParameter.AbstractJavaInplaceIntroducer; import com.intellij.refactoring.ui.TypeSelectorManagerImpl; import com.intellij.refactoring.util.CommonRefactoringUtil; import com.intellij.refactoring.util.occurrences.*; @@ -102,7 +103,6 @@ public class IntroduceFieldHandler extends BaseExpressionToFieldHandler { final boolean currentMethodConstructor = containingMethod != null && containingMethod.isConstructor(); final boolean allowInitInMethod = (!currentMethodConstructor || !isInSuperOrThis) && (anchorElement instanceof PsiLocalVariable || anchorElement instanceof PsiStatement); final boolean allowInitInMethodIfAll = (!currentMethodConstructor || !isInSuperOrThis) && anchorElementIfAll instanceof PsiStatement; - final TypeSelectorManagerImpl typeSelectorManager = new TypeSelectorManagerImpl(project, type, containingMethod, expr, occurrences); String enteredName = null; boolean replaceAll = false; @@ -110,20 +110,21 @@ public class IntroduceFieldHandler extends BaseExpressionToFieldHandler { final AbstractInplaceIntroducer activeIntroducer = AbstractInplaceIntroducer.getActiveIntroducer(editor); if (activeIntroducer == null) { myInplaceIntroduceFieldPopup = - new InplaceIntroduceFieldPopup(localVariable, parentClass, declareStatic, currentMethodConstructor, occurrences, expr, typeSelectorManager, editor, - allowInitInMethod, allowInitInMethodIfAll, anchorElement, anchorElementIfAll, expr != null ? createOccurrenceManager( - expr, parentClass) : null, - project); + new InplaceIntroduceFieldPopup(localVariable, parentClass, declareStatic, currentMethodConstructor, occurrences, expr, + new TypeSelectorManagerImpl(project, type, containingMethod, expr, occurrences), editor, + allowInitInMethod, allowInitInMethodIfAll, anchorElement, anchorElementIfAll, + expr != null ? createOccurrenceManager(expr, parentClass) : null,project); if (myInplaceIntroduceFieldPopup.startInplaceIntroduceTemplate()) { return null; } } else { - AbstractInplaceIntroducer.stopIntroduce(editor); + activeIntroducer.stopIntroduce(editor); expr = (PsiExpression)activeIntroducer.getExpr(); localVariable = (PsiLocalVariable)activeIntroducer.getLocalVariable(); occurrences = (PsiExpression[])activeIntroducer.getOccurrences(); enteredName = activeIntroducer.getInputName(); replaceAll = activeIntroducer.isReplaceAllOccurrences(); + type = ((AbstractJavaInplaceIntroducer)activeIntroducer).getType(); IntroduceFieldDialog.ourLastInitializerPlace = ((InplaceIntroduceFieldPopup)activeIntroducer).getInitializerPlace(); } } @@ -133,7 +134,7 @@ public class IntroduceFieldHandler extends BaseExpressionToFieldHandler { currentMethodConstructor, localVariable != null, declareStatic, occurrences, allowInitInMethod, allowInitInMethodIfAll, - typeSelectorManager, + new TypeSelectorManagerImpl(project, type, containingMethod, expr, occurrences), enteredName ); dialog.setReplaceAllOccurrences(replaceAll); diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java index ec59f37cf5b4..6265d9309062 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java @@ -96,7 +96,7 @@ public abstract class AbstractJavaInplaceIntroducer extends AbstractInplaceIntro TypeSelectorManagerImpl.typeSelected(psiVariable.getType(), getType());//myDefaultType.getType()); } - protected PsiType getType() { + public PsiType getType() { return myTypeSelectorManager.getDefaultType(); } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java index 53d170a73c6f..a29f7d3eba25 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java @@ -400,11 +400,7 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R final String propName = myLocalVar != null ? JavaCodeStyleManager .getInstance(myProject).variableNameToPropertyName(myLocalVar.getName(), VariableKind.LOCAL_VARIABLE) : null; - final PsiType initializerType = IntroduceParameterProcessor.getInitializerType(null, myExpr, myLocalVar); - - TypeSelectorManagerImpl typeSelectorManager = myExpr != null - ? new TypeSelectorManagerImpl(myProject, initializerType, myExpr, occurences) - : new TypeSelectorManagerImpl(myProject, initializerType, occurences); + PsiType initializerType = IntroduceParameterProcessor.getInitializerType(null, myExpr, myLocalVar); boolean isInplaceAvailableOnDataContext = myEditor != null && myEditor.getSettings().isVariableInplaceRenameEnabled(); @@ -421,7 +417,7 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R myInplaceIntroduceParameterPopup = new InplaceIntroduceParameterPopup(myProject, myEditor, classMemberRefs, - typeSelectorManager, + createTypeSelectorManager(occurences, initializerType), myExpr, myLocalVar, method, methodToSearchFor, occurences, getParamsToRemove(method, occurences), mustBeFinal); @@ -430,13 +426,14 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R } } else { - AbstractInplaceIntroducer.stopIntroduce(myEditor); + activeIntroducer.stopIntroduce(myEditor); myExpr = (PsiExpression)activeIntroducer.getExpr(); myLocalVar = (PsiLocalVariable)activeIntroducer.getLocalVariable(); occurences = (PsiExpression[])activeIntroducer.getOccurrences(); enteredName = activeIntroducer.getInputName(); replaceAllOccurrences = activeIntroducer.isReplaceAllOccurrences(); delegate = ((InplaceIntroduceParameterPopup)activeIntroducer).isGenerateDelegate(); + initializerType = ((AbstractJavaInplaceIntroducer)activeIntroducer).getType(); } } if (ApplicationManager.getApplication().isUnitTestMode()) { @@ -455,7 +452,7 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R final IntroduceParameterDialog dialog = new IntroduceParameterDialog(myProject, classMemberRefs, occurences, myLocalVar, myExpr, createNameSuggestionGenerator(myExpr, propName, myProject, enteredName), - typeSelectorManager, methodToSearchFor, method, getParamsToRemove(method, occurences), mustBeFinal); + createTypeSelectorManager(occurences, initializerType), methodToSearchFor, method, getParamsToRemove(method, occurences), mustBeFinal); dialog.setReplaceAllOccurrences(replaceAllOccurrences); dialog.setGenerateDelegate(delegate); dialog.show(); @@ -465,6 +462,11 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R } } + private TypeSelectorManagerImpl createTypeSelectorManager(PsiExpression[] occurences, PsiType initializerType) { + return myExpr != null ? new TypeSelectorManagerImpl(myProject, initializerType, myExpr, occurences) + : new TypeSelectorManagerImpl(myProject, initializerType, occurences); + } + private TIntArrayList getParamsToRemove(PsiMethod method, PsiExpression[] occurences) { PsiExpression expressionToRemoveParamFrom = myExpr; if (myExpr == null) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java index 57b95e7cc434..b4dbff208521 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java @@ -531,10 +531,15 @@ public abstract class AbstractInplaceIntroducer