mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-117332 Change signature refactoring should warn about @Contract conflict
This commit is contained in:
+12
-4
@@ -17,6 +17,7 @@ package com.intellij.refactoring.changeSignature;
|
||||
|
||||
import com.intellij.codeInsight.ExceptionUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
|
||||
import com.intellij.codeInspection.dataFlow.ControlFlowAnalyzer;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -884,7 +885,7 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
private static class ConflictSearcher {
|
||||
private final JavaChangeInfo myChangeInfo;
|
||||
|
||||
private ConflictSearcher(JavaChangeInfo changeInfo) {
|
||||
private ConflictSearcher(@NotNull JavaChangeInfo changeInfo) {
|
||||
this.myChangeInfo = changeInfo;
|
||||
}
|
||||
|
||||
@@ -901,6 +902,8 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
checkContract(conflictDescriptions, myChangeInfo.getMethod());
|
||||
|
||||
for (UsageInfo usageInfo : usagesSet) {
|
||||
final PsiElement element = usageInfo.getElement();
|
||||
@@ -914,6 +917,8 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
conflictDescriptions.putValue(baseMethod, "Implicit last parameter should not be deleted");
|
||||
}
|
||||
}
|
||||
|
||||
checkContract(conflictDescriptions, method);
|
||||
} else if (element instanceof PsiMethodReferenceExpression) {
|
||||
conflictDescriptions.putValue(element, "Changed method is used in method reference");
|
||||
}
|
||||
@@ -922,6 +927,12 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
return conflictDescriptions;
|
||||
}
|
||||
|
||||
private static void checkContract(MultiMap<PsiElement, String> conflictDescriptions, PsiMethod method) {
|
||||
if (ControlFlowAnalyzer.findContractAnnotation(method) != null) {
|
||||
conflictDescriptions.putValue(method, "@Contract annotation will have to be changed manually");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean needToChangeCalls() {
|
||||
return myChangeInfo.isNameChanged() || myChangeInfo.isParameterSetOrOrderChanged() || myChangeInfo.isExceptionSetOrOrderChanged();
|
||||
}
|
||||
@@ -964,9 +975,6 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
|
||||
private void addMethodConflicts(MultiMap<PsiElement, String> conflicts) {
|
||||
String newMethodName = myChangeInfo.getNewName();
|
||||
if (!(myChangeInfo instanceof JavaChangeInfo)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
PsiMethod prototype;
|
||||
final PsiMethod method = myChangeInfo.getMethod();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class A {
|
||||
@org.jetbrains.annotations.Contract("null,_->fail")
|
||||
public int method<caret>(Object i, Object j) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,15 @@ public class ChangeSignatureTest extends LightRefactoringTestCase {
|
||||
doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1), new ParameterInfoImpl(0)}, false);
|
||||
}
|
||||
|
||||
public void testWarnAboutContract() throws Exception {
|
||||
try {
|
||||
doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1), new ParameterInfoImpl(0)}, false);
|
||||
fail("Conflict expected");
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testGenericTypes() throws Exception {
|
||||
doTest(null, null, "T", new GenParams() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user