Search in sources :

Example 11 with Setter

use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.

the class SmallDeclarationVisitor method setSmallType.

protected static void setSmallType(FunctionOrValue f) {
    Type t = smallUnderlyingType(f.getType());
    f.setType(t);
    if (f instanceof Value) {
        Setter s = ((Value) f).getSetter();
        if (s != null) {
            s.getParameter().getModel().setType(t);
        }
    }
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) Setter(org.eclipse.ceylon.model.typechecker.model.Setter)

Example 12 with Setter

use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.

the class JsonPackage method loadAttribute.

FunctionOrValue loadAttribute(String name, Map<String, Object> m, Scope parent, List<TypeParameter> typeParameters) {
    String metatype = (String) m.get(KEY_METATYPE);
    Value d = new Value();
    d.setTransient(METATYPE_GETTER.equals(metatype));
    d.setName(name);
    d.setContainer(parent);
    d.setScope(parent);
    d.setUnit(u2);
    if (parent == this) {
        u2.addDeclaration(d);
        addMember(null);
    }
    setAnnotations(d, (Integer) m.remove(KEY_PACKED_ANNS), m.remove(KEY_ANNOTATIONS));
    d.setDynamic(m.remove(KEY_DYNAMIC) != null);
    if (m.containsKey("var")) {
        d.setVariable(true);
    }
    @SuppressWarnings("unchecked") final Map<String, Object> ktype = (Map<String, Object>) m.get(KEY_TYPE);
    d.setType(getTypeFromJson(ktype, parent instanceof Declaration ? (Declaration) parent : null, typeParameters));
    @SuppressWarnings("unchecked") final Map<String, Object> smap = (Map<String, Object>) m.remove("$set");
    if (smap != null) {
        Setter s = new Setter();
        s.setName(name);
        s.setContainer(parent);
        s.setScope(parent);
        s.setUnit(u2);
        s.setGetter(d);
        d.setSetter(s);
        if (parent == this) {
            u2.addDeclaration(s);
            addMember(null);
        }
        setAnnotations(s, (Integer) smap.remove(KEY_PACKED_ANNS), smap.remove(KEY_ANNOTATIONS));
        s.setType(d.getType());
    }
    return d;
}
Also used : Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with Setter

use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.

the class TypeUtils method generateModelPath.

/**
 * Returns the list of keys to get from the package to the declaration, in the model.
 */
public static List<String> generateModelPath(final Declaration d) {
    final ArrayList<String> sb = new ArrayList<>();
    final Package pkg = d.getUnit().getPackage();
    sb.add(pkg.isLanguagePackage() ? "$" : pkg.getNameAsString());
    if (d.isToplevel()) {
        sb.add(d.getName());
        if (d instanceof Setter) {
            sb.add("$set");
        }
    } else {
        Declaration p = d;
        final int i = sb.size();
        while (p instanceof Declaration) {
            if (p instanceof Setter) {
                sb.add(i, "$set");
            }
            final String mname = TypeUtils.modelName(p);
            if (!(mname.startsWith("anon$") || mname.startsWith("anonymous#"))) {
                sb.add(i, mname);
                // Build the path in reverse
                if (!p.isToplevel()) {
                    if (p instanceof Class) {
                        sb.add(i, p.isAnonymous() ? MetamodelGenerator.KEY_OBJECTS : MetamodelGenerator.KEY_CLASSES);
                    } else if (p instanceof org.eclipse.ceylon.model.typechecker.model.Interface) {
                        sb.add(i, MetamodelGenerator.KEY_INTERFACES);
                    } else if (p instanceof Function) {
                        if (!p.isAnonymous()) {
                            sb.add(i, MetamodelGenerator.KEY_METHODS);
                        }
                    } else if (p instanceof TypeAlias || p instanceof Setter) {
                        sb.add(i, MetamodelGenerator.KEY_ATTRIBUTES);
                    } else if (p instanceof Constructor || ModelUtil.isConstructor(p)) {
                        sb.add(i, MetamodelGenerator.KEY_CONSTRUCTORS);
                    } else {
                        // It's a value
                        TypeDeclaration td = ((TypedDeclaration) p).getTypeDeclaration();
                        sb.add(i, (td != null && td.isAnonymous()) ? MetamodelGenerator.KEY_OBJECTS : MetamodelGenerator.KEY_ATTRIBUTES);
                    }
                }
            }
            p = ModelUtil.getContainingDeclaration(p);
            while (p != null && p instanceof ClassOrInterface == false && !(p.isToplevel() || p.isAnonymous() || p.isClassOrInterfaceMember() || p.isJsCaptured())) {
                p = ModelUtil.getContainingDeclaration(p);
            }
        }
    }
    return sb;
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) ArrayList(java.util.ArrayList) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) Function(org.eclipse.ceylon.model.typechecker.model.Function) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) Class(org.eclipse.ceylon.model.typechecker.model.Class) Package(org.eclipse.ceylon.model.typechecker.model.Package) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Interface(org.eclipse.ceylon.model.typechecker.model.Interface)

