Search in sources :

Example 1 with InterfaceAlias

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.InterfaceDeclaration that) {
    InterfaceAlias i = new InterfaceAlias();
    that.setDeclarationModel(i);
    super.visit(that);
}
Also used : InterfaceAlias(org.eclipse.ceylon.model.typechecker.model.InterfaceAlias)

Example 2 with InterfaceAlias

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

the class JsonPackage method loadInterface.

@SuppressWarnings("unchecked")
Interface loadInterface(String name, Map<String, Object> m, Scope parent, final List<TypeParameter> existing) {
    // Check if it's been loaded first
    // It hasn't been loaded, so create it
    Interface t;
    m.remove(KEY_NAME);
    if (m.get(KEY_METATYPE) instanceof Interface) {
        t = (Interface) m.get(KEY_METATYPE);
        if (m.size() <= 3) {
            // it's been loaded
            return t;
        }
    } else {
        if (m.containsKey("$alias")) {
            t = new InterfaceAlias();
        } else {
            t = new Interface();
        }
        t.setContainer(parent);
        t.setScope(parent);
        t.setName(name);
        t.setUnit(u2);
        if (parent == this) {
            u2.addDeclaration(t);
        }
        parent.addMember(t);
        m.put(KEY_METATYPE, t);
        setAnnotations(t, (Integer) m.remove(KEY_PACKED_ANNS), m.remove(KEY_ANNOTATIONS));
    }
    if (m.remove(KEY_DYNAMIC) != null) {
        t.setDynamic(true);
    }
    List<TypeParameter> tparms = t.getTypeParameters();
    List<Map<String, Object>> listOfMaps = (List<Map<String, Object>>) m.get(KEY_TYPE_PARAMS);
    if (listOfMaps != null && (tparms == null || tparms.size() < listOfMaps.size())) {
        tparms = parseTypeParameters(listOfMaps, t, existing);
        m.remove(KEY_TYPE_PARAMS);
    }
    final List<TypeParameter> allparms = JsonPackage.merge(tparms, existing);
    // All interfaces extend Object, except aliases
    if (t.getExtendedType() == null) {
        if (t.isAlias()) {
            t.setExtendedType(getTypeFromJson((Map<String, Object>) m.remove("$alias"), parent instanceof Declaration ? (Declaration) parent : null, allparms));
        } else {
            t.setExtendedType(getTypeFromJson(objclass, parent instanceof Declaration ? (Declaration) parent : null, null));
        }
    }
    if (m.containsKey(KEY_SELF_TYPE)) {
        for (TypeParameter _tp : tparms) {
            if (_tp.getName().equals(m.get(KEY_SELF_TYPE))) {
                t.setSelfType(_tp.getType());
                _tp.setSelfTypedDeclaration(t);
            }
        }
        m.remove(KEY_SELF_TYPE);
    }
    if (m.containsKey("of") && t.getCaseTypes() == null) {
        t.setCaseTypes(parseTypeList((List<Map<String, Object>>) m.remove("of"), allparms));
    }
    if (m.containsKey(KEY_SATISFIES)) {
        for (Type s : parseTypeList((List<Map<String, Object>>) m.remove(KEY_SATISFIES), allparms)) {
            t.getSatisfiedTypes().add(s);
        }
    }
    addAttributesAndMethods(m, t, allparms);
    if (m.containsKey(KEY_INTERFACES)) {
        Map<String, Map<String, Object>> cdefs = (Map<String, Map<String, Object>>) m.remove(KEY_INTERFACES);
        for (Map.Entry<String, Map<String, Object>> cdef : cdefs.entrySet()) {
            loadInterface(cdef.getKey(), cdef.getValue(), t, allparms);
        }
    }
    if (m.containsKey(KEY_CLASSES)) {
        Map<String, Map<String, Object>> cdefs = (Map<String, Map<String, Object>>) m.remove(KEY_CLASSES);
        for (Map.Entry<String, Map<String, Object>> cdef : cdefs.entrySet()) {
            loadClass(cdef.getKey(), cdef.getValue(), t, allparms);
        }
    }
    if (t.isDynamic() && (getModule().getJsMajor() < 9 || (getModule().getJsMajor() == 9 && getModule().getJsMinor() < 1))) {
        // previous versions did not set dynamic flag on members
        t.makeMembersDynamic();
    }
    return t;
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) InterfaceAlias(org.eclipse.ceylon.model.typechecker.model.InterfaceAlias) 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) 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) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)

Aggregations

InterfaceAlias (org.eclipse.ceylon.model.typechecker.model.InterfaceAlias)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)1 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)1 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)1 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)1 NothingType (org.eclipse.ceylon.model.typechecker.model.NothingType)1 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)1 Type (org.eclipse.ceylon.model.typechecker.model.Type)1 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)1 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)1 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)1 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)1