mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
java change signature: don't warn if delete parameters in hierarchy (IDEA-254255)
GitOrigin-RevId: fd8b56048348b3220d360711acdb3585bb10747a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
03d47f3c36
commit
bf1ec8868c
@@ -48,6 +48,7 @@ import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.siyeh.IntentionPowerPackBundle;
|
||||
import com.siyeh.ig.psiutils.MethodCallUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -1213,15 +1214,38 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
final PsiCodeBlock body = method.getBody();
|
||||
if (body != null) {
|
||||
final LocalSearchScope searchScope = new LocalSearchScope(body);
|
||||
final PsiMethodCallExpression superCall = getSuperCall(method, body);
|
||||
for (int i = 0; i < toRemove.length; i++) {
|
||||
if (toRemove[i] && ReferencesSearch.search(parameters[i], searchScope).findFirst() != null) {
|
||||
String paramName = StringUtil.capitalize(RefactoringUIUtil.getDescription(parameters[i], true));
|
||||
conflictDescriptions.putValue(parameters[i], JavaRefactoringBundle.message("parameter.used.in.method.body.warning", paramName));
|
||||
if (toRemove[i]) {
|
||||
for (PsiReference ref : ReferencesSearch.search(parameters[i], searchScope)) {
|
||||
if (superCall == null || !passUnchangedParameterToSuperCall(superCall, i, ref)) {
|
||||
String paramName = StringUtil.capitalize(RefactoringUIUtil.getDescription(parameters[i], true));
|
||||
conflictDescriptions.putValue(parameters[i], JavaRefactoringBundle.message("parameter.used.in.method.body.warning", paramName));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean passUnchangedParameterToSuperCall(PsiMethodCallExpression superCall, int i, PsiReference ref) {
|
||||
return ArrayUtil.find(superCall.getArgumentList().getExpressions(), PsiUtil.skipParenthesizedExprUp(ref.getElement())) == i;
|
||||
}
|
||||
|
||||
private static PsiMethodCallExpression getSuperCall(PsiMethod method, PsiCodeBlock body) {
|
||||
PsiStatement[] statements = body.getStatements();
|
||||
PsiStatement firstStmt = statements.length > 0 ? statements[0] : null;
|
||||
if (firstStmt instanceof PsiExpressionStatement) {
|
||||
PsiExpression call = ((PsiExpressionStatement)firstStmt).getExpression();
|
||||
if (call instanceof PsiMethodCallExpression &&
|
||||
MethodCallUtils.isSuperMethodCall((PsiMethodCallExpression)call, method)) {
|
||||
return (PsiMethodCallExpression)call;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void checkContract(MultiMap<PsiElement, @Nls String> conflictDescriptions, PsiMethod method, boolean override) {
|
||||
try {
|
||||
ContractConverter.convertContract(method, myChangeInfo);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
void f<caret>oo(int i) {}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
void foo(int i) {
|
||||
super.foo(i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
void foo() {}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
void foo() {
|
||||
super.foo();
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,10 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException ignored) { }
|
||||
}
|
||||
|
||||
public void testNoConflictForSuperCallDelegation() {
|
||||
doTest(null, new ParameterInfoImpl[0], false);
|
||||
}
|
||||
|
||||
public void testGenericTypes() {
|
||||
doTest(null, null, "T", method -> new ParameterInfoImpl[]{
|
||||
ParameterInfoImpl.createNew().withName("x").withType(myFactory.createTypeFromText("T", method.getParameterList())).withDefaultValue("null"),
|
||||
|
||||
Reference in New Issue
Block a user