Class UnusedReturnValueMatcher
java.lang.Object
com.google.errorprone.matchers.UnusedReturnValueMatcher
- All Implemented Interfaces:
Matcher<com.sun.source.tree.ExpressionTree>
,Serializable
@CheckReturnValue
public final class UnusedReturnValueMatcher
extends Object
implements Matcher<com.sun.source.tree.ExpressionTree>
Matches expressions that invoke or reference a non-void method or constructor and which do not
use their return value and are not in a context where non-use of the return value is allowed.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumeration of known reasons that an unused return value may be allowed because of the context in which the method is used. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Allow return values to be ignored in tests that expect an exception to be thrown.static UnusedReturnValueMatcher
get
(boolean allowInExceptionThrowers) Gets an instance of this matcher.getAllowReasons
(com.sun.source.tree.ExpressionTree tree, VisitorState state) Returns a stream of reasons the given expression is allowed to have an unused return value based on its context.boolean
isAllowed
(com.sun.source.tree.ExpressionTree tree, VisitorState state) Returnstrue
if the given expression is allowed to have an unused return value based on its context.static boolean
isReturnValueUnused
(com.sun.source.tree.ExpressionTree tree, VisitorState state) Returnstrue
if and only if the giventree
is an invocation of or reference to a constructor or non-void
method for which the return value is considered unused.boolean
matches
(com.sun.source.tree.ExpressionTree tree, VisitorState state) static boolean
mockitoInvocation
(com.sun.source.tree.Tree tree, VisitorState state) Don't match the method that is invoked throughMockito.verify(t)
ordoReturn(val).when(t)
.
-
Method Details
-
get
Gets an instance of this matcher. -
matches
-
isReturnValueUnused
public static boolean isReturnValueUnused(com.sun.source.tree.ExpressionTree tree, VisitorState state) Returnstrue
if and only if the giventree
is an invocation of or reference to a constructor or non-void
method for which the return value is considered unused. -
isAllowed
Returnstrue
if the given expression is allowed to have an unused return value based on its context. -
getAllowReasons
public Stream<UnusedReturnValueMatcher.AllowReason> getAllowReasons(com.sun.source.tree.ExpressionTree tree, VisitorState state) Returns a stream of reasons the given expression is allowed to have an unused return value based on its context. -
expectedExceptionTest
Allow return values to be ignored in tests that expect an exception to be thrown. -
mockitoInvocation
Don't match the method that is invoked throughMockito.verify(t)
ordoReturn(val).when(t)
.
-