mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
rename: show conflict if renamed method erased signature would conflict with existing method (IDEA-111875)
This commit is contained in:
@@ -24,6 +24,8 @@ import com.intellij.lang.findUsages.DescriptiveNameUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.FileContextUtil;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.psi.util.MethodSignature;
|
||||
import com.intellij.psi.util.MethodSignatureUtil;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
@@ -59,9 +61,19 @@ public class ConflictsUtil {
|
||||
final PsiMethod prototype,
|
||||
final MultiMap<PsiElement,String> conflicts) {
|
||||
if (prototype == null) return;
|
||||
final String protoMethodInfo = getMethodPrototypeString(prototype);
|
||||
String protoMethodInfo = getMethodPrototypeString(prototype);
|
||||
|
||||
PsiMethod method = aClass != null ? aClass.findMethodBySignature(prototype, true) : null;
|
||||
if (method == null && aClass != null) {
|
||||
final MethodSignature signature = prototype.getSignature(PsiSubstitutor.EMPTY);
|
||||
for (PsiMethod classMethod : aClass.getMethods()) {
|
||||
if (MethodSignatureUtil.areSignaturesErasureEqual(signature, classMethod.getSignature(PsiSubstitutor.EMPTY))) {
|
||||
method = classMethod;
|
||||
protoMethodInfo = "with same erasure";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (method != null && method != refactoredMethod) {
|
||||
if (aClass.equals(method.getContainingClass())) {
|
||||
@@ -69,7 +81,7 @@ public class ConflictsUtil {
|
||||
RefactoringBundle.message("current.class") :
|
||||
RefactoringUIUtil.getDescription(aClass, false);
|
||||
conflicts.putValue(method, RefactoringBundle.message("method.0.is.already.defined.in.the.1",
|
||||
getMethodPrototypeString(prototype),
|
||||
protoMethodInfo,
|
||||
classDescr));
|
||||
}
|
||||
else { // method somewhere in base class
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class RenameTest<T> {
|
||||
void f<caret>oo(T t) {
|
||||
}
|
||||
|
||||
void foo1(Object t) {
|
||||
}
|
||||
}
|
||||
@@ -167,6 +167,17 @@ public class RenameCollisionsTest extends LightRefactoringTestCase {
|
||||
fail("Conflicts were not found");
|
||||
}
|
||||
|
||||
public void testRenameMethodCollisionSameSignature() throws Exception {
|
||||
try {
|
||||
doTest("foo1");
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
Assert.assertEquals("Method with same erasure is already defined in the class <b><code>RenameTest</code></b>.", e.getMessage());
|
||||
return;
|
||||
}
|
||||
fail("Conflicts were not found");
|
||||
}
|
||||
|
||||
public void testRenameMethodNoCollisionWithOtherSignature() throws Exception {
|
||||
doTest("foo2");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user