mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
inplace introduce: reinit default type before show dialog on the second key stroke; correct undo chain
This commit is contained in:
+6
-5
@@ -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()) {
|
||||
|
||||
+8
-7
@@ -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);
|
||||
|
||||
+1
-1
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
+10
-8
@@ -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) {
|
||||
|
||||
+7
-2
@@ -531,10 +531,15 @@ public abstract class AbstractInplaceIntroducer<V extends PsiNameIdentifierOwner
|
||||
return myLocalVariable;
|
||||
}
|
||||
|
||||
public static void stopIntroduce(Editor editor) {
|
||||
public void stopIntroduce(Editor editor) {
|
||||
final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
|
||||
if (templateState != null) {
|
||||
templateState.gotoEnd(true);
|
||||
final Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
templateState.gotoEnd(true);
|
||||
}
|
||||
};
|
||||
CommandProcessor.getInstance().executeCommand(myProject, runnable, getCommandName(), getCommandName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user