Java 类org.mozilla.javascript.ast.TryStatement 实例源码

项目:teavm    文件:AstWriter.java   
private void print(TryStatement node) throws IOException {
    writer.append("try ");
    print(node.getTryBlock());
    for (CatchClause cc : node.getCatchClauses()) {
        writer.ws().append("catch").ws().append('(');
        print(cc.getVarName());
        if (cc.getCatchCondition() != null) {
            writer.append(" if ");
            print(cc.getCatchCondition());
        }
        writer.append(')');
        print(cc.getBody());
    }
    if (node.getFinallyBlock() != null) {
        writer.ws().append("finally ");
        print(node.getFinallyBlock());
    }
}
项目:RSTALanguageSupport    文件:JavaScriptAstParser.java   
/**
 * Extract variables from try/catch node(s)
 */
private void processTryCatchNode(Node child, CodeBlock block,
        Set<Completion> set, String entered, int offset) {
    TryStatement tryStatement = (TryStatement) child;
    if (canProcessNode(tryStatement)) {
        offset = tryStatement.getTryBlock().getAbsolutePosition()
                + tryStatement.getTryBlock().getLength();
        addCodeBlock(tryStatement.getTryBlock(), set, entered, block,
                offset);
        // iterate catch
        for (int i = 0; i < tryStatement.getCatchClauses().size(); i++) {

            CatchClause clause = tryStatement.getCatchClauses().get(i);
            if (canProcessNode(clause)) {
                offset = clause.getAbsolutePosition() + clause.getLength();
                CodeBlock catchBlock = block.getParent().addChildCodeBlock(
                        clause.getAbsolutePosition());
                catchBlock.setEndOffset(offset);
                AstNode target = clause.getVarName();

                JavaScriptVariableDeclaration dec = extractVariableFromNode(
                        target, catchBlock, offset);
                if (dec != null) {
                    dec.setTypeDeclaration(clause);
                }

                addCodeBlock(clause.getBody(), set, entered, catchBlock,
                        offset);
            }
        }
        // now sort out finally block
        if (tryStatement.getFinallyBlock() != null) {
            AstNode finallyNode = tryStatement.getFinallyBlock();
            if (canProcessNode(finallyNode)) {
                offset = finallyNode.getAbsolutePosition()
                        + finallyNode.getLength();
                CodeBlock finallyBlock = block.getParent()
                        .addChildCodeBlock(
                                tryStatement.getFinallyBlock()
                                        .getAbsolutePosition());
                addCodeBlock(finallyNode, set, entered, finallyBlock,
                        offset);
                finallyBlock.setEndOffset(offset);
            }
        }
    }
}