RedundantReturnCheck extends AbstractCheck { @Override public void visitToken(DetailAST ast) { final DetailAST blockAst = ast.getLastChild(); switch (ast.getType()) { case TokenTypes.CTOR_DEF: if (!ignoreLonelyReturn(blockAst) && hasNonEmptyBody(ast)) { final List<DetailAST> redundantReturns = getRedundantReturns(blockAst); log(redundantReturns); } break; case TokenTypes.METHOD_DEF: if (!ignoreLonelyReturn(blockAst) && isVoidMethodWithNonEmptyBody(ast)) { final List<DetailAST> redundantReturns = getRedundantReturns(blockAst); log(redundantReturns); } break; default: SevntuUtil.reportInvalidToken(ast.getType()); break; } }  void setAllowReturnInEmptyMethodsAndConstructors(boolean allowEmptyBlocks); @Override int[] getDefaultTokens(); @Override int[] getAcceptableTokens(); @Override int[] getRequiredTokens(); @Override void visitToken(DetailAST ast); static final String MSG_KEY; }
@Test public void testUnsupportedNode() { final DetailAstImpl sync = new DetailAstImpl(); sync.setType(TokenTypes.LITERAL_SYNCHRONIZED); try { final RedundantReturnCheck check = new RedundantReturnCheck(); check.visitToken(sync); fail("exception expected"); } catch (IllegalArgumentException ex) { Assert.assertEquals("Found unsupported token: LITERAL_SYNCHRONIZED", ex.getMessage()); } }