Class AbstractReturnValueIgnored
- java.lang.Object
-
- com.google.errorprone.bugpatterns.BugChecker
-
- com.google.errorprone.bugpatterns.AbstractReturnValueIgnored
-
- All Implemented Interfaces:
BugChecker.MemberReferenceTreeMatcher
,BugChecker.MethodInvocationTreeMatcher
,BugChecker.NewClassTreeMatcher
,BugChecker.ReturnTreeMatcher
,Suppressible
,Serializable
- Direct Known Subclasses:
CheckReturnValue
,FutureReturnValueIgnored
,IgnoredPureGetter
,ProtoBuilderReturnValueIgnored
,RectIntersectReturnValueIgnored
,ReturnValueIgnored
,RxReturnValueIgnored
public abstract class AbstractReturnValueIgnored extends BugChecker implements BugChecker.MethodInvocationTreeMatcher, BugChecker.MemberReferenceTreeMatcher, BugChecker.ReturnTreeMatcher, BugChecker.NewClassTreeMatcher
An abstract base class to match API usages in which the return value is not used.In addition to regular contexts in which a return value isn't used (e.g.: the result of
String.trim()
is just ignored), this class has the capacity to determine if the result is cast in such a way as to lose important static type information.If an analysis extending this base class chooses to care about this circumstance, they can override
lostType(com.google.errorprone.VisitorState)
to define the type information they wish to keep.- 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
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractReturnValueIgnored()
protected
AbstractReturnValueIgnored(ErrorProneFlags flags)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
allowInExceptionThrowers()
Override this to return false to forbid discarding return values in testers that are testing whether an exception is thrown.protected Description
describeReturnValueIgnored(com.sun.source.tree.MemberReferenceTree memberReferenceTree, VisitorState state)
Uses the default description for results ignored via a method reference.protected Description
describeReturnValueIgnored(com.sun.source.tree.MethodInvocationTree methodInvocationTree, 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 newClassTree, 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 tree.protected String
getMessage(Name name)
Returns the diagnostic message.boolean
isCheckReturnValue(com.sun.source.tree.ExpressionTree tree, VisitorState state)
Returns whether the given tree's return value should be used according to this checker, regardless of whether or not the return value is actually used.boolean
isCovered(com.sun.source.tree.ExpressionTree tree, VisitorState state)
Returns whether this checker makes any determination about whether the given tree's return value should be used or not.protected Optional<com.sun.tools.javac.code.Type>
lostType(VisitorState state)
Check for occurrences of this type being lost, i.e.protected String
lostTypeMessage(String returnedType, String declaredReturnType)
Description
matchMemberReference(com.sun.source.tree.MemberReferenceTree tree, VisitorState state)
Description
matchMethodInvocation(com.sun.source.tree.MethodInvocationTree methodInvocationTree, VisitorState state)
Description
matchNewClass(com.sun.source.tree.NewClassTree newClassTree, VisitorState state)
Description
matchReturn(com.sun.source.tree.ReturnTree tree, VisitorState state)
Returning a type from a lambda or method that returns Object loses the type information.protected abstract Matcher<? super com.sun.source.tree.ExpressionTree>
specializedMatcher()
Match whatever additional conditions concrete subclasses want to match (a list of known side-effect-free methods, has a @CheckReturnValue annotation, etc.).-
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.matchers.Suppressible
allNames, canonicalName, customSuppressionAnnotations, supportsSuppressWarnings, suppressedByAnyOf
-
-
-
-
Constructor Detail
-
AbstractReturnValueIgnored
protected AbstractReturnValueIgnored()
-
AbstractReturnValueIgnored
protected AbstractReturnValueIgnored(ErrorProneFlags flags)
-
-
Method Detail
-
matchMethodInvocation
public Description matchMethodInvocation(com.sun.source.tree.MethodInvocationTree methodInvocationTree, VisitorState state)
- Specified by:
matchMethodInvocation
in interfaceBugChecker.MethodInvocationTreeMatcher
-
matchNewClass
public Description matchNewClass(com.sun.source.tree.NewClassTree newClassTree, VisitorState state)
- Specified by:
matchNewClass
in interfaceBugChecker.NewClassTreeMatcher
-
matchMemberReference
public Description matchMemberReference(com.sun.source.tree.MemberReferenceTree tree, VisitorState state)
- Specified by:
matchMemberReference
in interfaceBugChecker.MemberReferenceTreeMatcher
-
isCovered
public boolean isCovered(com.sun.source.tree.ExpressionTree tree, VisitorState state)
Returns whether this checker makes any determination about whether the given tree's return value should be used or not. Most checkers either determine that an expression is CRV or make no determination.
-
isCheckReturnValue
public final boolean isCheckReturnValue(com.sun.source.tree.ExpressionTree tree, VisitorState state)
Returns whether the given tree's return value should be used according to this checker, regardless of whether or not the return value is actually used.
-
getMatchMetadata
public 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 tree.
-
specializedMatcher
protected abstract Matcher<? super com.sun.source.tree.ExpressionTree> specializedMatcher()
Match whatever additional conditions concrete subclasses want to match (a list of known side-effect-free methods, has a @CheckReturnValue annotation, etc.).
-
lostType
protected Optional<com.sun.tools.javac.code.Type> lostType(VisitorState state)
Check for occurrences of this type being lost, i.e. cast toObject
.
-
allowInExceptionThrowers
protected boolean allowInExceptionThrowers()
Override this to return false to forbid discarding return values in testers that are testing whether an exception is thrown.
-
describeReturnValueIgnored
protected Description describeReturnValueIgnored(com.sun.source.tree.MethodInvocationTree methodInvocationTree, VisitorState state)
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.
-
describeReturnValueIgnored
protected Description describeReturnValueIgnored(com.sun.source.tree.MemberReferenceTree memberReferenceTree, VisitorState state)
Uses the default description for results ignored via a method reference. Subclasses may override if they prefer a different description.
-
describeReturnValueIgnored
protected Description describeReturnValueIgnored(com.sun.source.tree.NewClassTree newClassTree, VisitorState state)
Uses the default description for results ignored via a constructor call. Subclasses may override if they prefer a different description.
-
getMessage
protected String getMessage(Name name)
Returns the diagnostic message. Can be overridden by subclasses to provide a customized diagnostic that includes the name of the invoked method.
-
matchReturn
public Description matchReturn(com.sun.source.tree.ReturnTree tree, VisitorState state)
Returning a type from a lambda or method that returns Object loses the type information.- Specified by:
matchReturn
in interfaceBugChecker.ReturnTreeMatcher
-
-