From 0b59d19a7cd157020aba29d5cede277f797d6d01 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 5 Jun 2012 18:08:52 +0400 Subject: [PATCH] inline method/constant: warn when method is used in javadoc (IDEA-72562); add search in comments and strings/for text occurrences options --- .../inline/InlineConstantFieldProcessor.java | 59 +++++++++++++--- .../refactoring/inline/InlineFieldDialog.java | 27 +++++++- .../inline/InlineMethodDialog.java | 27 +++++++- .../inline/InlineMethodProcessor.java | 46 +++++++++++++ .../inline/InlineToAnonymousClassDialog.java | 53 ++++++-------- .../inlineMethod/MethodUsedInJavadoc.java | 7 ++ .../refactoring/inline/InlineMethodTest.java | 13 +++- .../inline/InlineOptionsDialog.java | 18 ++--- ...InlineOptionsWithSearchSettingsDialog.java | 69 +++++++++++++++++++ 9 files changed, 263 insertions(+), 56 deletions(-) create mode 100644 java/java-tests/testData/refactoring/inlineMethod/MethodUsedInJavadoc.java create mode 100644 platform/lang-impl/src/com/intellij/refactoring/inline/InlineOptionsWithSearchSettingsDialog.java diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java index 3b8db434bb0b..e8a94e02374a 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java @@ -20,14 +20,15 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Ref; import com.intellij.psi.*; +import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; import com.intellij.refactoring.BaseRefactoringProcessor; import com.intellij.refactoring.RefactoringBundle; -import com.intellij.refactoring.util.ConflictsUtil; -import com.intellij.refactoring.util.RefactoringUIUtil; +import com.intellij.refactoring.rename.NonCodeUsageInfoFactory; +import com.intellij.refactoring.util.*; import com.intellij.usageView.UsageInfo; import com.intellij.usageView.UsageViewDescriptor; import com.intellij.usageView.UsageViewUtil; @@ -35,7 +36,9 @@ import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; /** * @author ven @@ -45,12 +48,25 @@ public class InlineConstantFieldProcessor extends BaseRefactoringProcessor { private PsiField myField; private final PsiReferenceExpression myRefExpr; private final boolean myInlineThisOnly; + private boolean mySearchInCommentsAndStrings; + private boolean mySearchForTextOccurrences; public InlineConstantFieldProcessor(PsiField field, Project project, PsiReferenceExpression ref, boolean isInlineThisOnly) { + this(field, project, ref, isInlineThisOnly, false, false); + } + + public InlineConstantFieldProcessor(PsiField field, + Project project, + PsiReferenceExpression ref, + boolean isInlineThisOnly, + boolean searchInCommentsAndStrings, + boolean searchForTextOccurrences) { super(project); myField = field; myRefExpr = ref; myInlineThisOnly = isInlineThisOnly; + mySearchInCommentsAndStrings = searchInCommentsAndStrings; + mySearchForTextOccurrences = searchForTextOccurrences; } @NotNull @@ -62,7 +78,7 @@ public class InlineConstantFieldProcessor extends BaseRefactoringProcessor { protected boolean isPreviewUsages(UsageInfo[] usages) { if (super.isPreviewUsages(usages)) return true; for (UsageInfo info : usages) { - if (info instanceof UsageFromJavaDoc) return true; + if (info instanceof NonCodeUsageInfo) return true; } return false; } @@ -77,19 +93,32 @@ public class InlineConstantFieldProcessor extends BaseRefactoringProcessor { protected UsageInfo[] findUsages() { if (myInlineThisOnly) return new UsageInfo[]{new UsageInfo(myRefExpr)}; - PsiReference[] refs = ReferencesSearch.search(myField, GlobalSearchScope.projectScope(myProject), false).toArray(new PsiReference[0]); - UsageInfo[] infos = new UsageInfo[refs.length]; - for (int i = 0; i < refs.length; i++) { - PsiElement element = refs[i].getElement(); + List usages = new ArrayList(); + for (PsiReference ref : ReferencesSearch.search(myField, GlobalSearchScope.projectScope(myProject), false)) { + PsiElement element = ref.getElement(); UsageInfo info = new UsageInfo(element); if (!(element instanceof PsiExpression) && PsiTreeUtil.getParentOfType(element, PsiImportStaticStatement.class) == null) { info = new UsageFromJavaDoc(element); } - infos[i] = info; + usages.add(info); } - return infos; + if (mySearchInCommentsAndStrings || mySearchForTextOccurrences) { + TextOccurrencesUtil.UsageInfoFactory nonCodeUsageFactory = new NonCodeUsageInfoFactory(myField, myField.getName()); + if (mySearchInCommentsAndStrings) { + String stringToSearch = + ElementDescriptionUtil.getElementDescription(myField, NonCodeSearchDescriptionLocation.STRINGS_AND_COMMENTS); + TextOccurrencesUtil.addUsagesInStringsAndComments(myField, stringToSearch, usages, nonCodeUsageFactory); + } + + if (mySearchForTextOccurrences) { + String stringToSearch = ElementDescriptionUtil.getElementDescription(myField, NonCodeSearchDescriptionLocation.NON_JAVA); + TextOccurrencesUtil + .addTextOccurences(myField, stringToSearch, GlobalSearchScope.projectScope(myProject), usages, nonCodeUsageFactory); + } + } + return usages.toArray(new UsageInfo[usages.size()]); } protected void refreshElements(PsiElement[] elements) { @@ -105,6 +134,7 @@ public class InlineConstantFieldProcessor extends BaseRefactoringProcessor { initializer = normalize ((PsiExpression)initializer.copy()); for (UsageInfo info : usages) { if (info instanceof UsageFromJavaDoc) continue; + if (info instanceof NonCodeUsageInfo) continue; final PsiElement element = info.getElement(); try { if (element instanceof PsiExpression) { @@ -235,6 +265,17 @@ public class InlineConstantFieldProcessor extends BaseRefactoringProcessor { } } + if (!myInlineThisOnly) { + for (UsageInfo info : usagesIn) { + if (info instanceof UsageFromJavaDoc) { + final PsiElement element = info.getElement(); + if (element instanceof PsiDocMethodOrFieldRef && !PsiTreeUtil.isAncestor(myField, element, false)) { + conflicts.putValue(element, "Inlined method is used in javadoc"); + } + } + } + } + return showConflicts(conflicts, usagesIn); } diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineFieldDialog.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineFieldDialog.java index 602460f923e5..9df62a9dbe14 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineFieldDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineFieldDialog.java @@ -25,7 +25,7 @@ import com.intellij.refactoring.HelpID; import com.intellij.refactoring.JavaRefactoringSettings; import com.intellij.refactoring.RefactoringBundle; -public class InlineFieldDialog extends InlineOptionsDialog { +public class InlineFieldDialog extends InlineOptionsWithSearchSettingsDialog { public static final String REFACTORING_NAME = RefactoringBundle.message("inline.field.title"); private final PsiReferenceExpression myReferenceExpression; @@ -65,8 +65,31 @@ public class InlineFieldDialog extends InlineOptionsDialog { return JavaRefactoringSettings.getInstance().INLINE_FIELD_THIS; } + @Override + protected boolean isSearchInCommentsAndStrings() { + return JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_FIELD; + } + + @Override + protected void saveSearchInCommentsAndStrings(boolean searchInComments) { + JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_FIELD = searchInComments; + } + + @Override + protected boolean isSearchForTextOccurrences() { + return JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_FIELD; + } + + @Override + protected void saveSearchInTextOccurrences(boolean searchInTextOccurrences) { + JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_FIELD = searchInTextOccurrences; + } + protected void doAction() { - invokeRefactoring(new InlineConstantFieldProcessor(myField, getProject(), myReferenceExpression, isInlineThisOnly())); + super.doAction(); + invokeRefactoring( + new InlineConstantFieldProcessor(myField, getProject(), myReferenceExpression, isInlineThisOnly(), isSearchInCommentsAndStrings(), + isSearchForTextOccurrences())); JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance(); if(myRbInlineThisOnly.isEnabled() && myRbInlineAll.isEnabled()) { settings.INLINE_FIELD_THIS = isInlineThisOnly(); diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodDialog.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodDialog.java index d93e87f84ac3..fd5b5ae3f2a3 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodDialog.java @@ -26,7 +26,7 @@ import com.intellij.refactoring.HelpID; import com.intellij.refactoring.JavaRefactoringSettings; import com.intellij.refactoring.RefactoringBundle; -public class InlineMethodDialog extends InlineOptionsDialog { +public class InlineMethodDialog extends InlineOptionsWithSearchSettingsDialog { public static final String REFACTORING_NAME = RefactoringBundle.message("inline.method.title"); private final PsiJavaCodeReferenceElement myReferenceElement; private final Editor myEditor; @@ -72,7 +72,10 @@ public class InlineMethodDialog extends InlineOptionsDialog { } protected void doAction() { - invokeRefactoring(new InlineMethodProcessor(getProject(), myMethod, myReferenceElement, myEditor, isInlineThisOnly())); + super.doAction(); + invokeRefactoring( + new InlineMethodProcessor(getProject(), myMethod, myReferenceElement, myEditor, isInlineThisOnly(), isSearchInCommentsAndStrings(), + isSearchForTextOccurrences())); JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance(); if(myRbInlineThisOnly.isEnabled() && myRbInlineAll.isEnabled()) { settings.INLINE_METHOD_THIS = isInlineThisOnly(); @@ -91,4 +94,24 @@ public class InlineMethodDialog extends InlineOptionsDialog { protected boolean isInlineThis() { return JavaRefactoringSettings.getInstance().INLINE_METHOD_THIS; } + + @Override + protected boolean isSearchInCommentsAndStrings() { + return JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_METHOD; + } + + @Override + protected void saveSearchInCommentsAndStrings(boolean searchInComments) { + JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_METHOD = searchInComments; + } + + @Override + protected boolean isSearchForTextOccurrences() { + return JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_METHOD; + } + + @Override + protected void saveSearchInTextOccurrences(boolean searchInTextOccurrences) { + JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_METHOD = searchInTextOccurrences; + } } diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java index d008ebdce664..873ebab9d542 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java @@ -31,6 +31,7 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.codeStyle.VariableKind; import com.intellij.psi.controlFlow.*; import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; +import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef; import com.intellij.psi.infos.MethodCandidateInfo; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.LocalSearchScope; @@ -42,7 +43,9 @@ import com.intellij.psi.util.PsiUtil; import com.intellij.refactoring.BaseRefactoringProcessor; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.introduceParameter.Util; +import com.intellij.refactoring.rename.NonCodeUsageInfoFactory; import com.intellij.refactoring.rename.RenameJavaVariableProcessor; +import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteReferenceSimpleDeleteUsageInfo; import com.intellij.refactoring.util.*; import com.intellij.usageView.UsageInfo; import com.intellij.usageView.UsageViewDescriptor; @@ -64,6 +67,8 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor { private PsiJavaCodeReferenceElement myReference; private final Editor myEditor; private final boolean myInlineThisOnly; + private final boolean mySearchInComments; + private final boolean mySearchForTextOccurrences; private final PsiManager myManager; private final PsiElementFactory myFactory; @@ -80,11 +85,23 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor { @Nullable PsiJavaCodeReferenceElement reference, Editor editor, boolean isInlineThisOnly) { + this(project, method, reference, editor, isInlineThisOnly, false, false); + } + + public InlineMethodProcessor(@NotNull Project project, + @NotNull PsiMethod method, + @Nullable PsiJavaCodeReferenceElement reference, + Editor editor, + boolean isInlineThisOnly, + boolean searchInComments, + boolean searchForTextOccurrences) { super(project); myMethod = method; myReference = reference; myEditor = editor; myInlineThisOnly = isInlineThisOnly; + mySearchInComments = searchInComments; + mySearchForTextOccurrences = searchForTextOccurrences; myManager = PsiManager.getInstance(myProject); myFactory = JavaPsiFacade.getInstance(myManager.getProject()).getElementFactory(); @@ -113,9 +130,31 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor { usages.add(new UsageInfo(reference.getElement())); } + if (mySearchInComments || mySearchForTextOccurrences) { + + if (mySearchInComments) { + String stringToSearch = ElementDescriptionUtil.getElementDescription(myMethod, NonCodeSearchDescriptionLocation.STRINGS_AND_COMMENTS); + TextOccurrencesUtil.addUsagesInStringsAndComments(myMethod, stringToSearch, usages, new NonCodeUsageInfoFactory(myMethod, myMethod.getName())); + } + + if (mySearchForTextOccurrences) { + String stringToSearch = ElementDescriptionUtil.getElementDescription(myMethod, NonCodeSearchDescriptionLocation.NON_JAVA); + TextOccurrencesUtil + .addTextOccurences(myMethod, stringToSearch, GlobalSearchScope.projectScope(myProject), usages, new NonCodeUsageInfoFactory(myMethod, myMethod.getName())); + } + } + return usages.toArray(new UsageInfo[usages.size()]); } + @Override + protected boolean isPreviewUsages(UsageInfo[] usages) { + for (UsageInfo usage : usages) { + if (usage instanceof NonCodeUsageInfo) return true; + } + return super.isPreviewUsages(usages); + } + protected void refreshElements(PsiElement[] elements) { boolean condition = elements.length == 1 && elements[0] instanceof PsiMethod; LOG.assertTrue(condition); @@ -137,6 +176,13 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor { .message("inlined.method.overrides.method.from.0", method.getContainingClass().getQualifiedName()); conflicts.putValue(method, message); } + + for (UsageInfo info : usagesIn) { + final PsiElement element = info.getElement(); + if (element instanceof PsiDocMethodOrFieldRef && !PsiTreeUtil.isAncestor(myMethod, element, false)) { + conflicts.putValue(element, "Inlined method is used in javadoc"); + } + } } addInaccessibleMemberConflicts(myMethod, usagesIn, new ReferencedElementsCollector(), conflicts); diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassDialog.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassDialog.java index ef75c1c88152..b97da5d12b1f 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassDialog.java @@ -24,17 +24,12 @@ import com.intellij.refactoring.HelpID; import com.intellij.refactoring.JavaRefactoringSettings; import com.intellij.refactoring.RefactoringBundle; -import javax.swing.*; -import java.awt.*; - /** * @author yole */ -public class InlineToAnonymousClassDialog extends InlineOptionsDialog { +public class InlineToAnonymousClassDialog extends InlineOptionsWithSearchSettingsDialog { private final PsiClass myClass; private final PsiCall myCallToInline; - private JCheckBox myCbSearchInComments; - private JCheckBox myCbSearchTextOccurences; protected InlineToAnonymousClassDialog(Project project, PsiClass psiClass, final PsiCall callToInline, boolean isInvokeOnReference) { super(project, true, psiClass); @@ -66,38 +61,30 @@ public class InlineToAnonymousClassDialog extends InlineOptionsDialog { return false; } - protected JComponent createCenterPanel() { - JComponent optionsPanel = super.createCenterPanel(); + @Override + protected boolean isSearchInCommentsAndStrings() { + return JavaRefactoringSettings.getInstance().INLINE_CLASS_SEARCH_IN_COMMENTS; + } - JPanel panel = new JPanel(); - panel.setLayout(new GridBagLayout()); - GridBagConstraints gbc = new GridBagConstraints(); - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.weightx = 1.0; - panel.add(optionsPanel, gbc); - - JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance(); - myCbSearchInComments = new JCheckBox(RefactoringBundle.message("search.in.comments.and.strings"), - settings.INLINE_CLASS_SEARCH_IN_COMMENTS); - myCbSearchTextOccurences = new JCheckBox(RefactoringBundle.message("search.for.text.occurrences"), - settings.INLINE_CLASS_SEARCH_IN_NON_JAVA); - gbc.gridy = 1; - panel.add(myCbSearchInComments, gbc); - gbc.gridy = 2; - panel.add(myCbSearchTextOccurences, gbc); - return panel; + @Override + protected boolean isSearchForTextOccurrences() { + return JavaRefactoringSettings.getInstance().INLINE_CLASS_SEARCH_IN_NON_JAVA; } protected void doAction() { - final boolean searchInComments = myCbSearchInComments.isSelected(); - final boolean searchInNonJava = myCbSearchTextOccurences.isSelected(); - - JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance(); - settings.INLINE_CLASS_SEARCH_IN_COMMENTS = searchInComments; - settings.INLINE_CLASS_SEARCH_IN_NON_JAVA = searchInNonJava; - + super.doAction(); invokeRefactoring(new InlineToAnonymousClassProcessor(getProject(), myClass, myCallToInline, isInlineThisOnly(), - searchInComments, searchInNonJava)); + isSearchInCommentsAndStrings(), isSearchForTextOccurrences())); + } + + @Override + protected void saveSearchInCommentsAndStrings(boolean searchInComments) { + JavaRefactoringSettings.getInstance().INLINE_CLASS_SEARCH_IN_COMMENTS = searchInComments; + } + + @Override + protected void saveSearchInTextOccurrences(boolean searchInTextOccurrences) { + JavaRefactoringSettings.getInstance().INLINE_CLASS_SEARCH_IN_NON_JAVA = searchInTextOccurrences; } protected void doHelpAction() { diff --git a/java/java-tests/testData/refactoring/inlineMethod/MethodUsedInJavadoc.java b/java/java-tests/testData/refactoring/inlineMethod/MethodUsedInJavadoc.java new file mode 100644 index 000000000000..af2f72839ec3 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineMethod/MethodUsedInJavadoc.java @@ -0,0 +1,7 @@ +/** + * {@link InlineMethodTest#foo} + */ +class InlineMethodTest { + public void foo(){} + +} diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java index ed976b84d5c2..99b98075ce1d 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java @@ -6,6 +6,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiReference; import com.intellij.psi.PsiReferenceExpression; +import com.intellij.refactoring.BaseRefactoringProcessor; import com.intellij.refactoring.LightRefactoringTestCase; import com.intellij.refactoring.MockInlineMethodOptions; import com.intellij.refactoring.util.InlineUtil; @@ -174,7 +175,17 @@ public class InlineMethodTest extends LightRefactoringTestCase { public void testInlineAnonymousClassWithPrivateMethodInside() throws Exception { doTest(); } - + + public void testMethodUsedInJavadoc() throws Exception { + try { + doTest(); + fail("Conflict was not detected"); + } + catch (BaseRefactoringProcessor.ConflictsInTestsException e) { + assertEquals("Inlined method is used in javadoc", e.getMessage()); + } + } + public void testInlineRunnableRun() throws Exception { @NonNls String fileName = "/refactoring/inlineMethod/" + getTestName(false) + ".java"; configureByFile(fileName); diff --git a/platform/lang-impl/src/com/intellij/refactoring/inline/InlineOptionsDialog.java b/platform/lang-impl/src/com/intellij/refactoring/inline/InlineOptionsDialog.java index 01d4b942be79..6b0819711bd9 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/inline/InlineOptionsDialog.java +++ b/platform/lang-impl/src/com/intellij/refactoring/inline/InlineOptionsDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.refactoring.inline; import com.intellij.openapi.progress.ProgressManager; @@ -23,11 +22,13 @@ import com.intellij.psi.PsiNameIdentifierOwner; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.ui.RefactoringDialog; import com.intellij.refactoring.util.RadioUpDownListener; import javax.swing.*; import javax.swing.border.EmptyBorder; +import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; @@ -37,7 +38,6 @@ public abstract class InlineOptionsDialog extends RefactoringDialog implements I protected boolean myInvokedOnReference; protected final PsiElement myElement; private final JLabel myNameLabel = new JLabel(); - protected JPanel myOptionsPanel; protected InlineOptionsDialog(Project project, boolean canBeParent, PsiElement element) { super(project, canBeParent); @@ -54,9 +54,9 @@ public abstract class InlineOptionsDialog extends RefactoringDialog implements I } protected JComponent createCenterPanel() { - myOptionsPanel = new JPanel(); - myOptionsPanel.setBorder(new EmptyBorder(10, 0, 0, 0)); - myOptionsPanel.setLayout(new BoxLayout(myOptionsPanel, BoxLayout.Y_AXIS)); + JPanel optionsPanel = new JPanel(); + optionsPanel.setBorder(new EmptyBorder(10, 0, 0, 0)); + optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS)); myRbInlineAll = new JRadioButton(); myRbInlineAll.setText(getInlineAllText()); @@ -64,8 +64,8 @@ public abstract class InlineOptionsDialog extends RefactoringDialog implements I myRbInlineThisOnly = new JRadioButton(); myRbInlineThisOnly.setText(getInlineThisText()); - myOptionsPanel.add(myRbInlineAll); - myOptionsPanel.add(myRbInlineThisOnly); + optionsPanel.add(myRbInlineAll); + optionsPanel.add(myRbInlineThisOnly); ButtonGroup bg = new ButtonGroup(); bg.add(myRbInlineAll); bg.add(myRbInlineThisOnly); @@ -105,7 +105,7 @@ public abstract class InlineOptionsDialog extends RefactoringDialog implements I } } ); - return myOptionsPanel; + return optionsPanel; } protected abstract String getNameLabelText(); diff --git a/platform/lang-impl/src/com/intellij/refactoring/inline/InlineOptionsWithSearchSettingsDialog.java b/platform/lang-impl/src/com/intellij/refactoring/inline/InlineOptionsWithSearchSettingsDialog.java new file mode 100644 index 000000000000..dc02ae5406da --- /dev/null +++ b/platform/lang-impl/src/com/intellij/refactoring/inline/InlineOptionsWithSearchSettingsDialog.java @@ -0,0 +1,69 @@ +/* + * Copyright 2000-2009 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. + */ + +package com.intellij.refactoring.inline; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.refactoring.RefactoringBundle; + +import javax.swing.*; +import java.awt.*; + +public abstract class InlineOptionsWithSearchSettingsDialog extends InlineOptionsDialog { + protected JCheckBox myCbSearchInComments; + protected JCheckBox myCbSearchTextOccurences; + + protected InlineOptionsWithSearchSettingsDialog(Project project, boolean canBeParent, PsiElement element) { + super(project, canBeParent, element); + } + + protected abstract boolean isSearchInCommentsAndStrings(); + protected abstract void saveSearchInCommentsAndStrings(boolean searchInComments); + + protected abstract boolean isSearchForTextOccurrences(); + protected abstract void saveSearchInTextOccurrences(boolean searchInTextOccurrences); + + @Override + protected void doAction() { + final boolean searchInNonJava = myCbSearchTextOccurences.isSelected(); + final boolean searchInComments = myCbSearchInComments.isSelected(); + saveSearchInCommentsAndStrings(searchInComments); + saveSearchInTextOccurrences(searchInNonJava); + } + + @Override + protected JComponent createCenterPanel() { + final JPanel panel = new JPanel(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.weightx = 1.0; + gbc.gridwidth = 2; + 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.weightx = 0; + gbc.gridwidth = 1; + gbc.gridy = 1; + gbc.gridx = 0; + panel.add(myCbSearchInComments, gbc); + gbc.gridx = 1; + panel.add(myCbSearchTextOccurences, gbc); + return panel; + } +}