Search in sources :

Example 1 with Generic

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

the class ClassOrPackageDoc method doc.

protected final void doc(String id, String name, Declaration d) throws IOException {
    String declarationName = Util.getDeclarationName(d);
    id = (id != null ? id : name);
    boolean alias = Util.nullSafeCompare(name, declarationName) != 0;
    // put the id on the td because IE8 doesn't support id attributes on tr (yeah right)
    open("tr");
    open("td id='" + id + "' nowrap");
    writeIcon(d);
    if (!(d instanceof Constructor)) {
        around("code class='decl-label'", name);
        close("td");
        open("td");
    }
    writeLinkOneSelf(id);
    if (alias) {
        writeTagged(d);
        writeAlias(d);
    } else {
        writeLinkSource(d);
        writeTagged(d);
        if (d instanceof Functional) {
            writeParameterLinksIfRequired((Functional) d);
        }
        open("code class='signature'");
        around("span class='modifiers'", getModifiers(d));
        write(" ");
        if (!ModelUtil.isConstructor(d)) {
            if (!Decl.isDynamic(d)) {
                if (d instanceof Functional && ((Functional) d).isDeclaredVoid()) {
                    around("span class='void'", "void");
                } else if (d instanceof TypedDeclaration) {
                    linkRenderer().to(((TypedDeclaration) d).getType()).useScope(d).write();
                } else {
                    linkRenderer().to(d).useScope(d).write();
                }
            } else {
                around("span class='dynamic'", "dynamic");
            }
        }
        write(" ");
        open("span class='identifier'");
        write(name);
        close("span");
        if (isConstantValue(d)) {
            writeConstantValue((Value) d);
        }
        if (d instanceof Generic) {
            writeTypeParameters(d.getTypeParameters(), d);
        }
        if (d instanceof Functional) {
            writeParameterList((Functional) d, d);
        }
        if (d instanceof Generic) {
            writeTypeParametersConstraints(d.getTypeParameters(), d);
        }
        if (d instanceof Value) {
            Setter setter = ((Value) d).getSetter();
            if (setter != null && Util.getAnnotation(setter.getUnit(), setter.getAnnotations(), "doc") != null) {
                tool.warningSetterDoc(d.getQualifiedNameString(), d);
            }
        }
        close("code");
        writeDescription(d);
    }
    close("td");
    close("tr");
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Generic(org.eclipse.ceylon.model.typechecker.model.Generic) 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 2 with Generic

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.TypeParameterList that) {
    super.visit(that);
    if (declaration instanceof Generic) {
        Generic g = (Generic) declaration;
        g.setTypeParameters(getTypeParameters(that));
    }
}
Also used : Generic(org.eclipse.ceylon.model.typechecker.model.Generic)

Example 3 with Generic

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

the class ClassTransformer method typeParametersForInstantiator.

/**
 * When generating an instantiator method if the inner class has a type
 * parameter with the same name as a type parameter of an outer type, then the
 * instantiator method shouldn't declare its own type parameter of that
 * name -- it should use the captured one. This method filters out the
 * type parameters of the inner class which are the same as type parameters
 * of the outer class so that they can be captured.
 */
