use of com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration in project ceylon-compiler by ceylon.
the class ClassTransformer method transformMethodBody.
private List<JCStatement> transformMethodBody(Tree.AnyMethod def) {
List<JCStatement> body = null;
final Function model = def.getDeclarationModel();
if (model.isDeferred()) {
// Uninitialized or deferred initialized method => Make a Callable field
String fieldName = naming.selector(model);
final Parameter initializingParameter = CodegenUtil.findParamForDecl(def);
int mods = PRIVATE;
JCExpression initialValue;
if (initializingParameter != null) {
mods |= FINAL;
initialValue = makeUnquotedIdent(Naming.getAliasedParameterName(initializingParameter));
} else {
// The field isn't initialized by a parameter, but later in the block
initialValue = makeNull();
}
Type callableType = model.getReference().getFullType();
current().field(mods, fieldName, makeJavaType(callableType), initialValue, false);
Invocation invocation = new CallableSpecifierInvocation(this, model, makeUnquotedIdent(fieldName), // but with deferred methods we can't define them so that they are erased so we're good
null, def);
invocation.handleBoxing(true);
JCExpression call = expressionGen().transformInvocation(invocation);
JCStatement stmt;
if (!isVoid(def) || !Decl.isUnboxedVoid(model) || Strategy.useBoxedVoid((Function) model)) {
stmt = make().Return(call);
} else {
stmt = make().Exec(call);
}
JCStatement result;
if (initializingParameter == null) {
// If the field isn't initialized by a parameter we have to
// cope with the possibility that it's never initialized
final JCBinary cond = make().Binary(JCTree.EQ, makeUnquotedIdent(fieldName), makeNull());
final JCStatement throw_ = make().Throw(make().NewClass(null, null, makeIdent(syms().ceylonUninitializedMethodErrorType), List.<JCExpression>nil(), null));
result = make().If(cond, throw_, stmt);
} else {
result = stmt;
}
return List.<JCStatement>of(result);
} else if (def instanceof Tree.MethodDefinition) {
body = transformMethodBlock((Tree.MethodDefinition) def);
} else if (def instanceof MethodDeclaration && ((MethodDeclaration) def).getSpecifierExpression() != null) {
body = transformSpecifiedMethodBody((MethodDeclaration) def, ((MethodDeclaration) def).getSpecifierExpression());
}
return body;
}
Aggregations