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

The following examples show how to use com.puppycrawl.tools.checkstyle.api.TokenTypes#SLIST . 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: TableMaker.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * defines an anonymous block to enclose the scope of an else block
 *
 * @param tree the SymTabAST to process
 * @return <code>void</code>
 * @see #makeBlock(SymTabAST)
 * @see #walkTree(SymTabAST, boolean)
 */
public void makeElseBlock(SymTabAST tree) {
  if (tree.getType() == TokenTypes.SLIST) {
    BlockDef block = makeBlock(tree);
    symbolTable.pushScope( block );
    walkTree(tree, false);
    symbolTable.popScope();
  }
  else {
    walkTree(tree, false);
  }
}
 
Example 2
Source File: TableMaker.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * defines an anonymous block to enclose the scope of an else block
 *
 * @param tree the SymTabAST to process
 * @return <code>void</code>
 * @see #makeBlock(SymTabAST)
 * @see #walkTree(SymTabAST, boolean)
 */
public void makeElseBlock(SymTabAST tree) {
  if (tree.getType() == TokenTypes.SLIST) {
    BlockDef block = makeBlock(tree);
    symbolTable.pushScope( block );
    walkTree(tree, false);
    symbolTable.popScope();
  }
  else {
    walkTree(tree, false);
  }
}
 
Example 3
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 4
Source File: Resolver.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * processes a for loop and resolves references in it
 *
 * @param block the <code>BlockDef</code> to process
 */
private void handleFor(BlockDef block) {
    SymTabAST node = block.getTreeNode();

    SymTabAST body;
    SymTabAST forEach = node.findFirstToken(TokenTypes.FOR_EACH_CLAUSE);
    if (forEach == null) {
        SymTabAST init = node.findFirstToken(TokenTypes.FOR_INIT);
        // only need to handle the elist case.  if the init node is a variable
        // definition, the variable def will be handled later on in the resolution
        if (init.getFirstChild() != null) {
            if (init.getFirstChild().getType() == TokenTypes.ELIST) {
                resolveExpression(
                    (SymTabAST) (init.getFirstChild()),
                    block,
                    null,
                    true);
            }
        }

        SymTabAST cond = node.findFirstToken(TokenTypes.FOR_CONDITION);
        if (cond.getFirstChild() != null) {
            resolveExpression(
                (SymTabAST) (cond.getFirstChild()),
                block,
                null,
                true);
        }

        SymTabAST iterator = node.findFirstToken(TokenTypes.FOR_ITERATOR);
        if (iterator.getFirstChild() != null) {
            resolveExpression(
                (SymTabAST) (iterator.getFirstChild()),
                block,
                null,
                true);
        }
        body = (SymTabAST) (iterator.getNextSibling());
    }
    else {
        resolveExpression(
            (forEach.findFirstToken(TokenTypes.EXPR)),
            block,
            null,
            true);
        body = (SymTabAST) (forEach.getNextSibling());
    }
    //could be an SLIST, EXPR or an EMPTY_STAT
    if (body.getType() == TokenTypes.RPAREN) {
        body = (SymTabAST) body.getNextSibling();
    }
    if (body.getType() == TokenTypes.SLIST) {
        handleSList(body, block);
    }
    else {
        resolveExpression(body, block, null, true);
    }

}
 
Example 5
Source File: Resolver.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * processes an if statement and resolves references in it
 *
 * @param block the <code>BlockDef</code> to process
 */
private void handleIf(BlockDef block) {
    SymTabAST node = block.getTreeNode();

    SymTabAST conditional =
        (node.findFirstToken(TokenTypes.EXPR));
    resolveExpression(conditional, block, null, true);

    SymTabAST body = (SymTabAST) conditional.getNextSibling();
    // Handle Checkstyle grammar
    if (body.getType() == TokenTypes.RPAREN) {
        body = (SymTabAST) body.getNextSibling();
    }
    if (body != null) {
    	if (body.getType() == TokenTypes.SLIST) {
        	handleSList(body, block);
    	}
    	else {
        	resolveExpression(body, block, null, true);
    	}

     SymTabAST elseBody = (SymTabAST) body.getNextSibling();
     //handle Checkstyle grammar
     while ((elseBody != null)
         && (elseBody.getType() != TokenTypes.LITERAL_ELSE)) {
         elseBody = (SymTabAST) elseBody.getNextSibling();
     }
     /*
      if (elseBody != null && elseBody.getType() == TokenTypes.SLIST) {
          handleSList(elseBody, block);
      }else{
          resolveExpression(elseBody, block, null, true);
      }
      */
     if (elseBody != null) {
         elseBody = (SymTabAST) elseBody.getFirstChild();
     }
     if (elseBody != null) {
         resolveExpression(elseBody, block.getParentScope(), null, true);
     }
 }
}
 
