change signature: skip unresolvable usages on accepting refactoring with conflicts (IDEA-196340)

This commit is contained in:
Anna.Kozlova
2018-07-30 19:15:43 +02:00
parent fdaa681d78
commit 6b247492da
4 changed files with 44 additions and 2 deletions
@@ -46,6 +46,7 @@ import com.intellij.psi.util.*;
import com.intellij.refactoring.RefactoringBundle;
import com.intellij.refactoring.rename.RenameUtil;
import com.intellij.refactoring.rename.ResolveSnapshotProvider;
import com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo;
import com.intellij.refactoring.util.*;
import com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo;
import com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo;
@@ -200,7 +201,7 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
fixActualArgumentsList(((PsiEnumConstant)element).getArgumentList(), (JavaChangeInfo)changeInfo, true, PsiSubstitutor.EMPTY);
return true;
}
else if (!(usage instanceof OverriderUsageInfo)) {
else if (!(usage instanceof OverriderUsageInfo) && !(usage instanceof UnresolvableCollisionUsageInfo)) {
PsiReference reference = usage instanceof MoveRenameUsageInfo ? usage.getReference() : element.getReference();
if (reference != null) {
PsiElement target = changeInfo.getMethod();
@@ -0,0 +1,13 @@
class CallChain {
private void depth1() {
depth2("My first parameter");
}
private void depth2(String param) {
depth3();
}
private void dep<caret>th3() {
System.out.println("hello there");
}
}
@@ -0,0 +1,13 @@
class CallChain {
private void depth1() {
depth2("My first parameter");
}
private void depth2(String param, String param) {
depth3(param);
}
private void depth3(String param) {
System.out.println("hello there");
}
}
@@ -23,16 +23,17 @@ import com.intellij.psi.search.searches.ClassInheritorsSearch;
import com.intellij.psi.search.searches.MethodReferencesSearch;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.BaseRefactoringProcessor;
import com.intellij.refactoring.changeSignature.ChangeSignatureProcessor;
import com.intellij.refactoring.changeSignature.JavaThrownExceptionInfo;
import com.intellij.refactoring.changeSignature.ParameterInfoImpl;
import com.intellij.refactoring.changeSignature.ThrownExceptionInfo;
import com.intellij.refactoring.util.CanonicalTypes;
import java.util.HashSet;
import junit.framework.Assert;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
@@ -59,6 +60,20 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase {
parameterPropagationTest(method, methods, JavaPsiFacade.getElementFactory(getProject()).createTypeByFQClassName("T"));
}
public void testConflictingParameterName() {
final PsiMethod method = getPrimaryMethod();
final HashSet<PsiMethod> methods = new HashSet<>();
for (PsiReference reference : ReferencesSearch.search(method)) {
final PsiMethod psiMethod = PsiTreeUtil.getParentOfType(reference.getElement(), PsiMethod.class);
if (psiMethod != null) {
methods.add(psiMethod);
}
}
PsiClassType stringType = PsiType.getJavaLangString(getPsiManager(), GlobalSearchScope.allScope(getProject()));
final ParameterInfoImpl[] newParameters = {new ParameterInfoImpl(-1, "param", stringType)};
BaseRefactoringProcessor.ConflictsInTestsException.withIgnoredConflicts(() -> doTest(newParameters, new ThrownExceptionInfo[0], methods, null, method));
}
public void testExceptionSimple() {
exceptionPropagationTest();
}