disable unused return value for @CanIgnoreReturnValue methods

IDEA-193647
This commit is contained in:
Anna Kozlova
2018-06-14 20:35:32 +03:00
parent e4af280e6a
commit d02f19ef4d
2 changed files with 10 additions and 0 deletions
@@ -16,6 +16,7 @@
package com.intellij.codeInspection.unusedReturnValue;
import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.daemon.GroupNames;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.reference.*;
@@ -30,6 +31,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Collections;
/**
* @author max
@@ -60,6 +62,7 @@ public class UnusedReturnValue extends GlobalJavaBatchInspectionTool{
final boolean isNative = psiMethod.hasModifierProperty(PsiModifier.NATIVE);
if (refMethod.isExternalOverride() && !isNative) return null;
if (RefUtil.isImplicitRead(psiMethod)) return null;
if (canIgnoreReturnValue(psiMethod)) return null;
return new ProblemDescriptor[]{createProblemDescriptor(psiMethod, manager, processor, isNative)};
}
}
@@ -67,6 +70,12 @@ public class UnusedReturnValue extends GlobalJavaBatchInspectionTool{
return null;
}
static boolean canIgnoreReturnValue(PsiMethod psiMethod) {
return AnnotationUtil.isAnnotated(psiMethod,
Collections.singleton("com.google.errorprone.annotations.CanIgnoreReturnValue"),
AnnotationUtil.CHECK_HIERARCHY);
}
@Override
public void writeSettings(@NotNull Element node) throws WriteExternalException {
if (IGNORE_BUILDER_PATTERN) {
@@ -52,6 +52,7 @@ public class UnusedReturnValueLocalInspection extends AbstractBaseJavaLocalInspe
method.hasModifierProperty(PsiModifier.NATIVE) ||
MethodUtils.hasSuper(method) ||
RefUtil.isImplicitRead(method) ||
UnusedReturnValue.canIgnoreReturnValue(method) ||
UnusedDeclarationInspectionBase.isDeclaredAsEntryPoint(method)) return null;
final boolean[] atLeastOneUsageExists = new boolean[]{false};