Search in sources :

Example 1 with CatchClause

use of com.google.devtools.j2objc.ast.CatchClause in project j2objc by google.

the class StatementGenerator method visit.

@Override
public boolean visit(TryStatement node) {
    List<VariableDeclarationExpression> resources = node.getResources();
    boolean hasResources = !resources.isEmpty();
    boolean extendedTryWithResources = hasResources && (!node.getCatchClauses().isEmpty() || node.getFinally() != null);
    if (hasResources && !extendedTryWithResources) {
        printBasicTryWithResources(node.getBody(), resources);
        return false;
    }
    buffer.append("@try ");
    if (extendedTryWithResources) {
        // Put resources inside the body of this statement (JSL 14.20.3.2).
        printBasicTryWithResources(node.getBody(), resources);
    } else {
        node.getBody().accept(this);
    }
    buffer.append(' ');
    for (CatchClause cc : node.getCatchClauses()) {
        if (cc.getException().getType() instanceof UnionType) {
            printMultiCatch(cc);
        } else {
            buffer.append("@catch (");
            cc.getException().accept(this);
            buffer.append(") {\n");
            printStatements(cc.getBody().getStatements());
            buffer.append("}\n");
        }
    }
    if (node.getFinally() != null) {
        buffer.append(" @finally {\n");
        printStatements(node.getFinally().getStatements());
        buffer.append("}\n");
    }
    return false;
}
Also used : UnionType(com.google.devtools.j2objc.ast.UnionType) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) CatchClause(com.google.devtools.j2objc.ast.CatchClause)

Example 2 with CatchClause

use of com.google.devtools.j2objc.ast.CatchClause in project j2objc by google.

the class NilCheckResolver method visit.

@Override
public boolean visit(TryStatement node) {
    pushTryScope();
    for (VariableDeclarationExpression resource : node.getResources()) {
        resource.accept(this);
    }
    node.getBody().accept(this);
    popAndMerge();
    pushScope();
    for (CatchClause catchClause : node.getCatchClauses()) {
        scope.mergeDownAndReset();
        catchClause.accept(this);
    }
    popAndMerge();
    Block finallyBlock = node.getFinally();
    if (finallyBlock != null) {
        finallyBlock.accept(this);
    }
    return false;
}
Also used : VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) Block(com.google.devtools.j2objc.ast.Block) CatchClause(com.google.devtools.j2objc.ast.CatchClause)

Aggregations

CatchClause (com.google.devtools.j2objc.ast.CatchClause)2 VariableDeclarationExpression (com.google.devtools.j2objc.ast.VariableDeclarationExpression)2 Block (com.google.devtools.j2objc.ast.Block)1 UnionType (com.google.devtools.j2objc.ast.UnionType)1