diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/BaseExpressionToFieldHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceField/BaseExpressionToFieldHandler.java index 0f35875503a0..01e6ea397422 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/BaseExpressionToFieldHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/BaseExpressionToFieldHandler.java @@ -206,7 +206,7 @@ public abstract class BaseExpressionToFieldHandler extends IntroduceHandlerBase final Runnable runnable = - new ConvertToFieldRunnable(selectedExpr, settings, type, occurrences, occurenceManager, + new ConvertToFieldRunnable(settings.getSelectedExpr(), settings, type, settings.getOccurrences(), occurenceManager, anchorStatementIfAll, tempAnchorElement, editor, myParentClass); @@ -482,6 +482,8 @@ public abstract class BaseExpressionToFieldHandler extends IntroduceHandlerBase private final TargetDestination myTargetClass; private final boolean myAnnotateAsNonNls; private final boolean myIntroduceEnumConstant; + private PsiExpression mySelectedExpr; + private PsiExpression[] myOccurrences; public PsiLocalVariable getLocalVariable() { return myLocalVariable; @@ -534,7 +536,10 @@ public abstract class BaseExpressionToFieldHandler extends IntroduceHandlerBase return myIntroduceEnumConstant; } - public Settings(String fieldName, boolean replaceAll, + public Settings(String fieldName, + PsiExpression selectedExpr, + PsiExpression[] occurrences, + boolean replaceAll, boolean declareStatic, boolean declareFinal, InitializationPlace initializerPlace, String visibility, PsiLocalVariable localVariableToRemove, PsiType forcedType, boolean deleteLocalVariable, @@ -543,6 +548,8 @@ public abstract class BaseExpressionToFieldHandler extends IntroduceHandlerBase final boolean introduceEnumConstant) { myFieldName = fieldName; + myOccurrences = occurrences; + mySelectedExpr = selectedExpr; myReplaceAll = replaceAll; myDeclareStatic = declareStatic; myDeclareFinal = declareFinal; @@ -556,7 +563,10 @@ public abstract class BaseExpressionToFieldHandler extends IntroduceHandlerBase myIntroduceEnumConstant = introduceEnumConstant; } - public Settings(String fieldName, boolean replaceAll, + public Settings(String fieldName, + PsiExpression selectedExpression, + PsiExpression[] occurrences, + boolean replaceAll, boolean declareStatic, boolean declareFinal, InitializationPlace initializerPlace, String visibility, PsiLocalVariable localVariableToRemove, PsiType forcedType, boolean deleteLocalVariable, @@ -564,9 +574,20 @@ public abstract class BaseExpressionToFieldHandler extends IntroduceHandlerBase final boolean annotateAsNonNls, final boolean introduceEnumConstant) { - this(fieldName, replaceAll, declareStatic, declareFinal, initializerPlace, visibility, localVariableToRemove, forcedType, deleteLocalVariable, new TargetDestination(targetClass), annotateAsNonNls, introduceEnumConstant); + this(fieldName, selectedExpression, occurrences, replaceAll, declareStatic, declareFinal, initializerPlace, visibility, localVariableToRemove, forcedType, deleteLocalVariable, new TargetDestination(targetClass), annotateAsNonNls, introduceEnumConstant); } + public PsiExpression getSelectedExpr() { + return mySelectedExpr; + } + + public PsiExpression[] getOccurrences() { + return myOccurrences; + } + + public void setOccurrences(PsiExpression[] occurrences) { + myOccurrences = occurrences; + } } public static class TargetDestination { diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java index b784a08c80d3..971815541463 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java @@ -285,6 +285,8 @@ public class InplaceIntroduceConstantPopup extends AbstractJavaInplaceIntroducer protected void performIntroduce() { final BaseExpressionToFieldHandler.Settings settings = new BaseExpressionToFieldHandler.Settings(getInputName(), + getExpr(), + getOccurrences(), isReplaceAllOccurrences(), true, true, BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION, diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java index 7f8af6011e3e..cb129f4aea8d 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java @@ -62,6 +62,7 @@ public class InplaceIntroduceFieldPopup extends AbstractJavaInplaceIntroducer { private JPanel myWholePanel; static BaseExpressionToFieldHandler.InitializationPlace ourLastInitializerPlace; + private JLabel myLabel = new JLabel("###################"); public InplaceIntroduceFieldPopup(PsiLocalVariable localVariable, PsiClass parentClass, @@ -98,28 +99,22 @@ public class InplaceIntroduceFieldPopup extends AbstractJavaInplaceIntroducer { new IntroduceFieldPopupPanel(parentClass, initializerExpression, localVariable, currentMethodConstructor, localVariable != null, aStatic, myOccurrences, allowInitInMethod, allowInitInMethodIfAll, typeSelectorManager); - myWholePanel = new JPanel(new GridBagLayout()); + myWholePanel = new JPanel(new BorderLayout()); myWholePanel.setBorder(null); + myLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 0)); + myLabel.setFont(myLabel.getFont().deriveFont(Font.BOLD)); + myWholePanel.add(myLabel, BorderLayout.NORTH); - GridBagConstraints gc = - new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, - new Insets(0,0,0,0), 0, 0); + final JComponent centerPanel = myIntroduceFieldPanel.createCenterPanel(); + myWholePanel.add(centerPanel, BorderLayout.WEST); - gc.gridy++; - gc.insets.top = 5; - - myWholePanel.add(myIntroduceFieldPanel.createCenterPanel(), gc); - JComponent typeChooser = typeComponent(); - if (typeChooser != null) { - gc.gridy++ ; - gc.insets.left = 5; - gc.insets.right = 5; - myWholePanel.add(typeChooser, gc); - } myIntroduceFieldPanel.initializeControls(initializerExpression, ourLastInitializerPlace); + } - + @Override + protected void updateTitle(PsiVariable variable) { + myLabel.setText(variable.getText()); } protected PsiField createFieldToStartTemplateOn(final String[] names, @@ -190,39 +185,6 @@ public class InplaceIntroduceFieldPopup extends AbstractJavaInplaceIntroducer { @Override protected JComponent getComponent() { - final VisibilityListener visibilityListener = new VisibilityListener(myEditor) { - @Override - protected String getVisibility() { - return myIntroduceFieldPanel.getFieldVisibility(); - } - }; - myIntroduceFieldPanel.addVisibilityListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - new WriteCommandAction(myProject, getCommandName(), getCommandName()) { - @Override - protected void run(Result result) throws Throwable { - PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument()); - visibilityListener.perform(getVariable()); - updateTitle(getVariable()); - } - }.execute(); - } - }); - final FinalListener finalListener = new FinalListener(myEditor); - myIntroduceFieldPanel.addFinalListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - new WriteCommandAction(myProject, getCommandName(), getCommandName()){ - @Override - protected void run(Result result) throws Throwable { - PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument()); - finalListener.perform(myIntroduceFieldPanel.isDeclareFinal(), getVariable()); - updateTitle(getVariable()); - } - }.execute(); - } - }); myIntroduceFieldPanel.addOccurrenceListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { @@ -266,7 +228,10 @@ public class InplaceIntroduceFieldPopup extends AbstractJavaInplaceIntroducer { protected void performIntroduce() { ourLastInitializerPlace = myIntroduceFieldPanel.getInitializerPlace(); final BaseExpressionToFieldHandler.Settings settings = - new BaseExpressionToFieldHandler.Settings(getInputName(), myIntroduceFieldPanel.isReplaceAllOccurrences(), myStatic, + new BaseExpressionToFieldHandler.Settings(getInputName(), + getExpr(), + getOccurrences(), + myIntroduceFieldPanel.isReplaceAllOccurrences(), myStatic, myIntroduceFieldPanel.isDeclareFinal(), myIntroduceFieldPanel.getInitializerPlace(), myIntroduceFieldPanel.getFieldVisibility(), (PsiLocalVariable)getLocalVariable(), 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 9944e486019d..d34e78173954 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java @@ -30,6 +30,7 @@ import com.intellij.psi.util.PsiTreeUtil; 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.ui.TypeSelectorManagerImpl; import com.intellij.refactoring.util.CommonRefactoringUtil; import com.intellij.refactoring.util.RefactoringUtil; @@ -146,10 +147,18 @@ public class IntroduceConstantHandler extends BaseExpressionToFieldHandler { final TypeSelectorManagerImpl typeSelectorManager = new TypeSelectorManagerImpl(project, type, containingMethod, expr, occurences); if (editor != null && editor.getSettings().isVariableInplaceRenameEnabled() && (expr == null || expr.isPhysical())) { - if (new InplaceIntroduceConstantPopup(project, editor, parentClass, expr, localVariable, occurences, typeSelectorManager, - anchorElement, anchorElementIfAll, - expr != null ? createOccurenceManager(expr, parentClass) : null).startInplaceIntroduceTemplate() ){ - return null; + final AbstractInplaceIntroducer activeIntroducer = AbstractInplaceIntroducer.getActiveIntroducer(editor); + if (activeIntroducer == null) { + if (new InplaceIntroduceConstantPopup(project, editor, parentClass, expr, localVariable, occurences, typeSelectorManager, + anchorElement, anchorElementIfAll, + expr != null ? createOccurenceManager(expr, parentClass) : null).startInplaceIntroduceTemplate() ){ + return null; + } + } else { + AbstractInplaceIntroducer.stopIntroduce(editor); + expr = (PsiExpression)activeIntroducer.getExpr(); + localVariable = (PsiLocalVariable)activeIntroducer.getLocalVariable(); + occurences = (PsiExpression[])activeIntroducer.getOccurrences(); } } @@ -164,10 +173,11 @@ public class IntroduceConstantHandler extends BaseExpressionToFieldHandler { } return null; } - return new Settings(dialog.getEnteredName(), dialog.isReplaceAllOccurrences(), true, true, - BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION, dialog.getFieldVisibility(), localVariable, - dialog.getSelectedType(), dialog.isDeleteVariable(), dialog.getDestinationClass(), dialog.isAnnotateAsNonNls(), - dialog.introduceEnumConstant()); + return new Settings(dialog.getEnteredName(), expr, occurences, dialog.isReplaceAllOccurrences(), true, true, + InitializationPlace.IN_FIELD_DECLARATION, dialog.getFieldVisibility(), localVariable, + dialog.getSelectedType(), dialog.isDeleteVariable(), dialog.getDestinationClass(), + dialog.isAnnotateAsNonNls(), + dialog.introduceEnumConstant()); } private static void highlightError(Project project, Editor editor, PsiElement errorElement) { diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldCentralPanel.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldCentralPanel.java index 8f66388444a7..da1f74b69f53 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldCentralPanel.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldCentralPanel.java @@ -93,7 +93,6 @@ public abstract class IntroduceFieldCentralPanel { public abstract void setVisibility(String visibility); public abstract String getFieldVisibility(); - public abstract void addVisibilityListener(ChangeListener changeListener); protected void initializeControls(PsiExpression initializerExpression, BaseExpressionToFieldHandler.InitializationPlace ourLastInitializerPlace) { @@ -152,7 +151,7 @@ public abstract class IntroduceFieldCentralPanel { return true; } - private JPanel appendCheckboxes(ItemListener itemListener) { + protected JPanel appendCheckboxes(ItemListener itemListener) { GridBagConstraints gbConstraints = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1,1,0,0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0,0,0,0), 0,0); JPanel panel = new JPanel(new GridBagLayout()); myCbFinal = new StateRestoringCheckBox(); @@ -161,18 +160,7 @@ public abstract class IntroduceFieldCentralPanel { myCbFinal.addItemListener(itemListener); gbConstraints.gridy++; panel.add(myCbFinal, gbConstraints); - - if (myOccurrencesCount > 1) { - myCbReplaceAll = new NonFocusableCheckBox(); - myCbReplaceAll.setText(RefactoringBundle.message("replace.all.occurrences.of.expression.0.occurrences", myOccurrencesCount)); - gbConstraints.gridy++; - panel.add(myCbReplaceAll, gbConstraints); - myCbReplaceAll.addItemListener(itemListener); - if (myIsInvokedOnDeclaration) { - myCbReplaceAll.setEnabled(false); - myCbReplaceAll.setSelected(true); - } - } + appendOccurrences(itemListener, gbConstraints, panel); if (myLocalVariable != null) { gbConstraints.gridy++; @@ -199,6 +187,20 @@ public abstract class IntroduceFieldCentralPanel { return panel; } + public void appendOccurrences(ItemListener itemListener, GridBagConstraints gbConstraints, JPanel panel) { + if (myOccurrencesCount > 1) { + myCbReplaceAll = new NonFocusableCheckBox(); + myCbReplaceAll.setText(RefactoringBundle.message("replace.all.occurrences.of.expression.0.occurrences", myOccurrencesCount)); + gbConstraints.gridy++; + panel.add(myCbReplaceAll, gbConstraints); + myCbReplaceAll.addItemListener(itemListener); + if (myIsInvokedOnDeclaration) { + myCbReplaceAll.setEnabled(false); + myCbReplaceAll.setSelected(true); + } + } + } + private void updateTypeSelector() { if (myCbReplaceAll != null) { myTypeSelectorManager.setAllOccurences(myCbReplaceAll.isSelected()); @@ -215,7 +217,7 @@ public abstract class IntroduceFieldCentralPanel { } } - private void updateCbFinal() { + protected void updateCbFinal() { if (!allowFinal()) { myCbFinal.makeUnselectable(false); } else { @@ -224,7 +226,8 @@ public abstract class IntroduceFieldCentralPanel { } protected boolean allowFinal() { - return !myHasWriteAccess && isReplaceAllOccurrences(); + if (myHasWriteAccess && isReplaceAllOccurrences()) return false; + return true; } public void addOccurrenceListener(ItemListener itemListener) { @@ -255,7 +258,7 @@ public abstract class IntroduceFieldCentralPanel { public void saveFinalState() { - if (myCbFinal.isEnabled()) { + if (myCbFinal != null && myCbFinal.isEnabled()) { ourLastCbFinalState = myCbFinal.isSelected(); } } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldDialogPanel.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldDialogPanel.java index 351c375b7e44..0acb5d6ce1ab 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldDialogPanel.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldDialogPanel.java @@ -25,7 +25,6 @@ import com.intellij.refactoring.ui.TypeSelectorManager; import com.intellij.ui.IdeBorderFactory; import javax.swing.*; -import javax.swing.event.ChangeListener; import java.awt.*; import java.awt.event.ItemListener; @@ -55,10 +54,10 @@ public class IntroduceFieldDialogPanel extends IntroduceFieldCentralPanel { } protected void initializeControls(PsiExpression initializerExpression, BaseExpressionToFieldHandler.InitializationPlace ourLastInitializerPlace) { - super.initializeControls(initializerExpression, ourLastInitializerPlace); initializeInitializerPlace(initializerExpression, ourLastInitializerPlace); String ourLastVisibility = JavaRefactoringSettings.getInstance().INTRODUCE_FIELD_VISIBILITY; myVisibilityPanel.setVisibility(ourLastVisibility); + super.initializeControls(initializerExpression, ourLastInitializerPlace); } protected void initializeInitializerPlace(PsiExpression initializerExpression, @@ -217,10 +216,6 @@ public class IntroduceFieldDialogPanel extends IntroduceFieldCentralPanel { return true; } - public void addVisibilityListener(ChangeListener changeListener) { - myVisibilityPanel.addListener(changeListener); - } - public void setInitializeInFieldDeclaration() { myRbInFieldDeclaration.setSelected(true); } 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 49bd60b1d24d..243a1b1f2b87 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java @@ -24,6 +24,7 @@ import com.intellij.psi.util.PsiTreeUtil; 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.ui.TypeSelectorManagerImpl; import com.intellij.refactoring.util.CommonRefactoringUtil; import com.intellij.refactoring.util.occurences.*; @@ -104,12 +105,20 @@ public class IntroduceFieldHandler extends BaseExpressionToFieldHandler { final TypeSelectorManagerImpl typeSelectorManager = new TypeSelectorManagerImpl(project, type, containingMethod, expr, occurences); if (editor != null && editor.getSettings().isVariableInplaceRenameEnabled() && (expr == null || expr.isPhysical())) { - myInplaceIntroduceFieldPopup = - new InplaceIntroduceFieldPopup(localVariable, parentClass, declareStatic, currentMethodConstructor, occurences, expr, typeSelectorManager, editor, - allowInitInMethod, allowInitInMethodIfAll, anchorElement, anchorElementIfAll, expr != null ? createOccurenceManager(expr, parentClass) : null, - project); - if (myInplaceIntroduceFieldPopup.startInplaceIntroduceTemplate()) { - return null; + final AbstractInplaceIntroducer activeIntroducer = AbstractInplaceIntroducer.getActiveIntroducer(editor); + if (activeIntroducer == null) { + myInplaceIntroduceFieldPopup = + new InplaceIntroduceFieldPopup(localVariable, parentClass, declareStatic, currentMethodConstructor, occurences, expr, typeSelectorManager, editor, + allowInitInMethod, allowInitInMethodIfAll, anchorElement, anchorElementIfAll, expr != null ? createOccurenceManager(expr, parentClass) : null, + project); + if (myInplaceIntroduceFieldPopup.startInplaceIntroduceTemplate()) { + return null; + } + } else { + AbstractInplaceIntroducer.stopIntroduce(editor); + expr = (PsiExpression)activeIntroducer.getExpr(); + localVariable = (PsiLocalVariable)activeIntroducer.getLocalVariable(); + occurences = (PsiExpression[])activeIntroducer.getOccurrences(); } } @@ -134,11 +143,11 @@ public class IntroduceFieldHandler extends BaseExpressionToFieldHandler { } - return new Settings(dialog.getEnteredName(), dialog.isReplaceAllOccurrences(), - declareStatic, dialog.isDeclareFinal(), - dialog.getInitializerPlace(), dialog.getFieldVisibility(), - localVariable, - dialog.getFieldType(), localVariable != null, (TargetDestination)null, false, false); + return new Settings(dialog.getEnteredName(), expr, occurences, dialog.isReplaceAllOccurrences(), + declareStatic, dialog.isDeclareFinal(), + dialog.getInitializerPlace(), dialog.getFieldVisibility(), + localVariable, + dialog.getFieldType(), localVariable != null, (TargetDestination)null, false, false); } public InplaceIntroduceFieldPopup getInplaceIntroduceFieldPopup() { diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java index 8450e6490d51..5bf51d7365fc 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java @@ -25,7 +25,6 @@ import com.intellij.refactoring.ui.TypeSelectorManager; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.event.ChangeListener; import java.awt.*; import java.awt.event.*; @@ -65,28 +64,31 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { final PsiMethod setUpMethod = TestUtil.findSetUpMethod(myParentClass); final boolean setupEnabled = myInitialisersPlaceModel.getIndexOf(BaseExpressionToFieldHandler.InitializationPlace.IN_SETUP_METHOD) > -1; - if (myInitializerExpression != null && PsiTreeUtil.isAncestor(setUpMethod, myInitializerExpression, false) && setupEnabled || - ourLastInitializerPlace == BaseExpressionToFieldHandler.InitializationPlace.IN_SETUP_METHOD && TestUtil.isTestClass(myParentClass) && - setupEnabled) { + if (setupEnabled && (myInitializerExpression != null && PsiTreeUtil.isAncestor(setUpMethod, myInitializerExpression, false) || + TestUtil.isTestClass(myParentClass))) { myInitialisersPlaceModel.setSelectedItem(BaseExpressionToFieldHandler.InitializationPlace.IN_SETUP_METHOD); } - else if (ourLastInitializerPlace == BaseExpressionToFieldHandler.InitializationPlace.IN_CONSTRUCTOR) { - if (myInitialisersPlaceModel.getIndexOf(BaseExpressionToFieldHandler.InitializationPlace.IN_CONSTRUCTOR) > -1) { - myInitialisersPlaceModel.setSelectedItem(BaseExpressionToFieldHandler.InitializationPlace.IN_CONSTRUCTOR); - } else { - selectInCurrentMethod(); - } - } else if (ourLastInitializerPlace == BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION) { - if (myInitialisersPlaceModel.getIndexOf(BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION) > -1) { - myInitialisersPlaceModel.setSelectedItem(BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION); - } else { - selectInCurrentMethod(); - } - } else { + else if (myInitialisersPlaceModel.getIndexOf(BaseExpressionToFieldHandler.InitializationPlace.IN_CONSTRUCTOR) > -1 && myParentClass.getConstructors().length > 0) { + myInitialisersPlaceModel.setSelectedItem(BaseExpressionToFieldHandler.InitializationPlace.IN_CONSTRUCTOR); + } + else if (myInitialisersPlaceModel.getIndexOf(BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION) > -1) { + myInitialisersPlaceModel.setSelectedItem(BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION); + } + else { selectInCurrentMethod(); } } + @Override + protected void initializeControls(PsiExpression initializerExpression, + BaseExpressionToFieldHandler.InitializationPlace ourLastInitializerPlace) { + } + + @Override + public boolean isDeclareFinal() { + return allowFinal(); + } + private void selectInCurrentMethod() { if (myInitialisersPlaceModel.getIndexOf(BaseExpressionToFieldHandler.InitializationPlace.IN_CURRENT_METHOD) > -1) { myInitialisersPlaceModel.setSelectedItem(BaseExpressionToFieldHandler.InitializationPlace.IN_CURRENT_METHOD); @@ -107,7 +109,11 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { } public String getFieldVisibility() { - return (String)myVisibilityCombo.getSelectedItem(); + String visibility = JavaRefactoringSettings.getInstance().INTRODUCE_FIELD_VISIBILITY; + if (visibility == null) { + visibility = PsiModifier.PRIVATE; + } + return visibility; } protected JComponent createInitializerPlacePanel(final ItemListener itemListener, final ItemListener finalUpdater) { @@ -116,10 +122,8 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { JPanel groupPanel = new JPanel(new GridBagLayout()); final GridBagConstraints gridBagConstraints = - new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, - new Insets(0, 5, 0, 0), 0, 0); - gridBagConstraints.insets.top = 5; - + new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, + new Insets(0, 0, 0, 0), 0, 0); myInitialisersPlaceModel = new DefaultComboBoxModel(); myInitialisersPlaceModel.addElement(BaseExpressionToFieldHandler.InitializationPlace.IN_CURRENT_METHOD); @@ -132,6 +136,8 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { if (myInitialisersPlaceModel.getSize() > 1) { final JLabel initLabel = new JLabel(RefactoringBundle.message("initialize.in.border.title") + ":"); initLabel.setDisplayedMnemonic('i'); + gridBagConstraints.insets.left = 5; + gridBagConstraints.anchor = GridBagConstraints.WEST; groupPanel.add(initLabel, gridBagConstraints); JComboBox initializersCombo = new JComboBox(myInitialisersPlaceModel); InplaceCombosUtil.appendActions(initializersCombo, myParentClass.getProject()); @@ -156,32 +162,18 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { gridBagConstraints.gridx = 1; gridBagConstraints.insets.top = 0; gridBagConstraints.insets.left = 0; - gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; groupPanel.add(initializersCombo, gridBagConstraints); myInitializerCombo = initializersCombo; - } else if (myInitialisersPlaceModel.getSize() == 1){ + } /*else if (myInitialisersPlaceModel.getSize() == 1){ gridBagConstraints.gridwidth = 2; groupPanel.add(new JLabel("Initialize field in " + getPresentableText((BaseExpressionToFieldHandler.InitializationPlace)myInitialisersPlaceModel.getElementAt(0))), gridBagConstraints); gridBagConstraints.gridwidth = 1; - } + }*/ - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 1; - gridBagConstraints.insets.top = 8; - gridBagConstraints.insets.left = 5; - String visibility = JavaRefactoringSettings.getInstance().INTRODUCE_FIELD_VISIBILITY; - if (visibility == null) { - visibility = PsiModifier.PRIVATE; - } - myVisibilityCombo = InplaceCombosUtil.createVisibilityCombo(groupPanel, gridBagConstraints, myParentClass.getProject(), - visibility); - - mainPanel.add(groupPanel, BorderLayout.CENTER); - - return mainPanel; + return groupPanel; } @Nullable @@ -220,15 +212,6 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { return true; } - public void addVisibilityListener(final ChangeListener changeListener) { - myVisibilityCombo.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - changeListener.stateChanged(null); - } - }); - } - public void setInitializeInFieldDeclaration() { LOG.assertTrue(myInitializerCombo != null); myInitializerCombo.setSelectedItem(BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION); @@ -238,6 +221,10 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { myVisibilityCombo.setSelectedItem(visibility); } + @Override + protected void updateCbFinal() { + } + @Override protected boolean allowFinal() { final Object selectedItem = getInitializerPlace(); @@ -255,14 +242,20 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { return false; } + @Override + protected JPanel appendCheckboxes(ItemListener itemListener) { + final JPanel panel = new JPanel(new GridBagLayout()); + appendOccurrences(itemListener, new GridBagConstraints(0,0,1,1,0,0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0,0,0,0), 0,0), panel); + return panel; + } + protected JPanel composeWholePanel(JComponent initializerPlacePanel, JPanel checkboxPanel) { final JPanel panel = new JPanel(new GridBagLayout()); final GridBagConstraints constraints = - new GridBagConstraints(GridBagConstraints.RELATIVE, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, + new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); - constraints.insets.bottom = 5; panel.add(initializerPlacePanel, constraints); - constraints.insets.left = 5; + constraints.gridy++; panel.add(checkboxPanel, constraints); return panel; } 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 48d76f230ecf..0307db132614 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java @@ -49,7 +49,9 @@ import com.intellij.psi.codeStyle.SuggestedNameInfo; import com.intellij.psi.codeStyle.VariableKind; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.*; +import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer; import com.intellij.refactoring.introduceField.ElementToWorkOn; +import com.intellij.refactoring.introduceField.InplaceIntroduceFieldPopup; import com.intellij.refactoring.ui.MethodCellRenderer; import com.intellij.refactoring.ui.NameSuggestionsGenerator; import com.intellij.refactoring.ui.TypeSelectorManagerImpl; @@ -343,7 +345,7 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R private final Project myProject; - private final PsiExpression myExpr; + private PsiExpression myExpr; private PsiLocalVariable myLocalVar; private final Editor myEditor; @@ -367,12 +369,7 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R else { // local variable occurences = CodeInsightUtil.findReferenceExpressions(method, myLocalVar); } - PsiExpression expressionToRemoveParamFrom = myExpr; - if (myExpr == null) { - expressionToRemoveParamFrom = myLocalVar.getInitializer(); - } - TIntArrayList parametersToRemove = expressionToRemoveParamFrom == null ? new TIntArrayList() : Util - .findParametersToRemove(method, expressionToRemoveParamFrom, occurences); + boolean mustBeFinal = false; if (myLocalVar != null) { @@ -401,22 +398,30 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R ? new TypeSelectorManagerImpl(myProject, initializerType, myExpr, occurences) : new TypeSelectorManagerImpl(myProject, initializerType, occurences); - NameSuggestionsGenerator nameSuggestionsGenerator = createNameSuggestionGenerator(myExpr, propName, myProject); boolean isInplaceAvailableOnDataContext = myEditor != null && myEditor.getSettings().isVariableInplaceRenameEnabled(); if (myExpr != null) { isInplaceAvailableOnDataContext &= myExpr.isPhysical(); } - if (isInplaceAvailableOnDataContext) { - myInplaceIntroduceParameterPopup = - new InplaceIntroduceParameterPopup(myProject, myEditor, classMemberRefs, - typeSelectorManager, - myExpr, myLocalVar, method, methodToSearchFor, occurences, - parametersToRemove, - mustBeFinal); - if (myInplaceIntroduceParameterPopup.startInplaceIntroduceTemplate()) { - return; + final AbstractInplaceIntroducer activeIntroducer = AbstractInplaceIntroducer.getActiveIntroducer(myEditor); + if (activeIntroducer == null) { + + myInplaceIntroduceParameterPopup = + new InplaceIntroduceParameterPopup(myProject, myEditor, classMemberRefs, + typeSelectorManager, + myExpr, myLocalVar, method, methodToSearchFor, occurences, + getParamsToRemove(method, occurences), + mustBeFinal); + if (myInplaceIntroduceParameterPopup.startInplaceIntroduceTemplate()) { + return; + } + } + else { + AbstractInplaceIntroducer.stopIntroduce(myEditor); + myExpr = (PsiExpression)activeIntroducer.getExpr(); + myLocalVar = (PsiLocalVariable)activeIntroducer.getLocalVariable(); + occurences = (PsiExpression[])activeIntroducer.getOccurrences(); } } if (ApplicationManager.getApplication().isUnitTestMode()) { @@ -427,18 +432,28 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R new IntroduceParameterProcessor(myProject, method, methodToSearchFor, initializer, myExpr, myLocalVar, isDeleteLocalVariable, parameterName, replaceAllOccurences, IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, mustBeFinal, false, null, - parametersToRemove).run(); + getParamsToRemove(method, occurences)).run(); } else { if (myEditor != null) { RefactoringUtil.highlightAllOccurences(myProject, occurences, myEditor); } - new IntroduceParameterDialog(myProject, classMemberRefs, occurences, myLocalVar, myExpr, nameSuggestionsGenerator, - typeSelectorManager, methodToSearchFor, method, parametersToRemove, mustBeFinal).show(); + new IntroduceParameterDialog(myProject, classMemberRefs, occurences, myLocalVar, myExpr, + createNameSuggestionGenerator(myExpr, propName, myProject), + typeSelectorManager, methodToSearchFor, method, getParamsToRemove(method, occurences), mustBeFinal).show(); if (myEditor != null) { myEditor.getSelectionModel().removeSelection(); } } } + + private TIntArrayList getParamsToRemove(PsiMethod method, PsiExpression[] occurences) { + PsiExpression expressionToRemoveParamFrom = myExpr; + if (myExpr == null) { + expressionToRemoveParamFrom = myLocalVar.getInitializer(); + } + return expressionToRemoveParamFrom == null ? new TIntArrayList() : Util + .findParametersToRemove(method, expressionToRemoveParamFrom, occurences); + } } public InplaceIntroduceParameterPopup getInplaceIntroduceParameterPopup() { diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceField/makeFinal.java b/java/java-tests/testData/refactoring/inplaceIntroduceField/makeFinal.java deleted file mode 100644 index 1a44e3bbdeb4..000000000000 --- a/java/java-tests/testData/refactoring/inplaceIntroduceField/makeFinal.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2000-2011 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -class Test { - void simpleMethod() { - System.out.println(""); - System.out.println(""); - } -} diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceField/makeFinal_after.java b/java/java-tests/testData/refactoring/inplaceIntroduceField/makeFinal_after.java deleted file mode 100644 index f98cde371c6a..000000000000 --- a/java/java-tests/testData/refactoring/inplaceIntroduceField/makeFinal_after.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2000-2011 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -class Test { - - private final String x = ""; - - void simpleMethod() { - System.out.println(x); - System.out.println(""); - } -} diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceField/makeProtected.java b/java/java-tests/testData/refactoring/inplaceIntroduceField/makeProtected.java deleted file mode 100644 index 1a44e3bbdeb4..000000000000 --- a/java/java-tests/testData/refactoring/inplaceIntroduceField/makeProtected.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2000-2011 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -class Test { - void simpleMethod() { - System.out.println(""); - System.out.println(""); - } -} diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceField/makeProtectedFromLocal.java b/java/java-tests/testData/refactoring/inplaceIntroduceField/makeProtectedFromLocal.java deleted file mode 100644 index 8b78e50def8c..000000000000 --- a/java/java-tests/testData/refactoring/inplaceIntroduceField/makeProtectedFromLocal.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2000-2011 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -class Test { - void simpleMethod() { - String x = ""; - System.out.println(x); - System.out.println(""); - } -} diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceField/makeProtectedFromLocal_after.java b/java/java-tests/testData/refactoring/inplaceIntroduceField/makeProtectedFromLocal_after.java deleted file mode 100644 index 06dc0d8c014a..000000000000 --- a/java/java-tests/testData/refactoring/inplaceIntroduceField/makeProtectedFromLocal_after.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2000-2011 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -class Test { - - protected String x; - - void simpleMethod() { - x = ""; - System.out.println(x); - System.out.println(""); - } -} diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceField/makeProtected_after.java b/java/java-tests/testData/refactoring/inplaceIntroduceField/makeProtected_after.java deleted file mode 100644 index 06dc0d8c014a..000000000000 --- a/java/java-tests/testData/refactoring/inplaceIntroduceField/makeProtected_after.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2000-2011 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -class Test { - - protected String x; - - void simpleMethod() { - x = ""; - System.out.println(x); - System.out.println(""); - } -} diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceField/replaceAll_after.java b/java/java-tests/testData/refactoring/inplaceIntroduceField/replaceAll_after.java index a818fa631b43..f25df71b3f08 100644 --- a/java/java-tests/testData/refactoring/inplaceIntroduceField/replaceAll_after.java +++ b/java/java-tests/testData/refactoring/inplaceIntroduceField/replaceAll_after.java @@ -15,10 +15,9 @@ */ class Test { - private String x; + private final String x = ""; void simpleMethod() { - x = ""; System.out.println(x); System.out.println(x); } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceFieldTest.java b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceFieldTest.java index d002ba4a62ba..783bda3bdadf 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceFieldTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceFieldTest.java @@ -48,24 +48,6 @@ public class InplaceIntroduceFieldTest extends LightCodeInsightTestCase { }); } - public void testMakeFinal() throws Exception { - final boolean oldCreateFinals = IntroduceFieldCentralPanel.ourLastCbFinalState; - try { - IntroduceFieldCentralPanel.ourLastCbFinalState = false; - doTest(new Pass() { - @Override - public void pass(InplaceIntroduceFieldPopup inplaceIntroduceFieldPopup) { - inplaceIntroduceFieldPopup.setInitializeInFieldDeclaration(); - inplaceIntroduceFieldPopup.setCreateFinal(true); - } - }); - assertTrue(IntroduceFieldCentralPanel.ourLastCbFinalState); - } - finally { - IntroduceFieldCentralPanel.ourLastCbFinalState = oldCreateFinals; - } - } - public void testReplaceAll() throws Exception { doTest(new Pass() { @@ -76,29 +58,6 @@ public class InplaceIntroduceFieldTest extends LightCodeInsightTestCase { }); } - public void testMakeProtected() throws Exception { - - doTest(new Pass() { - @Override - public void pass(InplaceIntroduceFieldPopup inplaceIntroduceFieldPopup) { - inplaceIntroduceFieldPopup.setVisibility(PsiModifier.PACKAGE_LOCAL); - inplaceIntroduceFieldPopup.setVisibility(PsiModifier.PRIVATE); - inplaceIntroduceFieldPopup.setVisibility(PsiModifier.PROTECTED); - } - }); - } - - public void testMakeProtectedFromLocal() throws Exception { - doTest(new Pass() { - @Override - public void pass(InplaceIntroduceFieldPopup inplaceIntroduceFieldPopup) { - inplaceIntroduceFieldPopup.setVisibility(PsiModifier.PACKAGE_LOCAL); - inplaceIntroduceFieldPopup.setVisibility(PsiModifier.PRIVATE); - inplaceIntroduceFieldPopup.setVisibility(PsiModifier.PROTECTED); - } - }); - } - public void testEscapePosition() throws Exception { doTestEscape(); } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java index 428ef074882f..9376f9e49c2b 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java @@ -125,10 +125,10 @@ public class IntroduceConstantTest extends LightCodeInsightTestCase { new TypeSelectorManagerImpl(project, type, PsiTreeUtil.getParentOfType(anchorElement, PsiMethod.class), expr, occurences); final PsiType psiType = selectorManager.getDefaultType(); Assert.assertEquals(psiType.getCanonicalText(), expectedType); - return new Settings("xxx", true, true, true, + return new Settings("xxx", expr, occurences, true, true, true, InitializationPlace.IN_FIELD_DECLARATION, getVisibility(), null, psiType, false, parentClass, false, false); } }.invoke(getProject(), getEditor(), getFile(), null); } -} \ No newline at end of file +} diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldWitSetUpInitializationTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldWitSetUpInitializationTest.java index 07c5e28c547e..ba218ee76c8b 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldWitSetUpInitializationTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldWitSetUpInitializationTest.java @@ -93,7 +93,7 @@ public class IntroduceFieldWitSetUpInitializationTest extends CodeInsightTestCas final PsiLocalVariable local, final PsiExpression[] occurences, final boolean isStatic) { - return new BaseExpressionToFieldHandler.Settings("i", true, false, false, + return new BaseExpressionToFieldHandler.Settings("i", null, occurences, true, false, false, BaseExpressionToFieldHandler.InitializationPlace.IN_SETUP_METHOD, PsiModifier.PRIVATE, local, local.getType(), true, (BaseExpressionToFieldHandler.TargetDestination)null, false, false); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/MockIntroduceConstantHandler.java b/java/java-tests/testSrc/com/intellij/refactoring/MockIntroduceConstantHandler.java index 8ad7d0250b6b..63f10188c115 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/MockIntroduceConstantHandler.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/MockIntroduceConstantHandler.java @@ -20,7 +20,7 @@ public class MockIntroduceConstantHandler extends IntroduceConstantHandler{ protected Settings showRefactoringDialog(final Project project, final Editor editor, final PsiClass parentClass, final PsiExpression expr, final PsiType type, final PsiExpression[] occurences, final PsiElement anchorElement, final PsiElement anchorElementIfAll) { - return new Settings("xxx", true, true, true, InitializationPlace.IN_FIELD_DECLARATION, getVisibility(), null, null, false, + return new Settings("xxx", expr, occurences, true, true, true, InitializationPlace.IN_FIELD_DECLARATION, getVisibility(), null, null, false, myTargetClass != null ? myTargetClass : parentClass, false, false); } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/MockIntroduceFieldHandler.java b/java/java-tests/testSrc/com/intellij/refactoring/MockIntroduceFieldHandler.java index edff5f8a3635..5d38c7310cdf 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/MockIntroduceFieldHandler.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/MockIntroduceFieldHandler.java @@ -24,7 +24,7 @@ public class MockIntroduceFieldHandler extends IntroduceFieldHandler { protected Settings showRefactoringDialog(Project project, Editor editor, PsiClass parentClass, PsiExpression expr, PsiType type, PsiExpression[] occurences, PsiElement anchorElement, PsiElement anchorElementIfAll) { SuggestedNameInfo name = JavaCodeStyleManager.getInstance(project).suggestVariableName(VariableKind.FIELD, null, expr, type); - return new Settings(name.names[0], true, myDeclareStatic, true, myInitializationPlace, + return new Settings(name.names[0], expr, occurences, true, myDeclareStatic, true, myInitializationPlace, PsiModifier.PUBLIC, null, getFieldType(type), true, (TargetDestination)null, false, false); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/MockLocalToFieldHandler.java b/java/java-tests/testSrc/com/intellij/refactoring/MockLocalToFieldHandler.java index 09073b30fa64..22d76cd3acdc 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/MockLocalToFieldHandler.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/MockLocalToFieldHandler.java @@ -21,7 +21,7 @@ public class MockLocalToFieldHandler extends LocalToFieldHandler { @Override protected BaseExpressionToFieldHandler.Settings showRefactoringDialog(PsiClass aClass, PsiLocalVariable local, PsiExpression[] occurences, boolean isStatic) { - return new BaseExpressionToFieldHandler.Settings("xxx", true, isStatic, true, BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION, + return new BaseExpressionToFieldHandler.Settings("xxx", null, occurences, true, isStatic, true, BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION, PsiModifier.PRIVATE, local, local.getType(), false, aClass, true, myMakeEnumConstant); } } 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 488ee578a001..d2518f5889a3 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 @@ -30,6 +30,7 @@ import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.TextRange; @@ -37,6 +38,7 @@ import com.intellij.psi.*; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.*; @@ -53,6 +55,7 @@ public abstract class AbstractInplaceIntroducer ACTIVE_INTRODUCE = Key.create("ACTIVE_INTRODUCE"); public AbstractInplaceIntroducer(Project project, Editor editor, @@ -123,6 +126,9 @@ public abstract class AbstractInplaceIntroducer ex myExprMarker = exprMarker; } - protected E getExpr() { + public E getExpr() { return myExpr != null && myExpr.isValid() && myExpr.isPhysical() ? myExpr : null; } - protected E[] getOccurrences() { + public E[] getOccurrences() { return myOccurrences; } @@ -133,8 +133,7 @@ public abstract class AbstractInplaceVariableIntroducer ex .setHideOnClickOutside(false) .setHideOnKeyOutside(false) .setHideOnAction(false) - .setCloseButtonEnabled(true) - .setTitle(myTitle); + .setCloseButtonEnabled(true); final RelativePoint target = JBPopupFactory.getInstance().guessBestPopupLocation(myEditor); final Point screenPoint = target.getScreenPoint();