Example 6
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 7
Source File: Resolver.java    From contribution with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * processes a for loop and resolves references in it
 *
 * @param block the <code>BlockDef</code> to process
 */
private void handleFor(BlockDef block) {
    SymTabAST node = block.getTreeNode();

    SymTabAST body;
    SymTabAST forEach = node.findFirstToken(TokenTypes.FOR_EACH_CLAUSE);
    if (forEach == null) {
        SymTabAST init = node.findFirstToken(TokenTypes.FOR_INIT);
        // only need to handle the elist case.  if the init node is a variable
        // definition, the variable def will be handled later on in the resolution
        if (init.getFirstChild() != null) {
            if (init.getFirstChild().getType() == TokenTypes.ELIST) {
                resolveExpression(
                    (SymTabAST) (init.getFirstChild()),
                    block,
                    null,
                    true);
            }
        }

        SymTabAST cond = node.findFirstToken(TokenTypes.FOR_CONDITION);
        if (cond.getFirstChild() != null) {
            resolveExpression(
                (SymTabAST) (cond.getFirstChild()),
                block,
                null,
                true);
        }

        SymTabAST iterator = node.findFirstToken(TokenTypes.FOR_ITERATOR);
        if (iterator.getFirstChild() != null) {
            resolveExpression(
                (SymTabAST) (iterator.getFirstChild()),
                block,
                null,
                true);
        }
        body = (SymTabAST) (iterator.getNextSibling());
    }
    else {
        resolveExpression(
            (forEach.findFirstToken(TokenTypes.EXPR)),
            block,
            null,
            true);
        body = (SymTabAST) (forEach.getNextSibling());
    }
    //could be an SLIST, EXPR or an EMPTY_STAT
    if (body.getType() == TokenTypes.RPAREN) {
        body = (SymTabAST) body.getNextSibling();
    }
    if (body.getType() == TokenTypes.SLIST) {
        handleSList(body, block);
    }
    else {
        resolveExpression(body, block, null, true);
    }

}
 
Example 8
Source File: Resolver.java    From contribution with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * processes an if statement and resolves references in it
 *
 * @param block the <code>BlockDef</code> to process
 */
private void handleIf(BlockDef block) {
    SymTabAST node = block.getTreeNode();

    SymTabAST conditional =
        (node.findFirstToken(TokenTypes.EXPR));
    resolveExpression(conditional, block, null, true);

    SymTabAST body = (SymTabAST) conditional.getNextSibling();
    // Handle Checkstyle grammar
    if (body.getType() == TokenTypes.RPAREN) {
        body = (SymTabAST) body.getNextSibling();
    }
    if (body != null) {
    	if (body.getType() == TokenTypes.SLIST) {
        	handleSList(body, block);
    	}
    	else {
        	resolveExpression(body, block, null, true);
    	}

     SymTabAST elseBody = (SymTabAST) body.getNextSibling();
     //handle Checkstyle grammar
     while ((elseBody != null)
         && (elseBody.getType() != TokenTypes.LITERAL_ELSE)) {
         elseBody = (SymTabAST) elseBody.getNextSibling();
     }
     /*
      if (elseBody != null && elseBody.getType() == TokenTypes.SLIST) {
          handleSList(elseBody, block);
      }else{
          resolveExpression(elseBody, block, null, true);
      }
      */
     if (elseBody != null) {
         elseBody = (SymTabAST) elseBody.getFirstChild();
     }
     if (elseBody != null) {
         resolveExpression(elseBody, block.getParentScope(), null, true);
     }
 }
}