IDEA-195808 Odd warning when change parameter order of method with @Contract

This commit is contained in:
Tagir Valeev
2018-08-01 04:35:32 +07:00
parent 45899d86b6
commit da0a512e9d
2 changed files with 16 additions and 5 deletions
@@ -36,7 +36,7 @@ public final class ContractConverter {
throw new ContractConversionException("automatic update of external annotation is not supported");
}
if (annotation.getOwner() != method.getModifierList()) {
throw new ContractConversionException("annotation is inherited from base method");
throw new ContractInheritedException();
}
if (annotation.findDeclaredAttributeValue(MutationSignature.ATTR_MUTATES) != null) {
throw new ContractConversionException("it contains mutation contract");
@@ -107,9 +107,15 @@ public final class ContractConverter {
return oldToNewIndex;
}
public static final class ContractConversionException extends Exception {
public static class ContractConversionException extends Exception {
ContractConversionException(String message) {
super(message);
}
}
public static class ContractInheritedException extends ContractConversionException {
ContractInheritedException() {
super("annotation is inherited from base method");
}
}
}
@@ -1046,7 +1046,7 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
if (checkUnusedParameter) {
checkParametersToDelete(myChangeInfo.getMethod(), toRemove, conflictDescriptions);
}
checkContract(conflictDescriptions, myChangeInfo.getMethod());
checkContract(conflictDescriptions, myChangeInfo.getMethod(), false);
for (UsageInfo usageInfo : usagesSet) {
final PsiElement element = usageInfo.getElement();
@@ -1066,7 +1066,7 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
}
}
checkContract(conflictDescriptions, method);
checkContract(conflictDescriptions, method, true);
}
else if (element instanceof PsiMethodReferenceExpression && MethodReferenceUsageInfo.needToExpand(myChangeInfo)) {
conflictDescriptions.putValue(element, RefactoringBundle.message("expand.method.reference.warning"));
@@ -1105,10 +1105,15 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
}
}
private void checkContract(MultiMap<PsiElement, String> conflictDescriptions, PsiMethod method) {
private void checkContract(MultiMap<PsiElement, String> conflictDescriptions, PsiMethod method, boolean override) {
try {
ContractConverter.convertContract(method, myChangeInfo);
}
catch (ContractConverter.ContractInheritedException e) {
if (!override) {
conflictDescriptions.putValue(method, "@Contract annotation cannot be updated automatically: " + e.getMessage());
}
}
catch (ContractConverter.ContractConversionException e) {
conflictDescriptions.putValue(method, "@Contract annotation cannot be updated automatically: " + e.getMessage());
}