Java Code Examples for com.puppycrawl.tools.checkstyle.api.TokenTypes#LITERAL_FOR

The following examples show how to use com.puppycrawl.tools.checkstyle.api.TokenTypes#LITERAL_FOR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Resolver.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * processes a <code>BlockDef</code> and resolves references in it
 *
 * @param block the <code>BlockDef</code> to process
 */
protected void handleBlock(BlockDef block) {
    SymTabAST node = block.getTreeNode();

    switch (node.getType()) {

        case TokenTypes.LITERAL_FOR :
            handleFor(block);
            break;

        case TokenTypes.LITERAL_IF :
            handleIf(block);
            break;

        case TokenTypes.LITERAL_WHILE :
            handleWhileAndSynchronized(block);
            break;

        case TokenTypes.LITERAL_DO :
            handleDoWhile(block);
            break;

        case TokenTypes.LITERAL_TRY :
        case TokenTypes.LITERAL_FINALLY :
            SymTabAST slist = node.findFirstToken(TokenTypes.SLIST);

            handleSList(slist, block);
            break;

        case TokenTypes.LITERAL_CATCH :
            handleCatch(block);
            break;

        case TokenTypes.LITERAL_SWITCH :
            handleSwitch(block);
            break;

        case TokenTypes.SLIST :
            handleSList(node, block);
            break;

        case TokenTypes.EXPR :
            resolveExpression(node, block, null, true);
            break;

        case TokenTypes.INSTANCE_INIT :
        case TokenTypes.STATIC_INIT :
            handleSList((SymTabAST) node.getFirstChild(), block);
            break;

        case TokenTypes.LITERAL_SYNCHRONIZED :
            handleWhileAndSynchronized(block);
            break;

        case TokenTypes.LITERAL_ASSERT :
            handleAssert(block);
            break;

        default :
            if (mInitialized) {
                final Log log = mLogFactory.getInstance(this.getClass());
                log.error(
                    "Unhandled block "
                        + block
                        + " of type "
                        + node.getType());
            }
    }
}
 
Example 2
Source File: Resolver.java    From contribution with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * processes a <code>BlockDef</code> and resolves references in it
 *
 * @param block the <code>BlockDef</code> to process
 */
protected void handleBlock(BlockDef block) {
    SymTabAST node = block.getTreeNode();

    switch (node.getType()) {

        case TokenTypes.LITERAL_FOR :
            handleFor(block);
            break;

        case TokenTypes.LITERAL_IF :
            handleIf(block);
            break;

        case TokenTypes.LITERAL_WHILE :
            handleWhileAndSynchronized(block);
            break;

        case TokenTypes.LITERAL_DO :
            handleDoWhile(block);
            break;

        case TokenTypes.LITERAL_TRY :
        case TokenTypes.LITERAL_FINALLY :
            SymTabAST slist = node.findFirstToken(TokenTypes.SLIST);

            handleSList(slist, block);
            break;

        case TokenTypes.LITERAL_CATCH :
            handleCatch(block);
            break;

        case TokenTypes.LITERAL_SWITCH :
            handleSwitch(block);
            break;

        case TokenTypes.SLIST :
            handleSList(node, block);
            break;

        case TokenTypes.EXPR :
            resolveExpression(node, block, null, true);
            break;

        case TokenTypes.INSTANCE_INIT :
        case TokenTypes.STATIC_INIT :
            handleSList((SymTabAST) node.getFirstChild(), block);
            break;

        case TokenTypes.LITERAL_SYNCHRONIZED :
            handleWhileAndSynchronized(block);
            break;

        case TokenTypes.LITERAL_ASSERT :
            handleAssert(block);
            break;

        default :
            if (mInitialized) {
                final Log log = mLogFactory.getInstance(this.getClass());
                log.error(
                    "Unhandled block "
                        + block
                        + " of type "
                        + node.getType());
            }
    }
}
 
Example 3
Source File: IfBracesCheck.java    From requestor with Apache License 2.0 4 votes vote down vote up
@Override
public void visitToken(DetailAST aAST) {
    final DetailAST slistAST = aAST.findFirstToken(TokenTypes.SLIST);

    if (aAST.getType() == TokenTypes.LITERAL_ELSE) {
        // If we have an else, it must have braces, except it is an "else if" (then the if must have braces).
        DetailAST ifToken = aAST.findFirstToken(TokenTypes.LITERAL_IF);

        if (ifToken == null) {
            // This is an simple else, it must have brace.
            if (slistAST == null) {
                log(aAST.getLineNo(), "ifBracesElse", aAST.getText());
            }
        } else {
            // This is an "else if", the if must have braces.
            if (ifToken.findFirstToken(TokenTypes.SLIST) == null) {
                log(aAST.getLineNo(), "ifBracesConditional", ifToken.getText(), aAST.getText() + " " + ifToken
                        .getText());
            }
        }
    } else if (aAST.getType() == TokenTypes.LITERAL_IF) {
        // If the if uses braces, nothing as to be checked.
        if (slistAST != null) {
            return;
        }

        // We have an if, we need to check if it has no conditionnal structure as direct child.
        final int[] conditionals = {
                TokenTypes.LITERAL_DO,
                TokenTypes.LITERAL_ELSE,
                TokenTypes.LITERAL_FOR,
                TokenTypes.LITERAL_IF,
                TokenTypes.LITERAL_WHILE,
                TokenTypes.LITERAL_SWITCH,
        };

        for (int conditional : conditionals) {
            DetailAST conditionalAST = aAST.findFirstToken(conditional);

            if (conditionalAST != null) {
                log(aAST.getLineNo(), "ifBracesConditional", aAST.getText(), conditionalAST.getText());

                // Let's trigger this only once.
                return;
            }
        }
    }
}