AvoidConditionInversionCheck extends AbstractCheck { @Override public void visitToken(DetailAST ast) { final DetailAST expressionAst = ast.findFirstToken(TokenTypes.EXPR); switch (ast.getType()) { case TokenTypes.LITERAL_RETURN: if (!isEmptyReturn(ast)) { final DetailAST inversionAst = getInversion(expressionAst); if (isAvoidableInversion(inversionAst)) { log(inversionAst); } } break; case TokenTypes.LITERAL_WHILE: case TokenTypes.LITERAL_DO: case TokenTypes.LITERAL_IF: final DetailAST invertedAst = getInversion(expressionAst); if (isAvoidableInversion(invertedAst)) { log(invertedAst); } break; case TokenTypes.FOR_CONDITION: if (!isEmptyForCondition(ast)) { final DetailAST inversionAst = getInversion(expressionAst); if (isAvoidableInversion(inversionAst)) { log(inversionAst); } } break; default: SevntuUtil.reportInvalidToken(ast.getType()); break; } }  void setApplyOnlyToRelationalOperands(boolean applyOnlyToRelationalOperands); @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 AvoidConditionInversionCheck check = new AvoidConditionInversionCheck(); check.visitToken(sync); fail("exception expected"); } catch (IllegalArgumentException ex) { Assert.assertEquals("Found unsupported token: LITERAL_SYNCHRONIZED", ex.getMessage()); } }