mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
suggest to delete method overriders even if conflicts were found (IDEA-51577)
This commit is contained in:
+13
-23
@@ -308,37 +308,27 @@ public class JavaSafeDeleteProcessor implements SafeDeleteProcessorDelegate {
|
||||
removeDeletedMethods(OverridingMethodsSearch.search(psiMethod, psiMethod.getUseScope(), true).toArray(PsiMethod.EMPTY_ARRAY),
|
||||
allElementsToDelete);
|
||||
|
||||
boolean anyRefs = false;
|
||||
for (PsiReference reference : references) {
|
||||
final PsiElement element = reference.getElement();
|
||||
if (!isInside(element, allElementsToDelete) && !isInside(element, overridingMethods)) {
|
||||
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(element, psiMethod, false));
|
||||
anyRefs = true;
|
||||
}
|
||||
}
|
||||
|
||||
final Condition<PsiElement> usageInsideDeleted;
|
||||
if (!anyRefs) {
|
||||
HashMap<PsiMethod, Collection<PsiReference>> methodToReferences = new HashMap<PsiMethod, Collection<PsiReference>>();
|
||||
for (PsiMethod overridingMethod : overridingMethods) {
|
||||
final Collection<PsiReference> overridingReferences = ReferencesSearch.search(overridingMethod).findAll();
|
||||
methodToReferences.put(overridingMethod, overridingReferences);
|
||||
final HashMap<PsiMethod, Collection<PsiReference>> methodToReferences = new HashMap<PsiMethod, Collection<PsiReference>>();
|
||||
for (PsiMethod overridingMethod : overridingMethods) {
|
||||
final Collection<PsiReference> overridingReferences = ReferencesSearch.search(overridingMethod).findAll();
|
||||
methodToReferences.put(overridingMethod, overridingReferences);
|
||||
}
|
||||
final Set<PsiMethod> validOverriding =
|
||||
validateOverridingMethods(psiMethod, references, Arrays.asList(overridingMethods), methodToReferences, usages,
|
||||
allElementsToDelete);
|
||||
return new Condition<PsiElement>() {
|
||||
public boolean value(PsiElement usage) {
|
||||
if(usage instanceof PsiFile) return false;
|
||||
return isInside(usage, allElementsToDelete) || isInside(usage, validOverriding);
|
||||
}
|
||||
final Set<PsiMethod> validOverriding =
|
||||
validateOverridingMethods(psiMethod, references, Arrays.asList(overridingMethods), methodToReferences, usages,
|
||||
allElementsToDelete);
|
||||
usageInsideDeleted = new Condition<PsiElement>() {
|
||||
public boolean value(PsiElement usage) {
|
||||
if(usage instanceof PsiFile) return false;
|
||||
return isInside(usage, allElementsToDelete) || isInside(usage, validOverriding);
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
usageInsideDeleted = getUsageInsideDeletedFilter(allElementsToDelete);
|
||||
}
|
||||
|
||||
return usageInsideDeleted;
|
||||
};
|
||||
}
|
||||
|
||||
private static PsiMethod[] removeDeletedMethods(PsiMethod[] methods, final PsiElement[] allElementsToDelete) {
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
public class A {
|
||||
void foo() {
|
||||
bar();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
public class A {
|
||||
void foo() {
|
||||
bar();
|
||||
}
|
||||
|
||||
void b<caret>ar() {}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
void bar(){
|
||||
super.bar();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.TargetElementUtilBase;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.safeDelete.SafeDeleteHandler;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.io.File;
|
||||
@@ -61,6 +61,17 @@ public class SafeDeleteTest extends MultiFileTestCase {
|
||||
doTest("UserFlags");
|
||||
}
|
||||
|
||||
public void testRemoveOverridersInspiteOfUnsafeUsages() throws Exception {
|
||||
myDoCompare = false;
|
||||
try {
|
||||
BaseRefactoringProcessor.ConflictsInTestsException.setTestIgnore(true);
|
||||
doTest("A");
|
||||
}
|
||||
finally {
|
||||
BaseRefactoringProcessor.ConflictsInTestsException.setTestIgnore(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void doTest(@NonNls final String qClassName) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
|
||||
@@ -465,11 +465,21 @@ public abstract class BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
public static class ConflictsInTestsException extends RuntimeException {
|
||||
private final Collection<? extends String> messages;
|
||||
private final Collection<? extends String> messages;
|
||||
|
||||
public ConflictsInTestsException(Collection<? extends String> messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
private static boolean myTestIgnore = false;
|
||||
|
||||
public ConflictsInTestsException(Collection<? extends String> messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
public static void setTestIgnore(boolean myIgnore) {
|
||||
myTestIgnore = myIgnore;
|
||||
}
|
||||
|
||||
public static boolean isTestIgnore() {
|
||||
return myTestIgnore;
|
||||
}
|
||||
|
||||
public Collection<String> getMessages() {
|
||||
List<String> result = new ArrayList<String>(messages);
|
||||
|
||||
@@ -171,7 +171,7 @@ public class SafeDeleteProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
if (!conflicts.isEmpty()) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
throw new ConflictsInTestsException(conflicts);
|
||||
if (!ConflictsInTestsException.isTestIgnore()) throw new ConflictsInTestsException(conflicts);
|
||||
}
|
||||
else {
|
||||
UnsafeUsagesDialog dialog = new UnsafeUsagesDialog(ArrayUtil.toStringArray(conflicts), myProject);
|
||||
|
||||
Reference in New Issue
Block a user