Search in sources :

Example 1 with AttributeSetterDefinition

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeSetterDefinition in project ceylon by eclipse.

the class GenerateJsVisitor method visit.

@Override
public void visit(final Tree.AttributeGetterDefinition that) {
    if (errVisitor.hasErrors(that) || !TypeUtils.acceptNative(that))
        return;
    Value d = that.getDeclarationModel();
    if (opts.isOptimize() && d.isClassOrInterfaceMember())
        return;
    comment(that);
    if (AttributeGenerator.defineAsProperty(d)) {
        defineAttribute(names.self((TypeDeclaration) d.getContainer()), names.name(d));
        AttributeGenerator.getter(that, this, true);
        final AttributeSetterDefinition setterDef = associatedSetterDefinition(d);
        if (setterDef == null) {
            out(",undefined");
        } else {
            out(",function(", names.name(setterDef.getDeclarationModel().getParameter()), ")");
            AttributeGenerator.setter(setterDef, this);
        }
        out(",");
        TypeUtils.encodeForRuntime(that, that.getDeclarationModel(), that.getAnnotationList(), this);
        if (setterDef != null) {
            out(",");
            TypeUtils.encodeForRuntime(setterDef, setterDef.getDeclarationModel(), setterDef.getAnnotationList(), this);
        }
        out(");");
    } else {
        out(function, names.getter(d, false), "()");
        if (TypeUtils.isNativeExternal(d)) {
            out("{");
            if (stitchNative(d, that)) {
                if (verboseStitcher) {
                    spitOut("Stitching in native attribute " + d.getQualifiedNameString() + ", ignoring Ceylon declaration");
                }
            } else {
                AttributeGenerator.getter(that, this, false);
            }
            out("}");
        } else {
            AttributeGenerator.getter(that, this, true);
        }
        endLine();
        out(names.getter(d, false), ".$crtmm$=");
        TypeUtils.encodeForRuntime(that, d, this);
        if (!shareGetter(d)) {
            out(";");
        }
        AttributeGenerator.generateAttributeMetamodel(that, true, false, this);
    }
}
Also used : Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AttributeSetterDefinition(org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeSetterDefinition)

Example 2 with AttributeSetterDefinition

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeSetterDefinition in project ceylon by eclipse.

the class GenerateJsVisitor method addGetterToPrototype.

private void addGetterToPrototype(TypeDeclaration outer, final Tree.AttributeGetterDefinition that) {
    Value d = that.getDeclarationModel();
    if (!opts.isOptimize() || !d.isClassOrInterfaceMember())
        return;
    comment(that);
    defineAttribute(d.isStatic() ? names.name(outer) + ".$st$" : names.self(outer), names.name(d));
    if (TypeUtils.isNativeExternal(d)) {
        out("{");
        if (stitchNative(d, that)) {
            if (verboseStitcher) {
                spitOut("Stitching in native getter " + d.getQualifiedNameString() + ", ignoring Ceylon declaration");
            }
        } else {
            AttributeGenerator.getter(that, this, false);
        }
        out("}");
    } else {
        AttributeGenerator.getter(that, this, true);
    }
    final AttributeSetterDefinition setterDef = associatedSetterDefinition(d);
    if (setterDef == null) {
        out(",undefined");
    } else {
        out(",function(", names.name(setterDef.getDeclarationModel().getParameter()), ")");
        AttributeGenerator.setter(setterDef, this);
    }
    out(",");
    TypeUtils.encodeForRuntime(that, that.getDeclarationModel(), that.getAnnotationList(), this);
    if (setterDef != null) {
        out(",");
        TypeUtils.encodeForRuntime(setterDef, setterDef.getDeclarationModel(), setterDef.getAnnotationList(), this);
    }
    out(");");
}
Also used : Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) AttributeSetterDefinition(org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeSetterDefinition)

Aggregations

AttributeSetterDefinition (org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeSetterDefinition)2 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)2 Value (org.eclipse.ceylon.model.typechecker.model.Value)2 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)1