Example 14 with Setter

use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.

the class JsOutput method publishUnsharedDeclarations.

public void publishUnsharedDeclarations(JsIdentifierNames names) {
    // #489 lists with unshared toplevel members of each package
    for (org.eclipse.ceylon.model.typechecker.model.Package pkg : module.getPackages()) {
        ArrayList<Declaration> unsharedDecls = new ArrayList<>(pkg.getMembers().size());
        for (Declaration d : pkg.getMembers()) {
            if (!d.isShared() && !(d.isAnonymous() && d.getName() != null && d.getName().startsWith("anonymous#")) && (!d.isNative() || d.getNativeBackends().supports(Backend.JavaScript))) {
                unsharedDecls.add(d);
            }
        }
        if (!unsharedDecls.isEmpty()) {
            out("ex$.$pkgunsh$", pkg.getNameAsString().replace('.', '$'), "={");
            boolean first = true;
            for (Declaration d : unsharedDecls) {
                if (d.getName() == null)
                    continue;
                // TODO only use quotes when absolutely necessary
                if (d.isAnonymous()) {
                // Don't generate anything for anonymous types
                } else if (d instanceof Setter) {
                    // ignore
                    if (((Setter) d).getGetter() == null) {
                        if (first)
                            first = false;
                        else
                            out(",");
                        out("'", d.getName(), "':", names.setter(d));
                    }
                } else if (d instanceof Value) {
                    if (first)
                        first = false;
                    else
                        out(",");
                    out("'", d.getName(), "':", names.getter(d, true));
                } else {
                    if (first)
                        first = false;
                    else
                        out(",");
                    out("'", d.getName(), "':", names.name(d));
                }
            }
            out("};\n");
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) Value(org.eclipse.ceylon.model.typechecker.model.Value) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 15 with Setter

use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.

the class SpecificationVisitor method visit.

@Override
public void visit(Tree.AttributeSetterDefinition that) {
    Setter d = that.getDeclarationModel();
    if (d == declaration || d.getParameter().getModel() == declaration) {
        declare();
        specify();
    }
    super.visit(that);
}
Also used : Setter(org.eclipse.ceylon.model.typechecker.model.Setter)

Aggregations

Setter (org.eclipse.ceylon.model.typechecker.model.Setter)30 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)18 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)17 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)16 Value (org.eclipse.ceylon.model.typechecker.model.Value)16 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)14 Class (org.eclipse.ceylon.model.typechecker.model.Class)8 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)8 Function (org.eclipse.ceylon.model.typechecker.model.Function)8 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)7 Type (org.eclipse.ceylon.model.typechecker.model.Type)7 ArrayList (java.util.ArrayList)6 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)5 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)5 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)5 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)5 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)4 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)4 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)4 MethodDeclaration (org.eclipse.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)4