Search in sources :

Example 1 with BodyDeclaration

use of com.google.devtools.j2objc.ast.BodyDeclaration 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 BodyDeclaration

use of com.google.devtools.j2objc.ast.BodyDeclaration 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 BodyDeclaration

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

the class PrivateDeclarationResolver method visit.

@Override
public boolean visit(CompilationUnit node) {
    // Map the types by their elements.
    for (AbstractTypeDeclaration typeNode : node.getTypes()) {
        typeMap.put(typeNode.getTypeElement(), typeNode);
    }
    // Identify types that are public by their declaration.
    for (AbstractTypeDeclaration typeNode : node.getTypes()) {
        TypeElement typeElement = typeNode.getTypeElement();
        if (!ElementUtil.isPrivateInnerType(typeElement)) {
            addPublicType(typeElement);
        }
    }
    // public because they are exposed by a field or method from another type.
    while (!publicNodesToVisit.isEmpty()) {
        AbstractTypeDeclaration publicNode = publicNodesToVisit.remove(publicNodesToVisit.size() - 1);
        publicNode.setHasPrivateDeclaration(false);
        for (BodyDeclaration decl : publicNode.getBodyDeclarations()) {
            decl.accept(this);
        }
    }
    // declarations as private.
    for (AbstractTypeDeclaration typeNode : node.getTypes()) {
        if (!publicTypes.contains(typeNode.getTypeElement())) {
            typeNode.setHasPrivateDeclaration(true);
            for (BodyDeclaration decl : typeNode.getBodyDeclarations()) {
                decl.setHasPrivateDeclaration(true);
            }
        }
    }
    return false;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) BodyDeclaration(com.google.devtools.j2objc.ast.BodyDeclaration) AbstractTypeDeclaration(com.google.devtools.j2objc.ast.AbstractTypeDeclaration)

Example 4 with BodyDeclaration

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

the class NilCheckResolver method visitType.

private boolean visitType(AbstractTypeDeclaration node) {
    for (BodyDeclaration decl : node.getBodyDeclarations()) {
        decl.accept(this);
    }
    pushFirstScope();
    for (Statement stmt : node.getClassInitStatements()) {
        stmt.accept(this);
    }
    popLastScope();
    return false;
}
Also used : ForStatement(com.google.devtools.j2objc.ast.ForStatement) EnhancedForStatement(com.google.devtools.j2objc.ast.EnhancedForStatement) BreakStatement(com.google.devtools.j2objc.ast.BreakStatement) ContinueStatement(com.google.devtools.j2objc.ast.ContinueStatement) ThrowStatement(com.google.devtools.j2objc.ast.ThrowStatement) DoStatement(com.google.devtools.j2objc.ast.DoStatement) LabeledStatement(com.google.devtools.j2objc.ast.LabeledStatement) TryStatement(com.google.devtools.j2objc.ast.TryStatement) WhileStatement(com.google.devtools.j2objc.ast.WhileStatement) IfStatement(com.google.devtools.j2objc.ast.IfStatement) Statement(com.google.devtools.j2objc.ast.Statement) ReturnStatement(com.google.devtools.j2objc.ast.ReturnStatement) SwitchStatement(com.google.devtools.j2objc.ast.SwitchStatement) BodyDeclaration(com.google.devtools.j2objc.ast.BodyDeclaration)

Example 5 with BodyDeclaration

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

the class AnnotationRewriter method endVisit.

@Override
public void endVisit(AnnotationTypeDeclaration node) {
    TypeElement type = node.getTypeElement();
    if (!ElementUtil.isGeneratedAnnotation(type)) {
        return;
    }
    List<AnnotationTypeMemberDeclaration> members = TreeUtil.getAnnotationMembers(node);
    List<BodyDeclaration> bodyDecls = node.getBodyDeclarations();
    Map<ExecutableElement, VariableElement> fieldElements = createMemberFields(node, members);
    addMemberProperties(node, members, fieldElements);
    addDefaultAccessors(node, members);
    bodyDecls.add(createAnnotationTypeMethod(type));
    bodyDecls.add(createDescriptionMethod(type, members, fieldElements));
    addConstructor(node, fieldElements);
    addEqualsMethod(node);
    addHashCodeMethod(node);
}
Also used : AnnotationTypeMemberDeclaration(com.google.devtools.j2objc.ast.AnnotationTypeMemberDeclaration) TypeElement(javax.lang.model.element.TypeElement) GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) BodyDeclaration(com.google.devtools.j2objc.ast.BodyDeclaration) VariableElement(javax.lang.model.element.VariableElement) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement)

Aggregations

BodyDeclaration (com.google.devtools.j2objc.ast.BodyDeclaration)18 TypeElement (javax.lang.model.element.TypeElement)9 AbstractTypeDeclaration (com.google.devtools.j2objc.ast.AbstractTypeDeclaration)6 MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)5 ExecutableElement (javax.lang.model.element.ExecutableElement)5 AnnotationTypeDeclaration (com.google.devtools.j2objc.ast.AnnotationTypeDeclaration)4 ArrayInitializer (com.google.devtools.j2objc.ast.ArrayInitializer)4 Block (com.google.devtools.j2objc.ast.Block)4 Initializer (com.google.devtools.j2objc.ast.Initializer)4 VariableElement (javax.lang.model.element.VariableElement)4 FieldDeclaration (com.google.devtools.j2objc.ast.FieldDeclaration)3 ReturnStatement (com.google.devtools.j2objc.ast.ReturnStatement)3 TypeDeclaration (com.google.devtools.j2objc.ast.TypeDeclaration)3 VariableDeclarationFragment (com.google.devtools.j2objc.ast.VariableDeclarationFragment)3 GeneratedTypeElement (com.google.devtools.j2objc.types.GeneratedTypeElement)3 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)3 JCTree (com.sun.tools.javac.tree.JCTree)3 Comment (com.google.devtools.j2objc.ast.Comment)2 CompilationUnit (com.google.devtools.j2objc.ast.CompilationUnit)2 EnumDeclaration (com.google.devtools.j2objc.ast.EnumDeclaration)2