Search in sources :

Example 21 with Statement

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

the class StatementGenerator method visit.

@Override
public boolean visit(SwitchStatement node) {
    Expression expr = node.getExpression();
    buffer.append("switch (");
    expr.accept(this);
    buffer.append(") ");
    buffer.append("{\n");
    buffer.indent();
    for (Statement stmt : node.getStatements()) {
        buffer.printIndent();
        stmt.accept(this);
    }
    buffer.unindent();
    buffer.printIndent();
    buffer.append("}\n");
    return false;
}
Also used : LambdaExpression(com.google.devtools.j2objc.ast.LambdaExpression) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) NativeExpression(com.google.devtools.j2objc.ast.NativeExpression) CommaExpression(com.google.devtools.j2objc.ast.CommaExpression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) ExpressionStatement(com.google.devtools.j2objc.ast.ExpressionStatement) 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) NativeStatement(com.google.devtools.j2objc.ast.NativeStatement) AssertStatement(com.google.devtools.j2objc.ast.AssertStatement) SynchronizedStatement(com.google.devtools.j2objc.ast.SynchronizedStatement) DoStatement(com.google.devtools.j2objc.ast.DoStatement) LabeledStatement(com.google.devtools.j2objc.ast.LabeledStatement) TryStatement(com.google.devtools.j2objc.ast.TryStatement) VariableDeclarationStatement(com.google.devtools.j2objc.ast.VariableDeclarationStatement) 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) EmptyStatement(com.google.devtools.j2objc.ast.EmptyStatement) SwitchStatement(com.google.devtools.j2objc.ast.SwitchStatement)

Example 22 with Statement

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

the class Rewriter method endVisit.

@Override
public void endVisit(VariableDeclarationStatement node) {
    if (options.isJDT()) {
        ListMultimap<Integer, VariableDeclarationFragment> newDeclarations = rewriteExtraDimensions(node.getFragments());
        if (newDeclarations != null) {
            List<Statement> statements = ((Block) node.getParent()).getStatements();
            int location = 0;
            while (location < statements.size() && !node.equals(statements.get(location))) {
                location++;
            }
            for (Integer dimensions : newDeclarations.keySet()) {
                List<VariableDeclarationFragment> fragments = newDeclarations.get(dimensions);
                VariableDeclarationStatement newDecl = new VariableDeclarationStatement(fragments.get(0));
                newDecl.getFragments().addAll(fragments.subList(1, fragments.size()));
                statements.add(++location, newDecl);
            }
        }
    }
}
Also used : VariableDeclarationFragment(com.google.devtools.j2objc.ast.VariableDeclarationFragment) ForStatement(com.google.devtools.j2objc.ast.ForStatement) VariableDeclarationStatement(com.google.devtools.j2objc.ast.VariableDeclarationStatement) Statement(com.google.devtools.j2objc.ast.Statement) Block(com.google.devtools.j2objc.ast.Block) VariableDeclarationStatement(com.google.devtools.j2objc.ast.VariableDeclarationStatement)

Example 23 with Statement

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

the class MethodTranslator method visitBlockStatement.

@Override
public TreeNode visitBlockStatement(BlockStatement node, Void data) {
    Block block = new Block();
    visitChildren(node, (TreeNode tn) -> block.addStatement((Statement) tn));
    return block;
}
Also used : TreeNode(com.google.devtools.j2objc.ast.TreeNode) ExpressionStatement(com.google.devtools.j2objc.ast.ExpressionStatement) ForStatement(com.google.devtools.j2objc.ast.ForStatement) EnhancedForStatement(com.google.devtools.j2objc.ast.EnhancedForStatement) BlockStatement(com.strobel.decompiler.languages.java.ast.BlockStatement) BreakStatement(com.google.devtools.j2objc.ast.BreakStatement) TryCatchStatement(com.strobel.decompiler.languages.java.ast.TryCatchStatement) ContinueStatement(com.google.devtools.j2objc.ast.ContinueStatement) IfElseStatement(com.strobel.decompiler.languages.java.ast.IfElseStatement) DoStatement(com.google.devtools.j2objc.ast.DoStatement) VariableDeclarationStatement(com.google.devtools.j2objc.ast.VariableDeclarationStatement) WhileStatement(com.google.devtools.j2objc.ast.WhileStatement) Statement(com.google.devtools.j2objc.ast.Statement) GotoStatement(com.strobel.decompiler.languages.java.ast.GotoStatement) DoWhileStatement(com.strobel.decompiler.languages.java.ast.DoWhileStatement) IfStatement(com.google.devtools.j2objc.ast.IfStatement) ReturnStatement(com.google.devtools.j2objc.ast.ReturnStatement) ForEachStatement(com.strobel.decompiler.languages.java.ast.ForEachStatement) Block(com.google.devtools.j2objc.ast.Block)

