mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-21 14:37:45 +07:00
inline all and keep declaration: replace rb hierarchy with list
This commit is contained in:
@@ -44,8 +44,10 @@ public class InlineFieldDialog extends InlineOptionsWithSearchSettingsDialog {
|
||||
}
|
||||
|
||||
protected String getNameLabelText() {
|
||||
final String occurrencesString = myOccurrencesNumber > -1 ? " (" + myOccurrencesNumber + " occurrence" + (myOccurrencesNumber == 1 ? ")" : "s)") : "";
|
||||
|
||||
String fieldText = PsiFormatUtil.formatVariable(myField, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE,PsiSubstitutor.EMPTY);
|
||||
return RefactoringBundle.message("inline.field.field.name.label", fieldText);
|
||||
return RefactoringBundle.message("inline.field.field.name.label", fieldText, occurrencesString);
|
||||
}
|
||||
|
||||
protected String getBorderTitle() {
|
||||
@@ -57,14 +59,7 @@ public class InlineFieldDialog extends InlineOptionsWithSearchSettingsDialog {
|
||||
}
|
||||
|
||||
protected String getInlineAllText() {
|
||||
final String occurrencesString = myOccurrencesNumber > -1 ? " (" + myOccurrencesNumber + " occurrence" + (myOccurrencesNumber == 1 ? ")" : "s)") : "";
|
||||
return RefactoringBundle.message("all.references.field", occurrencesString);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDeleteTheDeclarationText() {
|
||||
if (myField.isWritable()) return RefactoringBundle.message("all.references.remove.field");
|
||||
return super.getDeleteTheDeclarationText();
|
||||
return RefactoringBundle.message("all.references.and.remove.the.field");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,7 +96,7 @@ public class InlineFieldDialog extends InlineOptionsWithSearchSettingsDialog {
|
||||
super.doAction();
|
||||
invokeRefactoring(
|
||||
new InlineConstantFieldProcessor(myField, getProject(), myReferenceExpression, isInlineThisOnly(), isSearchInCommentsAndStrings(),
|
||||
isSearchForTextOccurrences(), isDeleteTheDeclaration()));
|
||||
isSearchForTextOccurrences(), !isKeepTheDeclaration()));
|
||||
JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
|
||||
if(myRbInlineThisOnly.isEnabled() && myRbInlineAll.isEnabled()) {
|
||||
settings.INLINE_FIELD_THIS = isInlineThisOnly();
|
||||
|
||||
@@ -58,10 +58,11 @@ public class InlineMethodDialog extends InlineOptionsWithSearchSettingsDialog {
|
||||
|
||||
@Override
|
||||
protected String getNameLabelText() {
|
||||
final String occurrencesString = myOccurrencesNumber > -1 ? " (" + myOccurrencesNumber + " occurrence" + (myOccurrencesNumber == 1 ? ")" : "s)") : "";
|
||||
String methodText = PsiFormatUtil.formatMethod(myMethod,
|
||||
PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS,
|
||||
PsiFormatUtilBase.SHOW_TYPE);
|
||||
return RefactoringBundle.message("inline.method.method.label", methodText);
|
||||
return RefactoringBundle.message("inline.method.method.label", methodText, occurrencesString);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,8 +77,7 @@ public class InlineMethodDialog extends InlineOptionsWithSearchSettingsDialog {
|
||||
|
||||
@Override
|
||||
protected String getInlineAllText() {
|
||||
final String occurrencesString = myOccurrencesNumber > -1 ? " (" + myOccurrencesNumber + " occurrence" + (myOccurrencesNumber == 1 ? ")" : "s)") : "";
|
||||
return (RefactoringBundle.message(myMethod.isWritable() ? "all.invocations.the.method" : "all.invocations.in.project")) + occurrencesString;
|
||||
return RefactoringBundle.message(myMethod.isWritable() ? "all.invocations.and.remove.the.method" : "all.invocations.in.project");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,18 +86,12 @@ public class InlineMethodDialog extends InlineOptionsWithSearchSettingsDialog {
|
||||
return super.getKeepTheDeclarationText();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDeleteTheDeclarationText() {
|
||||
if (myMethod.isWritable()) return RefactoringBundle.message("all.invocations.remove.the.method");
|
||||
return super.getDeleteTheDeclarationText();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doAction() {
|
||||
super.doAction();
|
||||
invokeRefactoring(
|
||||
new InlineMethodProcessor(getProject(), myMethod, myReferenceElement, myEditor, isInlineThisOnly(), isSearchInCommentsAndStrings(),
|
||||
isSearchForTextOccurrences(), isDeleteTheDeclaration()));
|
||||
isSearchForTextOccurrences(), !isKeepTheDeclaration()));
|
||||
JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
|
||||
if(myRbInlineThisOnly.isEnabled() && myRbInlineAll.isEnabled()) {
|
||||
settings.INLINE_METHOD_THIS = isInlineThisOnly();
|
||||
|
||||
@@ -402,7 +402,8 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
final boolean condition = InlineMethodProcessor.checkBadReturns(method) && !InlineUtil.allUsagesAreTailCalls(method);
|
||||
assertFalse("Bad returns found", condition);
|
||||
final InlineMethodProcessor processor =
|
||||
new InlineMethodProcessor(getProject(), method, refExpr, myEditor, options.isInlineThisOnly(), nonCode, nonCode, options.isDeleteTheDeclaration());
|
||||
new InlineMethodProcessor(getProject(), method, refExpr, myEditor, options.isInlineThisOnly(), nonCode, nonCode,
|
||||
!options.isKeepTheDeclaration());
|
||||
processor.run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public interface InlineOptions {
|
||||
|
||||
boolean isPreviewUsages();
|
||||
|
||||
default boolean isDeleteTheDeclaration() {
|
||||
return true;
|
||||
default boolean isKeepTheDeclaration() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,20 +25,17 @@ import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.refactoring.ui.RefactoringDialog;
|
||||
import com.intellij.refactoring.util.RadioUpDownListener;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
public abstract class InlineOptionsDialog extends RefactoringDialog implements InlineOptions {
|
||||
protected JRadioButton myRbInlineAll;
|
||||
protected JRadioButton myDeleteTheDeclaration;
|
||||
protected JRadioButton myKeepTheDeclaration;
|
||||
@Nullable protected JRadioButton myKeepTheDeclaration;
|
||||
protected JRadioButton myRbInlineThisOnly;
|
||||
protected boolean myInvokedOnReference;
|
||||
protected final PsiElement myElement;
|
||||
@@ -61,11 +58,11 @@ public abstract class InlineOptionsDialog extends RefactoringDialog implements I
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeleteTheDeclaration() {
|
||||
if (myDeleteTheDeclaration != null) {
|
||||
return myDeleteTheDeclaration.isSelected();
|
||||
public boolean isKeepTheDeclaration() {
|
||||
if (myKeepTheDeclaration != null) {
|
||||
return myKeepTheDeclaration.isSelected();
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -80,31 +77,43 @@ public abstract class InlineOptionsDialog extends RefactoringDialog implements I
|
||||
myRbInlineAll.setSelected(true);
|
||||
myRbInlineThisOnly = new JRadioButton();
|
||||
myRbInlineThisOnly.setText(getInlineThisText());
|
||||
|
||||
final boolean writable = allowInlineAll();
|
||||
optionsPanel.add(myRbInlineAll);
|
||||
JPanel inlineAllOptionsPanel = new JPanel();
|
||||
inlineAllOptionsPanel.setBorder(new EmptyBorder(0, JBUI.scale(20), 0, 0));
|
||||
inlineAllOptionsPanel.setLayout(new BoxLayout(inlineAllOptionsPanel, BoxLayout.Y_AXIS));
|
||||
optionsPanel.add(inlineAllOptionsPanel);
|
||||
|
||||
String keepDeclarationText = getKeepTheDeclarationText();
|
||||
if (keepDeclarationText != null && writable) {
|
||||
myKeepTheDeclaration = new JRadioButton();
|
||||
myKeepTheDeclaration.setText(keepDeclarationText);
|
||||
optionsPanel.add(myKeepTheDeclaration);
|
||||
}
|
||||
|
||||
optionsPanel.add(myRbInlineThisOnly);
|
||||
ButtonGroup bg = new ButtonGroup();
|
||||
bg.add(myRbInlineAll);
|
||||
bg.add(myRbInlineThisOnly);
|
||||
new RadioUpDownListener(myRbInlineAll, myRbInlineThisOnly);
|
||||
final JRadioButton[] buttons = myKeepTheDeclaration != null
|
||||
? new JRadioButton[] {myRbInlineAll, myKeepTheDeclaration, myRbInlineThisOnly}
|
||||
: new JRadioButton[] {myRbInlineAll, myRbInlineThisOnly};
|
||||
for (JRadioButton button : buttons) {
|
||||
bg.add(button);
|
||||
}
|
||||
new RadioUpDownListener(buttons);
|
||||
|
||||
myRbInlineThisOnly.setEnabled(myInvokedOnReference);
|
||||
final boolean writable = allowInlineAll();
|
||||
myRbInlineAll.setEnabled(writable);
|
||||
if(myInvokedOnReference) {
|
||||
if (canInlineThisOnly()) {
|
||||
myRbInlineAll.setSelected(false);
|
||||
myRbInlineAll.setEnabled(false);
|
||||
|
||||
if (myKeepTheDeclaration != null) {
|
||||
myKeepTheDeclaration.setSelected(false);
|
||||
myKeepTheDeclaration.setEnabled(false);
|
||||
}
|
||||
|
||||
myRbInlineThisOnly.setSelected(true);
|
||||
} else {
|
||||
if (writable) {
|
||||
final boolean inlineThis = isInlineThis();
|
||||
myRbInlineThisOnly.setSelected(inlineThis);
|
||||
if (myKeepTheDeclaration != null) myKeepTheDeclaration.setSelected(false);
|
||||
myRbInlineAll.setSelected(!inlineThis);
|
||||
}
|
||||
else {
|
||||
@@ -115,48 +124,22 @@ public abstract class InlineOptionsDialog extends RefactoringDialog implements I
|
||||
}
|
||||
else {
|
||||
myRbInlineAll.setSelected(true);
|
||||
if (myKeepTheDeclaration != null) myKeepTheDeclaration.setSelected(false);
|
||||
myRbInlineThisOnly.setSelected(false);
|
||||
}
|
||||
|
||||
getPreviewAction().setEnabled(myRbInlineAll.isSelected());
|
||||
myRbInlineAll.addItemListener(
|
||||
new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
boolean enabled = myRbInlineAll.isSelected();
|
||||
getPreviewAction().setEnabled(enabled);
|
||||
}
|
||||
getPreviewAction().setEnabled(myRbInlineAll.isSelected() || myKeepTheDeclaration != null && myKeepTheDeclaration.isSelected());
|
||||
final ActionListener previewListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
boolean enabled = myRbInlineAll.isSelected() || myKeepTheDeclaration != null && myKeepTheDeclaration.isSelected();
|
||||
getPreviewAction().setEnabled(enabled);
|
||||
}
|
||||
);
|
||||
|
||||
String deleteDeclarationText = getDeleteTheDeclarationText();
|
||||
String keepDeclarationText = getKeepTheDeclarationText();
|
||||
if (deleteDeclarationText != null && keepDeclarationText != null) {
|
||||
myDeleteTheDeclaration = new JRadioButton();
|
||||
myDeleteTheDeclaration.setText(deleteDeclarationText);
|
||||
myDeleteTheDeclaration.setSelected(true);
|
||||
inlineAllOptionsPanel.add(myDeleteTheDeclaration);
|
||||
|
||||
myKeepTheDeclaration = new JRadioButton();
|
||||
myKeepTheDeclaration.setText(keepDeclarationText);
|
||||
inlineAllOptionsPanel.add(myKeepTheDeclaration);
|
||||
|
||||
UIUtil.setEnabled(inlineAllOptionsPanel, myRbInlineAll.isSelected(), true);
|
||||
|
||||
ButtonGroup gr = new ButtonGroup();
|
||||
gr.add(myDeleteTheDeclaration);
|
||||
gr.add(myKeepTheDeclaration);
|
||||
|
||||
ActionListener enableListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
UIUtil.setEnabled(inlineAllOptionsPanel, myRbInlineAll.isSelected(), true);
|
||||
}
|
||||
};
|
||||
myRbInlineAll.addActionListener(enableListener);
|
||||
myRbInlineThisOnly.addActionListener(enableListener);
|
||||
};
|
||||
for (JRadioButton button : buttons) {
|
||||
button.addActionListener(previewListener);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return optionsPanel;
|
||||
}
|
||||
@@ -168,7 +151,6 @@ public abstract class InlineOptionsDialog extends RefactoringDialog implements I
|
||||
protected abstract String getNameLabelText();
|
||||
protected abstract String getBorderTitle();
|
||||
protected abstract String getInlineAllText();
|
||||
protected String getDeleteTheDeclarationText() {return null;}
|
||||
protected String getKeepTheDeclarationText() {return null;}
|
||||
protected abstract String getInlineThisText();
|
||||
protected abstract boolean isInlineThis();
|
||||
|
||||
+8
-2
@@ -19,6 +19,8 @@ package com.intellij.refactoring.inline;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.util.ui.JBInsets;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -72,11 +74,12 @@ public abstract class InlineOptionsWithSearchSettingsDialog extends InlineOption
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.weightx = 1.0;
|
||||
gbc.gridwidth = 2;
|
||||
gbc.insets.bottom = JBUI.scale(10);
|
||||
panel.add(super.createCenterPanel(), gbc);
|
||||
|
||||
|
||||
myCbSearchInComments = new JCheckBox(RefactoringBundle.message("search.in.comments.and.strings"), isSearchInCommentsAndStrings());
|
||||
myCbSearchTextOccurences = new JCheckBox(RefactoringBundle.message("search.for.text.occurrences"), isSearchForTextOccurrences());
|
||||
gbc.insets.bottom = 0;
|
||||
gbc.weightx = 0;
|
||||
gbc.gridwidth = 1;
|
||||
gbc.gridy = 1;
|
||||
@@ -87,11 +90,14 @@ public abstract class InlineOptionsWithSearchSettingsDialog extends InlineOption
|
||||
final ActionListener actionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setEnabledSearchSettngs(myRbInlineAll.isSelected());
|
||||
setEnabledSearchSettngs(myRbInlineAll.isSelected() || myKeepTheDeclaration != null && myKeepTheDeclaration.isSelected());
|
||||
}
|
||||
};
|
||||
myRbInlineThisOnly.addActionListener(actionListener);
|
||||
myRbInlineAll.addActionListener(actionListener);
|
||||
if (myKeepTheDeclaration != null) {
|
||||
myKeepTheDeclaration.addActionListener(actionListener);
|
||||
}
|
||||
setEnabledSearchSettngs(myRbInlineAll.isSelected());
|
||||
return panel;
|
||||
}
|
||||
|
||||
@@ -434,12 +434,10 @@ field.0.is.never.used=Field {0} is never used
|
||||
inline.field.command=Inline field {0}
|
||||
0.is.used.for.writing.in.1={0} is used for writing in {1}
|
||||
0.will.not.be.accessible.from.1.after.inlining={0} will not be accessible from {1} after inlining
|
||||
inline.field.field.name.label=Field {0}
|
||||
inline.field.field.name.label=Field {0} {1}
|
||||
inline.field.border.title=Inline
|
||||
all.references.and.remove.the.field=Inline &all references and remove the field
|
||||
all.references.field=Inline &all references ({0}) and
|
||||
all.references.remove.field=re&move the field
|
||||
all.references.keep.field=k&eep the field
|
||||
all.references.keep.field=Inline all references and k&eep the field
|
||||
all.references.and.remove.the.local=Inline &all references and remove the variable
|
||||
this.reference.only.and.keep.the.variable=Inline this reference only and &keep the variable
|
||||
this.reference.only.and.keep.the.field=Inline this reference only and &keep the field
|
||||
@@ -454,12 +452,10 @@ inline.local.variable.definition.prompt=Inline local variable ''{0}'' definition
|
||||
occurences.string=({0,choice,1#1 occurrence|2#{0,number} occurrences})
|
||||
occurrences.string=({0,choice,1#1 occurrence|2#{0,number} occurrences})
|
||||
inline.method.title=Inline Method
|
||||
inline.method.method.label=Method {0}
|
||||
inline.method.method.label=Method {0} {1}
|
||||
inline.method.border.title=Inline
|
||||
all.invocations.and.remove.the.method=Inline &all invocations and remove the method
|
||||
all.invocations.the.method=Inline &all invocations and
|
||||
all.invocations.remove.the.method=re&move the method
|
||||
all.invocations.keep.the.method=k&eep the method
|
||||
all.invocations.keep.the.method=Inline all invocations and k&eep the method
|
||||
all.invocations.in.project=&All invocations in project
|
||||
this.invocation.only.and.keep.the.method=Inline this invocation only and &keep the method
|
||||
refactoring.cannot.be.applied.to.abstract.methods={0} refactoring cannot be applied to abstract methods
|
||||
|
||||
Reference in New Issue
Block a user