use of com.google.devtools.j2objc.ast.Expression 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;
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class StatementGenerator method visit.
@Override
public boolean visit(MethodInvocation node) {
ExecutableElement element = node.getExecutableElement();
assert element != null;
// Object receiving the message, or null if it's a method in this class.
Expression receiver = node.getExpression();
buffer.append('[');
if (ElementUtil.isStatic(element)) {
buffer.append(nameTable.getFullName(ElementUtil.getDeclaringClass(element)));
} else if (receiver != null) {
receiver.accept(this);
} else {
buffer.append("self");
}
printMethodInvocationNameAndArgs(nameTable.getMethodSelector(element), node.getArguments());
buffer.append(']');
return false;
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class StatementGenerator method visit.
@Override
public boolean visit(ForStatement node) {
buffer.append("for (");
for (Iterator<Expression> it = node.getInitializers().iterator(); it.hasNext(); ) {
Expression next = it.next();
next.accept(this);
if (it.hasNext()) {
buffer.append(", ");
}
}
buffer.append("; ");
if (node.getExpression() != null) {
node.getExpression().accept(this);
}
buffer.append("; ");
for (Iterator<Expression> it = node.getUpdaters().iterator(); it.hasNext(); ) {
it.next().accept(this);
if (it.hasNext()) {
buffer.append(", ");
}
}
buffer.append(") ");
node.getBody().accept(this);
return false;
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class TreeConverter method convertForLoop.
private TreeNode convertForLoop(JCTree.JCForLoop node) {
ForStatement newNode = new ForStatement().setExpression((Expression) convert(node.getCondition())).setBody((Statement) convert(node.getStatement()));
VariableDeclarationExpression lastVar = null;
for (JCTree.JCStatement initializer : node.getInitializer()) {
if (initializer.getKind() == Kind.VARIABLE) {
JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) initializer;
VariableDeclarationExpression newVar = convertVariableExpression(var);
if (lastVar == null) {
newNode.addInitializer(newVar);
lastVar = newVar;
} else {
lastVar.addFragment(TreeUtil.remove(newVar.getFragment(0)));
}
} else {
assert initializer.getKind() == Kind.EXPRESSION_STATEMENT;
newNode.addInitializer((Expression) convert(((JCTree.JCExpressionStatement) initializer).getExpression()));
}
}
for (JCTree.JCExpressionStatement updater : node.getUpdate()) {
newNode.addUpdater((Expression) convert(updater.getExpression()));
}
return newNode;
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class TreeConverter method convertAssignment.
private static TreeNode convertAssignment(org.eclipse.jdt.core.dom.Assignment node) {
Assignment newNode = new Assignment();
convertExpression(node, newNode);
return newNode.setOperator(Assignment.Operator.fromJdtOperatorName(node.getOperator().toString())).setLeftHandSide((Expression) convert(node.getLeftHandSide())).setRightHandSide((Expression) convert(node.getRightHandSide()));
}
Aggregations