Example 24 with Statement

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

the class TypeImplementationGenerator method printInitializeMethod.

private void printInitializeMethod() {
    List<Statement> initStatements = typeNode.getClassInitStatements();
    if (initStatements.isEmpty()) {
        return;
    }
    StringBuilder sb = new StringBuilder();
    sb.append("{\nif (self == [" + typeName + " class]) {\n");
    for (Statement statement : initStatements) {
        sb.append(generateStatement(statement));
    }
    sb.append("J2OBJC_SET_INITIALIZED(" + typeName + ")\n");
    sb.append("}\n}");
    print("\n+ (void)initialize " + reindent(sb.toString()) + "\n");
}
Also used : Statement(com.google.devtools.j2objc.ast.Statement)

Example 25 with Statement

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

the class ClassFileConverter method convertClassInitializer.

/**
 * The clinit method isn't converted into a member element by javac,
 * so extract it separately from the classfile.
 */
private void convertClassInitializer(AbstractTypeDeclaration typeDecl) {
    EntityDeclaration decl = classFile.getMethod("<clinit>", "()V");
    if (decl == null) {
        // Class doesn't have a static initializer.
        return;
    }
    MethodTranslator translator = new MethodTranslator(parserEnv, translationEnv, null, typeDecl, null);
    Block block = (Block) decl.acceptVisitor(translator, null);
    for (Statement stmt : block.getStatements()) {
        typeDecl.addClassInitStatement(stmt.copy());
    }
}
Also used : EntityDeclaration(com.strobel.decompiler.languages.java.ast.EntityDeclaration) Statement(com.google.devtools.j2objc.ast.Statement) Block(com.google.devtools.j2objc.ast.Block)

Aggregations

Statement (com.google.devtools.j2objc.ast.Statement)40 ExpressionStatement (com.google.devtools.j2objc.ast.ExpressionStatement)23 ForStatement (com.google.devtools.j2objc.ast.ForStatement)22 VariableDeclarationStatement (com.google.devtools.j2objc.ast.VariableDeclarationStatement)22 Block (com.google.devtools.j2objc.ast.Block)21 IfStatement (com.google.devtools.j2objc.ast.IfStatement)20 WhileStatement (com.google.devtools.j2objc.ast.WhileStatement)17 EnhancedForStatement (com.google.devtools.j2objc.ast.EnhancedForStatement)15 ReturnStatement (com.google.devtools.j2objc.ast.ReturnStatement)15 SwitchStatement (com.google.devtools.j2objc.ast.SwitchStatement)15 DoStatement (com.google.devtools.j2objc.ast.DoStatement)14 BreakStatement (com.google.devtools.j2objc.ast.BreakStatement)13 ThrowStatement (com.google.devtools.j2objc.ast.ThrowStatement)13 Expression (com.google.devtools.j2objc.ast.Expression)12 LabeledStatement (com.google.devtools.j2objc.ast.LabeledStatement)12 SimpleName (com.google.devtools.j2objc.ast.SimpleName)12 EmptyStatement (com.google.devtools.j2objc.ast.EmptyStatement)11 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)11 VariableElement (javax.lang.model.element.VariableElement)11 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)9