use of com.google.devtools.j2objc.ast.ReturnStatement 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.ReturnStatement in project j2objc by google.
the class AnnotationRewriter method createAnnotationTypeMethod.
private MethodDeclaration createAnnotationTypeMethod(TypeElement type) {
ExecutableElement annotationTypeElement = GeneratedExecutableElement.newMethodWithSelector("annotationType", typeUtil.getJavaClass().asType(), type);
MethodDeclaration annotationTypeMethod = new MethodDeclaration(annotationTypeElement);
annotationTypeMethod.setHasDeclaration(false);
Block annotationTypeBody = new Block();
annotationTypeMethod.setBody(annotationTypeBody);
annotationTypeBody.addStatement(new ReturnStatement(new TypeLiteral(type.asType(), typeUtil)));
return annotationTypeMethod;
}
use of com.google.devtools.j2objc.ast.ReturnStatement in project j2objc by google.
the class AnnotationRewriter method createDescriptionMethod.
private MethodDeclaration createDescriptionMethod(TypeElement type) {
ExecutableElement descriptionElement = GeneratedExecutableElement.newMethodWithSelector("description", typeUtil.getJavaString().asType(), type);
MethodDeclaration descriptionMethod = new MethodDeclaration(descriptionElement);
descriptionMethod.setHasDeclaration(false);
Block descriptionBody = new Block();
descriptionMethod.setBody(descriptionBody);
descriptionBody.addStatement(new ReturnStatement(new StringLiteral("@" + elementUtil.getBinaryName(type) + "()", typeUtil)));
return descriptionMethod;
}
Aggregations