use of com.google.devtools.j2objc.ast.Block in project j2objc by google.
the class Functionizer method setFunctionCaller.
/**
* Replace method block statements with single statement that invokes function.
*/
private void setFunctionCaller(MethodDeclaration method, ExecutableElement methodElement) {
TypeMirror returnType = methodElement.getReturnType();
TypeElement declaringClass = ElementUtil.getDeclaringClass(methodElement);
Block body = new Block();
method.setBody(body);
method.removeModifiers(Modifier.NATIVE);
List<Statement> stmts = body.getStatements();
FunctionInvocation invocation = new FunctionInvocation(newFunctionElement(methodElement), returnType);
List<Expression> args = invocation.getArguments();
if (!ElementUtil.isStatic(methodElement)) {
args.add(new ThisExpression(declaringClass.asType()));
}
for (SingleVariableDeclaration param : method.getParameters()) {
args.add(new SimpleName(param.getVariableElement()));
}
if (TypeUtil.isVoid(returnType)) {
stmts.add(new ExpressionStatement(invocation));
if (ElementUtil.isConstructor(methodElement)) {
stmts.add(new ReturnStatement(new ThisExpression(declaringClass.asType())));
}
} else {
stmts.add(new ReturnStatement(invocation));
}
}
use of com.google.devtools.j2objc.ast.Block in project j2objc by google.
the class MetadataWriter method visitType.
private void visitType(AbstractTypeDeclaration node) {
TypeElement type = node.getTypeElement();
if (!translationUtil.needsReflection(type)) {
return;
}
ExecutableElement metadataElement = GeneratedExecutableElement.newMethodWithSelector("__metadata", CLASS_INFO_TYPE, type).addModifiers(Modifier.STATIC, Modifier.PRIVATE);
MethodDeclaration metadataDecl = new MethodDeclaration(metadataElement);
metadataDecl.setHasDeclaration(false);
Block body = new Block();
metadataDecl.setBody(body);
new MetadataGenerator(node, body.getStatements()).generateClassMetadata();
node.addBodyDeclaration(metadataDecl);
}
use of com.google.devtools.j2objc.ast.Block in project j2objc by google.
the class NilCheckResolver method visit.
@Override
public boolean visit(MethodDeclaration node) {
Block body = node.getBody();
if (body != null) {
pushFirstScope();
body.accept(this);
popLastScope();
}
return false;
}
use of com.google.devtools.j2objc.ast.Block in project j2objc by google.
the class NilCheckResolver method visit.
@Override
public boolean visit(TryStatement node) {
pushTryScope();
for (VariableDeclarationExpression resource : node.getResources()) {
resource.accept(this);
}
node.getBody().accept(this);
popAndMerge();
pushScope();
for (CatchClause catchClause : node.getCatchClauses()) {
scope.mergeDownAndReset();
catchClause.accept(this);
}
popAndMerge();
Block finallyBlock = node.getFinally();
if (finallyBlock != null) {
finallyBlock.accept(this);
}
return false;
}
use of com.google.devtools.j2objc.ast.Block in project j2objc by google.
the class EnhancedForRewriter method makeBlock.
private Block makeBlock(Statement stmt) {
if (stmt instanceof Block) {
return (Block) stmt;
}
Block block = new Block();
if (stmt.getParent() != null) {
stmt.replaceWith(block);
}
block.addStatement(stmt);
return block;
}
Aggregations