Class CheckReturnValue
- java.lang.Object
-
- com.google.errorprone.bugpatterns.BugChecker
-
- com.google.errorprone.bugpatterns.AbstractReturnValueIgnored
-
- com.google.errorprone.bugpatterns.CheckReturnValue
-
- All Implemented Interfaces:
BugChecker.ClassTreeMatcher
,BugChecker.MemberReferenceTreeMatcher
,BugChecker.MethodInvocationTreeMatcher
,BugChecker.MethodTreeMatcher
,BugChecker.NewClassTreeMatcher
,BugChecker.ReturnTreeMatcher
,ResultUsePolicyAnalyzer<com.sun.source.tree.ExpressionTree,VisitorState>
,Suppressible
,Serializable
public class CheckReturnValue extends AbstractReturnValueIgnored implements BugChecker.MethodTreeMatcher, BugChecker.ClassTreeMatcher
- Author:
- [email protected] (Eddie Aftandilian)
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.errorprone.bugpatterns.BugChecker
BugChecker.AnnotatedTypeTreeMatcher, BugChecker.AnnotationTreeMatcher, BugChecker.ArrayAccessTreeMatcher, BugChecker.ArrayTypeTreeMatcher, BugChecker.AssertTreeMatcher, BugChecker.AssignmentTreeMatcher, BugChecker.BinaryTreeMatcher, BugChecker.BlockTreeMatcher, BugChecker.BreakTreeMatcher, BugChecker.CaseTreeMatcher, BugChecker.CatchTreeMatcher, BugChecker.ClassTreeMatcher, BugChecker.CompilationUnitTreeMatcher, BugChecker.CompoundAssignmentTreeMatcher, BugChecker.ConditionalExpressionTreeMatcher, BugChecker.ContinueTreeMatcher, BugChecker.DoWhileLoopTreeMatcher, BugChecker.EmptyStatementTreeMatcher, BugChecker.EnhancedForLoopTreeMatcher, BugChecker.ExpressionStatementTreeMatcher, BugChecker.ForLoopTreeMatcher, BugChecker.IdentifierTreeMatcher, BugChecker.IfTreeMatcher, BugChecker.ImportTreeMatcher, BugChecker.InstanceOfTreeMatcher, BugChecker.IntersectionTypeTreeMatcher, BugChecker.LabeledStatementTreeMatcher, BugChecker.LambdaExpressionTreeMatcher, BugChecker.LiteralTreeMatcher, BugChecker.MemberReferenceTreeMatcher, BugChecker.MemberSelectTreeMatcher, BugChecker.MethodInvocationTreeMatcher, BugChecker.MethodTreeMatcher, BugChecker.ModifiersTreeMatcher, BugChecker.NewArrayTreeMatcher, BugChecker.NewClassTreeMatcher, BugChecker.ParameterizedTypeTreeMatcher, BugChecker.ParenthesizedTreeMatcher, BugChecker.PrimitiveTypeTreeMatcher, BugChecker.ReturnTreeMatcher, BugChecker.SuppressibleTreePathScanner<A extends Object,B extends Object>, BugChecker.SwitchTreeMatcher, BugChecker.SynchronizedTreeMatcher, BugChecker.ThrowTreeMatcher, BugChecker.TryTreeMatcher, BugChecker.TypeCastTreeMatcher, BugChecker.TypeParameterTreeMatcher, BugChecker.UnaryTreeMatcher, BugChecker.UnionTypeTreeMatcher, BugChecker.VariableTreeMatcher, BugChecker.WhileLoopTreeMatcher, BugChecker.WildcardTreeMatcher
-
-
Field Summary
Fields Modifier and Type Field Description static String
CHECK_ALL_CONSTRUCTORS
static String
CHECK_ALL_METHODS
-
Constructor Summary
Constructors Constructor Description CheckReturnValue(ErrorProneFlags flags)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Description
describeReturnValueIgnored(com.sun.source.tree.MemberReferenceTree tree, VisitorState state)
Uses the default description for results ignored via a method reference.protected Description
describeReturnValueIgnored(com.sun.source.tree.MethodInvocationTree tree, VisitorState state)
Fixes the error by assigning the result of the call to the receiver reference, or deleting the method call.protected Description
describeReturnValueIgnored(com.sun.source.tree.NewClassTree tree, VisitorState state)
Uses the default description for results ignored via a constructor call.com.google.common.collect.ImmutableMap<String,?>
getMatchMetadata(com.sun.source.tree.ExpressionTree tree, VisitorState state)
Returns a map of optional metadata about why this check matched the given expression.ResultUsePolicy
getMethodPolicy(com.sun.source.tree.ExpressionTree expression, VisitorState state)
Returns theResultUsePolicy
for the method used in the givenexpression
.boolean
isCovered(com.sun.source.tree.ExpressionTree tree, VisitorState state)
Returns whether this checker makes any determination about whether the given expression's return value should be used or not.Description
matchClass(com.sun.source.tree.ClassTree tree, VisitorState state)
Validate that at most one ofCheckReturnValue
andCanIgnoreReturnValue
are applied to a class (or interface or enum).Description
matchMethod(com.sun.source.tree.MethodTree tree, VisitorState state)
Validate@CheckReturnValue
andCanIgnoreReturnValue
usage on methods.Matcher<com.sun.source.tree.ExpressionTree>
specializedMatcher()
Return a matcher for method invocations in which the method being called should be considered must-be-used.-
Methods inherited from class com.google.errorprone.bugpatterns.AbstractReturnValueIgnored
allowInExceptionThrowers, getMessage, lostType, lostTypeMessage, matchMemberReference, matchMethodInvocation, matchNewClass, matchReturn
-
Methods inherited from class com.google.errorprone.bugpatterns.BugChecker
allNames, buildDescription, buildDescription, buildDescription, canonicalName, customSuppressionAnnotations, defaultSeverity, describeMatch, describeMatch, describeMatch, describeMatch, describeMatch, describeMatch, disableable, equals, hashCode, isSuppressed, isSuppressed, isSuppressed, isSuppressed, linkUrl, message, supportsSuppressWarnings, suppressedByAnyOf, suppressedRegions
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.errorprone.bugpatterns.checkreturnvalue.ResultUsePolicyAnalyzer
allNames, canonicalName
-
Methods inherited from interface com.google.errorprone.matchers.Suppressible
allNames, canonicalName, customSuppressionAnnotations, supportsSuppressWarnings, suppressedByAnyOf
-
-
-
-
Field Detail
-
CHECK_ALL_CONSTRUCTORS
public static final String CHECK_ALL_CONSTRUCTORS
- See Also:
- Constant Field Values
-
CHECK_ALL_METHODS
public static final String CHECK_ALL_METHODS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CheckReturnValue
@Inject public CheckReturnValue(ErrorProneFlags flags)
-
-
Method Detail
-
specializedMatcher
public Matcher<com.sun.source.tree.ExpressionTree> specializedMatcher()
Return a matcher for method invocations in which the method being called should be considered must-be-used.- Specified by:
specializedMatcher
in classAbstractReturnValueIgnored
-
getMethodPolicy
public ResultUsePolicy getMethodPolicy(com.sun.source.tree.ExpressionTree expression, VisitorState state)
Description copied from interface:ResultUsePolicyAnalyzer
Returns theResultUsePolicy
for the method used in the givenexpression
.- Specified by:
getMethodPolicy
in interfaceResultUsePolicyAnalyzer<com.sun.source.tree.ExpressionTree,VisitorState>
- Overrides:
getMethodPolicy
in classAbstractReturnValueIgnored
-
isCovered
public boolean isCovered(com.sun.source.tree.ExpressionTree tree, VisitorState state)
Description copied from interface:ResultUsePolicyAnalyzer
Returns whether this checker makes any determination about whether the given expression's return value should be used or not. Most checkers either determine that an expression is CRV or make no determination.- Specified by:
isCovered
in interfaceResultUsePolicyAnalyzer<com.sun.source.tree.ExpressionTree,VisitorState>
- Overrides:
isCovered
in classAbstractReturnValueIgnored
-
getMatchMetadata
public com.google.common.collect.ImmutableMap<String,?> getMatchMetadata(com.sun.source.tree.ExpressionTree tree, VisitorState state)
Description copied from interface:ResultUsePolicyAnalyzer
Returns a map of optional metadata about why this check matched the given expression.- Specified by:
getMatchMetadata
in interfaceResultUsePolicyAnalyzer<com.sun.source.tree.ExpressionTree,VisitorState>
-
matchMethod
public Description matchMethod(com.sun.source.tree.MethodTree tree, VisitorState state)
Validate@CheckReturnValue
andCanIgnoreReturnValue
usage on methods.The annotations should not both be applied to the same method.
The annotations should not be applied to void-returning methods. Doing so makes no sense, because there is no return value to check.
- Specified by:
matchMethod
in interfaceBugChecker.MethodTreeMatcher
-
matchClass
public Description matchClass(com.sun.source.tree.ClassTree tree, VisitorState state)
Validate that at most one ofCheckReturnValue
andCanIgnoreReturnValue
are applied to a class (or interface or enum).- Specified by:
matchClass
in interfaceBugChecker.ClassTreeMatcher
-
describeReturnValueIgnored
protected Description describeReturnValueIgnored(com.sun.source.tree.MethodInvocationTree tree, VisitorState state)
Description copied from class:AbstractReturnValueIgnored
Fixes the error by assigning the result of the call to the receiver reference, or deleting the method call. Subclasses may override if they prefer a different description.- Overrides:
describeReturnValueIgnored
in classAbstractReturnValueIgnored
-
describeReturnValueIgnored
protected Description describeReturnValueIgnored(com.sun.source.tree.NewClassTree tree, VisitorState state)
Description copied from class:AbstractReturnValueIgnored
Uses the default description for results ignored via a constructor call. Subclasses may override if they prefer a different description.- Overrides:
describeReturnValueIgnored
in classAbstractReturnValueIgnored
-
describeReturnValueIgnored
protected Description describeReturnValueIgnored(com.sun.source.tree.MemberReferenceTree tree, VisitorState state)
Description copied from class:AbstractReturnValueIgnored
Uses the default description for results ignored via a method reference. Subclasses may override if they prefer a different description.- Overrides:
describeReturnValueIgnored
in classAbstractReturnValueIgnored
-
-