ReturnNullInsteadOfBooleanCheck extends AbstractCheck { @Override public void visitToken(DetailAST ast) { switch (ast.getType()) { case TokenTypes.METHOD_DEF: methodStack.push(exploreMethod); final DetailAST returnTypeAST = ast .findFirstToken(TokenTypes.TYPE).getFirstChild(); exploreMethod = "Boolean".equals(returnTypeAST.getText()); break; case TokenTypes.LITERAL_RETURN: if (exploreMethod) { final DetailAST exprToken = ast .findFirstToken(TokenTypes.EXPR).getFirstChild(); if ("null".equals(exprToken.getText())) { log(ast, MSG_KEY); } } break; default: SevntuUtil.reportInvalidToken(ast.getType()); break; } }  @Override int[] getDefaultTokens(); @Override int[] getAcceptableTokens(); @Override int[] getRequiredTokens(); @Override void beginTree(DetailAST rootAST); @Override void visitToken(DetailAST ast); @Override void leaveToken(DetailAST ast); static final String MSG_KEY; }
@Test public void testUnsupportedNodeVisit() { final DetailAstImpl sync = new DetailAstImpl(); sync.setType(TokenTypes.LITERAL_SYNCHRONIZED); try { final ReturnNullInsteadOfBooleanCheck check = new ReturnNullInsteadOfBooleanCheck(); check.visitToken(sync); fail("exception expected"); } catch (IllegalArgumentException ex) { Assert.assertEquals("Found unsupported token: LITERAL_SYNCHRONIZED", ex.getMessage()); } }