ForbidCertainMethodCheck extends AbstractCheck { @Override public void visitToken(DetailAST ast) { if (ast.getType() == TokenTypes.METHOD_CALL) { final DetailAST dot = ast.getFirstChild(); final String methodNameInCode; if (dot.getType() == TokenTypes.IDENT) { methodNameInCode = dot.getText(); } else { methodNameInCode = dot.getLastChild().getText(); } final int numArgsInCode = getMethodCallParameterCount(ast); if (isForbiddenMethod(methodNameInCode, numArgsInCode)) { log(ast, MSG_KEY, methodNameInCode, methodName, numArgsInCode, argumentCount); } } else { SevntuUtil.reportInvalidToken(ast.getType()); } }  void setMethodName(String methodName); void setArgumentCount(String argumentCount); @Override int[] getDefaultTokens(); @Override int[] getAcceptableTokens(); @Override int[] getRequiredTokens(); @Override void visitToken(DetailAST ast); static final String MSG_KEY; }
@Test public void testUnsupportedToken() { final DetailAstImpl sync = new DetailAstImpl(); sync.setType(TokenTypes.LITERAL_SYNCHRONIZED); try { final ForbidCertainMethodCheck check = new ForbidCertainMethodCheck(); check.visitToken(sync); Assert.fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException ex) { Assert.assertEquals("Found unsupported token: LITERAL_SYNCHRONIZED", ex.getMessage()); } }