Class 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:
  • Method Details

    • get

      public static UnusedReturnValueMatcher get(boolean allowInExceptionThrowers)
      Gets an instance of this matcher.
    • matches

      public boolean matches(com.sun.source.tree.ExpressionTree tree, VisitorState state)
      Specified by:
      matches in interface Matcher<com.sun.source.tree.ExpressionTree>
    • isReturnValueUnused

      public static boolean isReturnValueUnused(com.sun.source.tree.ExpressionTree tree, VisitorState state)
      Returns true if and only if the given tree is an invocation of or reference to a constructor or non-void method for which the return value is considered unused.
    • isAllowed

      public boolean isAllowed(com.sun.source.tree.ExpressionTree tree, VisitorState state)
      Returns true 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

      public static boolean expectedExceptionTest(VisitorState state)
      Allow return values to be ignored in tests that expect an exception to be thrown.
    • mockitoInvocation

      public static boolean mockitoInvocation(com.sun.source.tree.Tree tree, VisitorState state)
      Don't match the method that is invoked through Mockito.verify(t) or doReturn(val).when(t).