Search in sources :

Example 86 with VariableTree

use of com.sun.source.tree.VariableTree in project j2objc by google.

the class TreeConverter method convertEnum.

private TreeNode convertEnum(ClassTree node, TreePath parent) {
    TreePath path = getTreePath(parent, node);
    TypeElement element = (TypeElement) getElement(path);
    if (ElementUtil.isAnonymous(element)) {
        return convertClassDeclaration(node, parent).setPosition(getPosition(node));
    }
    EnumDeclaration newNode = new EnumDeclaration();
    convertBodyDeclaration(node, parent, node.getModifiers(), newNode);
    newNode.setName(convertSimpleName(element, getTypeMirror(path), getNamePosition(node))).setTypeElement(element);
    for (Tree bodyDecl : node.getMembers()) {
        if (bodyDecl.getKind() == Kind.VARIABLE) {
            TreeNode var = convertVariableDeclaration((VariableTree) bodyDecl, path);
            if (var.getKind() == TreeNode.Kind.ENUM_CONSTANT_DECLARATION) {
                newNode.addEnumConstant((EnumConstantDeclaration) var);
            } else {
                newNode.addBodyDeclaration((BodyDeclaration) var);
            }
        } else if (bodyDecl.getKind() == Kind.BLOCK) {
            BlockTree javacBlock = (BlockTree) bodyDecl;
            Block block = (Block) convert(javacBlock, path);
            newNode.addBodyDeclaration(new Initializer(block, javacBlock.isStatic()));
        } else {
            newNode.addBodyDeclaration((BodyDeclaration) convert(bodyDecl, path));
        }
    }
    return newNode;
}
Also used : TreePath(com.sun.source.util.TreePath) Initializer(com.google.devtools.j2objc.ast.Initializer) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer) GeneratedTypeElement(com.google.devtools.j2objc.types.GeneratedTypeElement) TypeElement(javax.lang.model.element.TypeElement) TreeNode(com.google.devtools.j2objc.ast.TreeNode) CompoundAssignmentTree(com.sun.source.tree.CompoundAssignmentTree) LiteralTree(com.sun.source.tree.LiteralTree) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) AssignmentTree(com.sun.source.tree.AssignmentTree) TypeCastTree(com.sun.source.tree.TypeCastTree) LambdaExpressionTree(com.sun.source.tree.LambdaExpressionTree) ForLoopTree(com.sun.source.tree.ForLoopTree) InstanceOfTree(com.sun.source.tree.InstanceOfTree) ParenthesizedTree(com.sun.source.tree.ParenthesizedTree) ConditionalExpressionTree(com.sun.source.tree.ConditionalExpressionTree) MemberSelectTree(com.sun.source.tree.MemberSelectTree) ExpressionStatementTree(com.sun.source.tree.ExpressionStatementTree) ThrowTree(com.sun.source.tree.ThrowTree) BlockTree(com.sun.source.tree.BlockTree) EnhancedForLoopTree(com.sun.source.tree.EnhancedForLoopTree) ReturnTree(com.sun.source.tree.ReturnTree) ArrayTypeTree(com.sun.source.tree.ArrayTypeTree) LabeledStatementTree(com.sun.source.tree.LabeledStatementTree) UnaryTree(com.sun.source.tree.UnaryTree) VariableTree(com.sun.source.tree.VariableTree) NewClassTree(com.sun.source.tree.NewClassTree) ParameterizedTypeTree(com.sun.source.tree.ParameterizedTypeTree) BreakTree(com.sun.source.tree.BreakTree) Tree(com.sun.source.tree.Tree) ExpressionTree(com.sun.source.tree.ExpressionTree) ArrayAccessTree(com.sun.source.tree.ArrayAccessTree) AnnotatedTypeTree(com.sun.source.tree.AnnotatedTypeTree) IdentifierTree(com.sun.source.tree.IdentifierTree) CatchTree(com.sun.source.tree.CatchTree) NewArrayTree(com.sun.source.tree.NewArrayTree) ContinueTree(com.sun.source.tree.ContinueTree) CaseTree(com.sun.source.tree.CaseTree) CompilationUnitTree(com.sun.source.tree.CompilationUnitTree) SwitchTree(com.sun.source.tree.SwitchTree) PrimitiveTypeTree(com.sun.source.tree.PrimitiveTypeTree) SynchronizedTree(com.sun.source.tree.SynchronizedTree) AssertTree(com.sun.source.tree.AssertTree) StatementTree(com.sun.source.tree.StatementTree) ModifiersTree(com.sun.source.tree.ModifiersTree) WhileLoopTree(com.sun.source.tree.WhileLoopTree) AnnotationTree(com.sun.source.tree.AnnotationTree) MethodTree(com.sun.source.tree.MethodTree) BinaryTree(com.sun.source.tree.BinaryTree) ClassTree(com.sun.source.tree.ClassTree) IfTree(com.sun.source.tree.IfTree) MemberReferenceTree(com.sun.source.tree.MemberReferenceTree) JCTree(com.sun.tools.javac.tree.JCTree) DoWhileLoopTree(com.sun.source.tree.DoWhileLoopTree) TryTree(com.sun.source.tree.TryTree) BlockTree(com.sun.source.tree.BlockTree) Block(com.google.devtools.j2objc.ast.Block) BodyDeclaration(com.google.devtools.j2objc.ast.BodyDeclaration) EnumDeclaration(com.google.devtools.j2objc.ast.EnumDeclaration)

Aggregations

VariableTree (com.sun.source.tree.VariableTree)86 Tree (com.sun.source.tree.Tree)43 ClassTree (com.sun.source.tree.ClassTree)37 MethodTree (com.sun.source.tree.MethodTree)37 ExpressionTree (com.sun.source.tree.ExpressionTree)34 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)25 NewClassTree (com.sun.source.tree.NewClassTree)23 TreePath (com.sun.source.util.TreePath)23 IdentifierTree (com.sun.source.tree.IdentifierTree)22 JCTree (com.sun.tools.javac.tree.JCTree)21 MemberSelectTree (com.sun.source.tree.MemberSelectTree)19 AssignmentTree (com.sun.source.tree.AssignmentTree)17 ArrayList (java.util.ArrayList)17 BlockTree (com.sun.source.tree.BlockTree)16 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)13 Type (com.sun.tools.javac.code.Type)13 LambdaExpressionTree (com.sun.source.tree.LambdaExpressionTree)12 ReturnTree (com.sun.source.tree.ReturnTree)12 StatementTree (com.sun.source.tree.StatementTree)12 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)12