diff --git a/java/java-impl/src/com/intellij/refactoring/safeDelete/JavaSafeDeleteProcessor.java b/java/java-impl/src/com/intellij/refactoring/safeDelete/JavaSafeDeleteProcessor.java index 9276aedb7219..84d7a4b0a1bf 100644 --- a/java/java-impl/src/com/intellij/refactoring/safeDelete/JavaSafeDeleteProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/safeDelete/JavaSafeDeleteProcessor.java @@ -16,6 +16,7 @@ package com.intellij.refactoring.safeDelete; import com.intellij.codeInsight.daemon.impl.quickfix.RemoveUnusedVariableFix; +import com.intellij.find.findUsages.PsiElement2UsageTargetAdapter; import com.intellij.ide.util.SuperMethodWarningUtil; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; @@ -44,6 +45,7 @@ import com.intellij.refactoring.util.RefactoringMessageUtil; import com.intellij.refactoring.util.RefactoringUIUtil; import com.intellij.usageView.UsageInfo; import com.intellij.usageView.UsageViewUtil; +import com.intellij.usages.*; import com.intellij.util.ArrayUtil; import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; @@ -146,6 +148,34 @@ public class JavaSafeDeleteProcessor extends SafeDeleteProcessorDelegateBase { } } + @Override + public UsageView showUsages(UsageInfo[] usages, UsageViewPresentation presentation, UsageViewManager manager, PsiElement[] elements) { + final List overridingMethods = new ArrayList(); + final List others = new ArrayList(); + for (UsageInfo usage : usages) { + if (usage instanceof SafeDeleteOverridingMethodUsageInfo) { + overridingMethods.add(((SafeDeleteOverridingMethodUsageInfo)usage).getOverridingMethod()); + } else { + others.add(usage); + } + } + + UsageTarget[] targets = new UsageTarget[elements.length + overridingMethods.size()]; + for (int i = 0; i < targets.length; i++) { + if (i < elements.length) { + targets[i] = new PsiElement2UsageTargetAdapter(elements[i]); + } else { + targets[i] = new PsiElement2UsageTargetAdapter(overridingMethods.get(i - elements.length)); + } + } + + return manager.showUsages(targets, + UsageInfoToUsageConverter.convert(new UsageInfoToUsageConverter.TargetElementsDescriptor(elements), + others.toArray(new UsageInfo[others.size()])), + presentation + ); + } + public Collection getAdditionalElementsToDelete(final PsiElement element, final Collection allElementsToDelete, final boolean askUser) { if (element instanceof PsiField) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteProcessor.java index bbadc0c06cc0..aad492208900 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteProcessor.java @@ -243,16 +243,7 @@ public class SafeDeleteProcessor extends BaseRefactoringProcessor { presentation.setUsagesString(RefactoringBundle.message("usageView.usagesText")); UsageViewManager manager = UsageViewManager.getInstance(myProject); - UsageTarget[] targets = new UsageTarget[myElements.length]; - for (int i = 0; i < targets.length; i++) { - targets[i] = new PsiElement2UsageTargetAdapter(myElements[i]); - } - - final UsageView usageView = manager.showUsages( - targets, - UsageInfoToUsageConverter.convert(new UsageInfoToUsageConverter.TargetElementsDescriptor(myElements), usages), - presentation - ); + final UsageView usageView = showUsages(usages, presentation, manager); usageView.addPerformOperationAction(new RerunSafeDelete(myProject, myElements, usageView), RefactoringBundle.message("retry.command"), null, RefactoringBundle.message("rerun.safe.delete")); usageView.addPerformOperationAction(new Runnable() { @@ -268,6 +259,24 @@ public class SafeDeleteProcessor extends BaseRefactoringProcessor { }, "Delete Anyway", RefactoringBundle.message("usageView.need.reRun"), RefactoringBundle.message("usageView.doAction")); } + private UsageView showUsages(UsageInfo[] usages, UsageViewPresentation presentation, UsageViewManager manager) { + for (SafeDeleteProcessorDelegate delegate : Extensions.getExtensions(SafeDeleteProcessorDelegate.EP_NAME)) { + if (delegate instanceof SafeDeleteProcessorDelegateBase) { + final UsageView view = ((SafeDeleteProcessorDelegateBase)delegate).showUsages(usages, presentation, manager, myElements); + if (view != null) return view; + } + } + UsageTarget[] targets = new UsageTarget[myElements.length]; + for (int i = 0; i < targets.length; i++) { + targets[i] = new PsiElement2UsageTargetAdapter(myElements[i]); + } + + return manager.showUsages(targets, + UsageInfoToUsageConverter.convert(new UsageInfoToUsageConverter.TargetElementsDescriptor(myElements), usages), + presentation + ); + } + public PsiElement[] getElements() { return myElements; } diff --git a/platform/lang-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteProcessorDelegateBase.java b/platform/lang-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteProcessorDelegateBase.java index 6aad21b890a8..f628803686da 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteProcessorDelegateBase.java +++ b/platform/lang-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteProcessorDelegateBase.java @@ -17,6 +17,10 @@ package com.intellij.refactoring.safeDelete; import com.intellij.openapi.module.Module; import com.intellij.psi.PsiElement; +import com.intellij.usageView.UsageInfo; +import com.intellij.usages.UsageView; +import com.intellij.usages.UsageViewManager; +import com.intellij.usages.UsageViewPresentation; import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -32,4 +36,9 @@ public abstract class SafeDeleteProcessorDelegateBase implements SafeDeleteProce public Collection getElementsToSearch(PsiElement element, Collection allElementsToDelete) { return getElementsToSearch(element, null, allElementsToDelete); } + + @Nullable + public UsageView showUsages(UsageInfo[] usages, UsageViewPresentation presentation, UsageViewManager manager, PsiElement[] elements) { + return null; + } }