safe delete: move overriding methods to targets in view

This commit is contained in:
Anna Kozlova
2012-05-31 14:15:08 +04:00
parent e70f160fe2
commit aa0ca08e3c
3 changed files with 58 additions and 10 deletions
@@ -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<PsiElement> overridingMethods = new ArrayList<PsiElement>();
final List<UsageInfo> others = new ArrayList<UsageInfo>();
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<PsiElement> getAdditionalElementsToDelete(final PsiElement element, final Collection<PsiElement> allElementsToDelete,
final boolean askUser) {
if (element instanceof PsiField) {
@@ -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;
}
@@ -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<? extends PsiElement> getElementsToSearch(PsiElement element, Collection<PsiElement> allElementsToDelete) {
return getElementsToSearch(element, null, allElementsToDelete);
}
@Nullable
public UsageView showUsages(UsageInfo[] usages, UsageViewPresentation presentation, UsageViewManager manager, PsiElement[] elements) {
return null;
}
}