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 91048594be19..2173e1901a91 100644 --- a/java/java-impl/src/com/intellij/refactoring/safeDelete/JavaSafeDeleteProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/safeDelete/JavaSafeDeleteProcessor.java @@ -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 usageInsideDeleted; - if (!anyRefs) { - HashMap> methodToReferences = new HashMap>(); - for (PsiMethod overridingMethod : overridingMethods) { - final Collection overridingReferences = ReferencesSearch.search(overridingMethod).findAll(); - methodToReferences.put(overridingMethod, overridingReferences); + final HashMap> methodToReferences = new HashMap>(); + for (PsiMethod overridingMethod : overridingMethods) { + final Collection overridingReferences = ReferencesSearch.search(overridingMethod).findAll(); + methodToReferences.put(overridingMethod, overridingReferences); + } + final Set validOverriding = + validateOverridingMethods(psiMethod, references, Arrays.asList(overridingMethods), methodToReferences, usages, + allElementsToDelete); + return new Condition() { + public boolean value(PsiElement usage) { + if(usage instanceof PsiFile) return false; + return isInside(usage, allElementsToDelete) || isInside(usage, validOverriding); } - final Set validOverriding = - validateOverridingMethods(psiMethod, references, Arrays.asList(overridingMethods), methodToReferences, usages, - allElementsToDelete); - usageInsideDeleted = new Condition() { - 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) { diff --git a/java/java-tests/testData/refactoring/safeDelete/removeOverridersInspiteOfUnsafeUsages/after/A.java b/java/java-tests/testData/refactoring/safeDelete/removeOverridersInspiteOfUnsafeUsages/after/A.java new file mode 100644 index 000000000000..e9c798d8da7d --- /dev/null +++ b/java/java-tests/testData/refactoring/safeDelete/removeOverridersInspiteOfUnsafeUsages/after/A.java @@ -0,0 +1,9 @@ +public class A { + void foo() { + bar(); + } + + } + +class B extends A { + } \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/safeDelete/removeOverridersInspiteOfUnsafeUsages/before/A.java b/java/java-tests/testData/refactoring/safeDelete/removeOverridersInspiteOfUnsafeUsages/before/A.java new file mode 100644 index 000000000000..fb2a6c146c14 --- /dev/null +++ b/java/java-tests/testData/refactoring/safeDelete/removeOverridersInspiteOfUnsafeUsages/before/A.java @@ -0,0 +1,13 @@ +public class A { + void foo() { + bar(); + } + + void bar() {} +} + +class B extends A { + void bar(){ + super.bar(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/SafeDeleteTest.java b/java/java-tests/testSrc/com/intellij/refactoring/SafeDeleteTest.java index 58c5de5c4615..6aa8177e3726 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/SafeDeleteTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/SafeDeleteTest.java @@ -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 { diff --git a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java index e23f0549a2c6..0e914e3aadff 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java @@ -465,11 +465,21 @@ public abstract class BaseRefactoringProcessor { } public static class ConflictsInTestsException extends RuntimeException { - private final Collection messages; + private final Collection messages; - public ConflictsInTestsException(Collection messages) { - this.messages = messages; - } + private static boolean myTestIgnore = false; + + public ConflictsInTestsException(Collection messages) { + this.messages = messages; + } + + public static void setTestIgnore(boolean myIgnore) { + myTestIgnore = myIgnore; + } + + public static boolean isTestIgnore() { + return myTestIgnore; + } public Collection getMessages() { List result = new ArrayList(messages); 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 6ff420c02420..c5e862a57606 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteProcessor.java @@ -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);