Search in sources :

Example 1 with Initializer

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

the class TreeConverter method convertAbstractTypeDeclaration.

private TreeNode convertAbstractTypeDeclaration(JCTree.JCClassDecl node, AbstractTypeDeclaration newNode) {
    convertBodyDeclaration(node, node.getModifiers(), newNode, node.sym);
    List<BodyDeclaration> bodyDeclarations = new ArrayList<>();
    for (JCTree bodyDecl : node.getMembers()) {
        Object member = convert(bodyDecl);
        if (member instanceof BodyDeclaration) {
            // Not true for enum constants.
            bodyDeclarations.add((BodyDeclaration) member);
        } else if (member instanceof Block) {
            JCTree.JCBlock javacBlock = (JCTree.JCBlock) bodyDecl;
            Block block = (Block) member;
            bodyDeclarations.add(new Initializer(block, javacBlock.isStatic()));
        }
    }
    return newNode.setName(convertSimpleName(node.sym, node.sym.asType(), getNamePosition(node))).setTypeElement(node.sym).setBodyDeclarations(bodyDeclarations);
}
Also used : Initializer(com.google.devtools.j2objc.ast.Initializer) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer) ArrayList(java.util.ArrayList) JCTree(com.sun.tools.javac.tree.JCTree) Block(com.google.devtools.j2objc.ast.Block) BodyDeclaration(com.google.devtools.j2objc.ast.BodyDeclaration) JavaFileObject(javax.tools.JavaFileObject)

Example 2 with Initializer

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

the class TreeConverter method convertEnum.

private TreeNode convertEnum(JCTree.JCClassDecl node) {
    if (node.sym.isAnonymous()) {
        return convertClassDeclaration(node).setPosition(getPosition(node));
    }
    EnumDeclaration newNode = (EnumDeclaration) new EnumDeclaration();
    convertBodyDeclaration(node, node.getModifiers(), newNode, node.sym);
    newNode.setName(convertSimpleName(node.sym, node.type, getNamePosition(node))).setTypeElement(node.sym);
    for (JCTree bodyDecl : node.getMembers()) {
        if (bodyDecl.getKind() == Kind.VARIABLE) {
            TreeNode var = convertVariableDeclaration((JCTree.JCVariableDecl) bodyDecl);
            if (var.getKind() == TreeNode.Kind.ENUM_CONSTANT_DECLARATION) {
                newNode.addEnumConstant((EnumConstantDeclaration) var);
            } else {
                newNode.addBodyDeclaration((BodyDeclaration) var);
            }
        } else if (bodyDecl.getKind() == Kind.BLOCK) {
            JCTree.JCBlock javacBlock = (JCTree.JCBlock) bodyDecl;
            Block block = (Block) convert(javacBlock);
            newNode.addBodyDeclaration(new Initializer(block, javacBlock.isStatic()));
        } else {
            newNode.addBodyDeclaration((BodyDeclaration) convert(bodyDecl));
        }
    }
    return newNode;
}
Also used : Initializer(com.google.devtools.j2objc.ast.Initializer) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer) TreeNode(com.google.devtools.j2objc.ast.TreeNode) JCTree(com.sun.tools.javac.tree.JCTree) Block(com.google.devtools.j2objc.ast.Block) BodyDeclaration(com.google.devtools.j2objc.ast.BodyDeclaration) EnumDeclaration(com.google.devtools.j2objc.ast.EnumDeclaration)

Example 3 with Initializer

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

the class TreeConverter method convertInitializer.

private static TreeNode convertInitializer(org.eclipse.jdt.core.dom.Initializer node) {
    Initializer newNode = new Initializer();
    convertBodyDeclaration(node, newNode);
    return newNode.setBody((Block) convert(node.getBody()));
}
Also used : Initializer(com.google.devtools.j2objc.ast.Initializer) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer)

Aggregations

ArrayInitializer (com.google.devtools.j2objc.ast.ArrayInitializer)3 Initializer (com.google.devtools.j2objc.ast.Initializer)3 Block (com.google.devtools.j2objc.ast.Block)2 BodyDeclaration (com.google.devtools.j2objc.ast.BodyDeclaration)2 JCTree (com.sun.tools.javac.tree.JCTree)2 EnumDeclaration (com.google.devtools.j2objc.ast.EnumDeclaration)1 TreeNode (com.google.devtools.j2objc.ast.TreeNode)1 ArrayList (java.util.ArrayList)1 JavaFileObject (javax.tools.JavaFileObject)1