From 8f7e39a26d64eb9539394640f14ce31bc63aee39 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 10 Mar 2011 18:07:51 +0100 Subject: [PATCH] show number of invocations to inline (IDEA-65272) --- .../inline/InlineMethodDialog.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) 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 c8389c7f51b0..e5a3c794b843 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodDialog.java @@ -17,10 +17,15 @@ package com.intellij.refactoring.inline; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.help.HelpManager; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiJavaCodeReferenceElement; +import com.intellij.psi.PsiManager; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiSubstitutor; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.PsiSearchHelper; +import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiFormatUtil; import com.intellij.refactoring.HelpID; import com.intellij.refactoring.RefactoringBundle; @@ -34,6 +39,8 @@ public class InlineMethodDialog extends InlineOptionsDialog { private final PsiMethod myMethod; + private int myOccurrencesNumber = -1; + public InlineMethodDialog(Project project, PsiMethod method, PsiJavaCodeReferenceElement ref, Editor editor, final boolean allowInlineThisOnly) { super(project, true, method); @@ -44,10 +51,21 @@ public class InlineMethodDialog extends InlineOptionsDialog { myInvokedOnReference = ref != null; setTitle(REFACTORING_NAME); - + initOccurrencesNumber(method); init(); } + private void initOccurrencesNumber(PsiMethod method) { + final ProgressManager progressManager = ProgressManager.getInstance(); + final PsiSearchHelper searchHelper = method.getManager().getSearchHelper(); + final GlobalSearchScope scope = GlobalSearchScope.projectScope(method.getProject()); + final boolean isCheapToSearch = + searchHelper.isCheapEnoughToSearch(method.getName(), scope, null, progressManager.getProgressIndicator()) != PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES; + if (isCheapToSearch) { + myOccurrencesNumber = ReferencesSearch.search(method).findAll().size(); + } + } + protected String getNameLabelText() { String methodText = PsiFormatUtil.formatMethod(myMethod, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS, PsiFormatUtil.SHOW_TYPE); @@ -63,9 +81,10 @@ public class InlineMethodDialog extends InlineOptionsDialog { } protected String getInlineAllText() { - return myMethod.isWritable() - ? RefactoringBundle.message("all.invocations.and.remove.the.method") - : RefactoringBundle.message("all.invocations.in.project"); + final String occurrencesString = myOccurrencesNumber > -1 ? " (" + myOccurrencesNumber + " occurrence" + (myOccurrencesNumber == 1 ? ")" : "s)") : ""; + return (myMethod.isWritable() + ? RefactoringBundle.message("all.invocations.and.remove.the.method") + : RefactoringBundle.message("all.invocations.in.project")) + occurrencesString; } protected void doAction() {