Search in sources :

Example 21 with SyntheticName

use of org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName in project ceylon by eclipse.

the class AttributeDefinitionBuilder method initValueField.

/**
 * Generate the initializer statements where the field gets set to its initial value
 */
private List<JCStatement> initValueField() {
    List<JCStatement> stmts = List.<JCStatement>nil();
    JCExpression initValue = this.initialValue;
    if (initValue == null) {
        initValue = this.memoizedInitialValue;
    }
    if (initValue != null) {
        if (useJavaBox && initialValueBoxing != BoxingStrategy.JAVA) {
            SyntheticName temp = owner.naming.temp();
            JCExpression type = owner.makeJavaType(attrType, initialValueBoxing == BoxingStrategy.BOXED ? AbstractTransformer.JT_NO_PRIMITIVES : 0);
            initValue = owner.make().LetExpr(owner.makeVar(temp, type, initValue), owner.make().Conditional(owner.make().Binary(JCTree.Tag.EQ, temp.makeIdent(), owner.makeNull()), owner.makeNull(), owner.boxJavaType(owner.unboxType(temp.makeIdent(), owner.simplifyType(attrType)), owner.simplifyType(attrType))));
        }
        stmts = stmts.prepend(owner.make().Exec(owner.make().Assign(makeValueFieldAccess(), initValue)));
    }
    return stmts;
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) SyntheticName(org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName) JCStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)

Aggregations

SyntheticName (org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)21 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)20 JCStatement (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)11 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)10 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)10 Type (org.eclipse.ceylon.model.typechecker.model.Type)7 ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)6 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)6 MethodDeclaration (org.eclipse.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)5 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)5 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)5 Value (org.eclipse.ceylon.model.typechecker.model.Value)5 Function (org.eclipse.ceylon.model.typechecker.model.Function)4 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)4 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)4 Substitution (org.eclipse.ceylon.compiler.java.codegen.Naming.Substitution)3 JCPrimitiveTypeTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCPrimitiveTypeTree)3 JCVariableDecl (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl)3 JavaBeanValue (org.eclipse.ceylon.model.loader.model.JavaBeanValue)3 HasErrorException (org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException)2