private java.util.List<TypeParameter> typeParametersForInstantiator(final Class model) {
    java.util.List<TypeParameter> filtered = new ArrayList<TypeParameter>();
    java.util.List<TypeParameter> tps = model.getTypeParameters();
    if (tps != null) {
        for (TypeParameter tp : tps) {
            boolean omit = false;
            Scope s = model.getContainer();
            while (!(s instanceof Package)) {
                if (s instanceof Generic) {
                    for (TypeParameter outerTp : ((Generic) s).getTypeParameters()) {
                        if (tp.getName().equals(outerTp.getName())) {
                            omit = true;
                        }
                    }
                }
                s = s.getContainer();
            }
            if (!omit) {
                filtered.add(tp);
            }
        }
    }
    return filtered;
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Generic(org.eclipse.ceylon.model.typechecker.model.Generic) ArrayList(java.util.ArrayList) Package(org.eclipse.ceylon.model.typechecker.model.Package)

Example 4 with Generic

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

the class ClassTransformer method typeParametersOfAllContainers.

private java.util.List<TypeParameter> typeParametersOfAllContainers(final ClassOrInterface model, boolean includeModelTypeParameters) {
    java.util.List<java.util.List<TypeParameter>> r = new ArrayList<java.util.List<TypeParameter>>(1);
    Scope s = model.getContainer();
    while (!(s instanceof Package)) {
        if (s instanceof Generic) {
            r.add(0, ((Generic) s).getTypeParameters());
        }
        s = s.getContainer();
    }
    Set<String> names = new HashSet<String>();
    for (TypeParameter tp : model.getTypeParameters()) {
        names.add(tp.getName());
    }
    java.util.List<TypeParameter> result = new ArrayList<TypeParameter>(1);
    for (java.util.List<TypeParameter> tps : r) {
        for (TypeParameter tp : tps) {
            if (names.add(tp.getName())) {
                result.add(tp);
            }
        }
    }
    if (includeModelTypeParameters)
        result.addAll(model.getTypeParameters());
    return result;
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Generic(org.eclipse.ceylon.model.typechecker.model.Generic) ArrayList(java.util.ArrayList) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ArrayList(java.util.ArrayList) AnnotationList(org.eclipse.ceylon.compiler.typechecker.tree.Tree.AnnotationList) List(org.eclipse.ceylon.langtools.tools.javac.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Package(org.eclipse.ceylon.model.typechecker.model.Package) HashSet(java.util.HashSet)

Example 5 with Generic

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

the class JsonPackage method parseTypeParameters.

/**
 * Creates a list of TypeParameter from a list of maps.
 * @param typeParams The list of maps to create the TypeParameters.
 * @param container The declaration which owns the resulting type parameters.
 * @param existing A list of type parameters declared in the parent scopes which can be referenced from
 * the ones that have to be parsed.
 */
private List<TypeParameter> parseTypeParameters(List<Map<String, Object>> typeParams, final Declaration container, List<TypeParameter> existing) {
    if (typeParams == null)
        return Collections.emptyList();
    // New array with existing parms to avoid modifying that one
    List<TypeParameter> allparms = new ArrayList<>((existing == null ? 0 : existing.size()) + typeParams.size());
    if (existing != null && !existing.isEmpty()) {
        allparms.addAll(existing);
    }
    List<TypeParameter> tparms = new ArrayList<>(typeParams.size());
    // First create the type parameters
    for (Map<String, Object> tp : typeParams) {
        final Declaration maybe;
        if (tp.get(KEY_METATYPE) instanceof TypeParameter) {
            maybe = (TypeParameter) tp.get(KEY_METATYPE);
        } else {
            maybe = container.getDirectMember((String) tp.get(KEY_NAME), null, false);
        }
        if (maybe instanceof TypeParameter) {
            // we already had it (from partial loading elsewhere)
            allparms.add((TypeParameter) maybe);
            tparms.add((TypeParameter) maybe);
            tp.put(KEY_METATYPE, maybe);
        } else {
            TypeParameter tparm = new TypeParameter();
            tparm.setUnit(container.getUnit());
            tparm.setDeclaration(container);
            container.getMembers().add(tparm);
            if (tp.containsKey(KEY_NAME)) {
                tparm.setName((String) tp.get(KEY_NAME));
            } else if (!tp.containsKey(KEY_TYPES)) {
                throw new IllegalArgumentException("Invalid type parameter map " + tp);
            }
            String variance = (String) tp.get(KEY_DS_VARIANCE);
            if ("out".equals(variance)) {
                tparm.setCovariant(true);
            } else if ("in".equals(variance)) {
                tparm.setContravariant(true);
            }
            if (container instanceof Scope) {
                Scope scope = (Scope) container;
                tparm.setContainer(scope);
                tparm.setScope(scope);
            }
            tparm.setDefaulted(tp.containsKey(KEY_DEFAULT));
            tparms.add(tparm);
            allparms.add(tparm);
            tp.put(KEY_METATYPE, tparm);
        }
    }
    if (container instanceof Generic) {
        ((Generic) container).setTypeParameters(tparms);
    }
    // Second, add defaults and heritage
    for (Map<String, Object> tp : typeParams) {
        TypeParameter tparm = (TypeParameter) tp.get(KEY_METATYPE);
        if (tparm.getExtendedType() == null) {
            if (tp.containsKey(KEY_PACKAGE)) {
                // Looks like this never happens but...
                Type subtype = getTypeFromJson(tp, container, allparms);
                tparm.setExtendedType(subtype);
            } else if (tp.containsKey(KEY_TYPES)) {
                if (!("u".equals(tp.get("comp")) || "i".equals(tp.get("comp")))) {
                    throw new IllegalArgumentException("Only union or intersection types are allowed as 'comp'");
                }
                Type subtype = getTypeFromJson(tp, container, allparms);
                tparm.setName(subtype.asString());
                tparm.setExtendedType(subtype);
            } else {
                tparm.setExtendedType(getTypeFromJson(voidclass, container, null));
            }
        }
        if (tparm.isDefaulted()) {
            @SuppressWarnings("unchecked") final Map<String, Object> deftype = (Map<String, Object>) tp.get(KEY_DEFAULT);
            tparm.setDefaultTypeArgument(getTypeFromJson(deftype, container, existing));
        }
        if (tp.containsKey(KEY_SATISFIES)) {
            @SuppressWarnings("unchecked") final List<Map<String, Object>> stypes = (List<Map<String, Object>>) tp.get(KEY_SATISFIES);
            tparm.setSatisfiedTypes(parseTypeList(stypes, allparms));
            tparm.setConstrained(true);
        } else if (tp.containsKey("of")) {
            @SuppressWarnings("unchecked") final List<Map<String, Object>> oftype = (List<Map<String, Object>>) tp.get("of");
            tparm.setCaseTypes(parseTypeList(oftype, allparms));
            tparm.setConstrained(true);
        }
    }
    return tparms;
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Generic(org.eclipse.ceylon.model.typechecker.model.Generic) ArrayList(java.util.ArrayList) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Generic (org.eclipse.ceylon.model.typechecker.model.Generic)11 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)9 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)6 ArrayList (java.util.ArrayList)5 Type (org.eclipse.ceylon.model.typechecker.model.Type)5 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)5 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)5 HashMap (java.util.HashMap)4 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)4 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)4 Map (java.util.Map)3 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)3 NothingType (org.eclipse.ceylon.model.typechecker.model.NothingType)3 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)3 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)3 List (java.util.List)2 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)2 Class (org.eclipse.ceylon.model.typechecker.model.Class)2 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)2 Functional (org.eclipse.ceylon.model.typechecker.model.Functional)2