safe delete: search for conflicts in usages (IDEA-152126)

This commit is contained in:
Anna Kozlova
2016-03-03 11:39:53 +01:00
parent 89f6a57fb2
commit 953c6249c4
3 changed files with 28 additions and 2 deletions
@@ -256,6 +256,27 @@ public class JavaSafeDeleteProcessor extends SafeDeleteProcessorDelegateBase {
return null;
}
@Override
public Collection<String> findConflicts(PsiElement element, PsiElement[] elements, UsageInfo[] usages) {
String methodRefFound = null;
if (!ApplicationManager.getApplication().isUnitTestMode() && (element instanceof PsiMethod || element instanceof PsiParameter)) {
for (UsageInfo usage : usages) {
final PsiElement refElement = usage.getElement();
if (refElement instanceof PsiMethodReferenceExpression) {
methodRefFound = RefactoringBundle.message("expand.method.reference.warning");
break;
}
}
}
if (methodRefFound != null) {
Collection<String> result = new ArrayList<>();
result.add(methodRefFound);
result.addAll(super.findConflicts(element, elements, usages));
return result;
}
return super.findConflicts(element, elements, usages);
}
public Collection<String> findConflicts(@NotNull final PsiElement element, @NotNull final PsiElement[] allElementsToDelete) {
if (element instanceof PsiMethod) {
final PsiClass containingClass = ((PsiMethod)element).getContainingClass();
@@ -26,7 +26,6 @@ import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.DumbModePermission;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.*;
@@ -188,7 +187,9 @@ public class SafeDeleteProcessor extends BaseRefactoringProcessor {
for (PsiElement element : myElements) {
for(SafeDeleteProcessorDelegate delegate: Extensions.getExtensions(SafeDeleteProcessorDelegate.EP_NAME)) {
if (delegate.handlesElement(element)) {
Collection<String> foundConflicts = delegate.findConflicts(element, myElements);
Collection<String> foundConflicts = delegate instanceof SafeDeleteProcessorDelegateBase
? ((SafeDeleteProcessorDelegateBase)delegate).findConflicts(element, myElements, usages)
: delegate.findConflicts(element, myElements);
if (foundConflicts != null) {
conflicts.addAll(foundConflicts);
}
@@ -42,4 +42,8 @@ public abstract class SafeDeleteProcessorDelegateBase implements SafeDeleteProce
public UsageView showUsages(UsageInfo[] usages, UsageViewPresentation presentation, UsageViewManager manager, PsiElement[] elements) {
return null;
}
public Collection<String> findConflicts(PsiElement element, PsiElement[] elements, UsageInfo[] usages) {
return findConflicts(element, elements);
}
}