Search in sources :

Example 1 with UnionType

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

the class TreeConverter method convertUnionType.

private static TreeNode convertUnionType(org.eclipse.jdt.core.dom.UnionType node) {
    UnionType newNode = new UnionType();
    convertType(node, newNode);
    for (Object type : node.types()) {
        newNode.addType((Type) TreeConverter.convert(type));
    }
    return newNode;
}
Also used : UnionType(com.google.devtools.j2objc.ast.UnionType)

Example 2 with UnionType

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

the class StatementGenerator method visit.

@Override
public boolean visit(TryStatement node) {
    assert node.getResources().isEmpty() : "try-with-resources is handled by Rewriter.";
    buffer.append("@try ");
    node.getBody().accept(this);
    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) CatchClause(com.google.devtools.j2objc.ast.CatchClause)

Example 3 with UnionType

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

the class StatementGenerator method printMultiCatch.

private void printMultiCatch(CatchClause node) {
    SingleVariableDeclaration exception = node.getException();
    for (Type exceptionType : ((UnionType) exception.getType()).getTypes()) {
        buffer.append("@catch (");
        exceptionType.accept(this);
        buffer.append(" *");
        buffer.append(nameTable.getVariableQualifiedName(exception.getVariableElement()));
        buffer.append(") {\n");
        printStatements(node.getBody().getStatements());
        buffer.append("}\n");
    }
}
Also used : UnionType(com.google.devtools.j2objc.ast.UnionType) QualifiedType(com.google.devtools.j2objc.ast.QualifiedType) PrimitiveType(com.google.devtools.j2objc.ast.PrimitiveType) IntersectionType(com.google.devtools.j2objc.ast.IntersectionType) UnionType(com.google.devtools.j2objc.ast.UnionType) Type(com.google.devtools.j2objc.ast.Type) SimpleType(com.google.devtools.j2objc.ast.SimpleType) ArrayType(com.google.devtools.j2objc.ast.ArrayType) SingleVariableDeclaration(com.google.devtools.j2objc.ast.SingleVariableDeclaration)

Aggregations

UnionType (com.google.devtools.j2objc.ast.UnionType)3 ArrayType (com.google.devtools.j2objc.ast.ArrayType)1 CatchClause (com.google.devtools.j2objc.ast.CatchClause)1 IntersectionType (com.google.devtools.j2objc.ast.IntersectionType)1 PrimitiveType (com.google.devtools.j2objc.ast.PrimitiveType)1 QualifiedType (com.google.devtools.j2objc.ast.QualifiedType)1 SimpleType (com.google.devtools.j2objc.ast.SimpleType)1 SingleVariableDeclaration (com.google.devtools.j2objc.ast.SingleVariableDeclaration)1 Type (com.google.devtools.j2objc.ast.Type)1