mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IgnoreResultOfCallInspectionBase: use getMethodCallContracts (IDEA-CR-20686)
This commit is contained in:
+2
-2
@@ -1376,8 +1376,8 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
finishElement(expression);
|
||||
}
|
||||
|
||||
static List<? extends MethodContract> getMethodCallContracts(@NotNull final PsiMethod method,
|
||||
@Nullable PsiMethodCallExpression call) {
|
||||
public static List<? extends MethodContract> getMethodCallContracts(@NotNull final PsiMethod method,
|
||||
@Nullable PsiMethodCallExpression call) {
|
||||
List<MethodContract> contracts = HardcodedContracts.getHardcodedContracts(method, call);
|
||||
return !contracts.isEmpty() ? contracts : getMethodContracts(method);
|
||||
}
|
||||
|
||||
+11
-18
@@ -18,7 +18,6 @@ package com.siyeh.ig.bugs;
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInspection.dataFlow.ControlFlowAnalyzer;
|
||||
import com.intellij.codeInspection.dataFlow.MethodContract;
|
||||
import com.intellij.codeInspection.dataFlow.StandardMethodContract;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
@@ -170,23 +169,7 @@ public class IgnoreResultOfCallInspectionBase extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
|
||||
final PsiAnnotation anno = ControlFlowAnalyzer.findContractAnnotation(method);
|
||||
final boolean honorInferred = Registry.is("ide.ignore.call.result.inspection.honor.inferred.pure");
|
||||
if (anno != null &&
|
||||
(honorInferred || !AnnotationUtil.isInferredAnnotation(anno)) &&
|
||||
Boolean.TRUE.equals(AnnotationUtil.getBooleanAttributeValue(anno, "pure"))) {
|
||||
String text = AnnotationUtil.getStringAttributeValue(anno, null);
|
||||
if (text != null) {
|
||||
try {
|
||||
if (StandardMethodContract.parseContract(text).stream()
|
||||
.anyMatch(c -> c.getReturnValue() == MethodContract.ValueConstraint.THROW_EXCEPTION)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (StandardMethodContract.ParseException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (isPureMethod(method)) {
|
||||
registerMethodCallOrRefError(call, aClass);
|
||||
return;
|
||||
}
|
||||
@@ -204,6 +187,16 @@ public class IgnoreResultOfCallInspectionBase extends BaseInspection {
|
||||
registerMethodCallOrRefError(call, aClass);
|
||||
}
|
||||
|
||||
private boolean isPureMethod(PsiMethod method) {
|
||||
final PsiAnnotation anno = ControlFlowAnalyzer.findContractAnnotation(method);
|
||||
if (anno == null) return false;
|
||||
final boolean honorInferred = Registry.is("ide.ignore.call.result.inspection.honor.inferred.pure");
|
||||
if (!honorInferred && AnnotationUtil.isInferredAnnotation(anno)) return false;
|
||||
return Boolean.TRUE.equals(AnnotationUtil.getBooleanAttributeValue(anno, "pure")) &&
|
||||
ControlFlowAnalyzer.getMethodCallContracts(method, null).stream()
|
||||
.noneMatch(c -> c.getReturnValue() == MethodContract.ValueConstraint.THROW_EXCEPTION);
|
||||
}
|
||||
|
||||
private void registerMethodCallOrRefError(PsiExpression call, PsiClass aClass) {
|
||||
if (call instanceof PsiMethodCallExpression) {
|
||||
registerMethodCallError((PsiMethodCallExpression)call, aClass);
|
||||
|
||||
Reference in New Issue
Block a user