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;
}
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);
}
}
}
}
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;
}
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");
}
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());
}
}
Aggregations