Search in sources :

Example 31 with TypeAlias

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

the class ClassDoc method loadMembers.

private void loadMembers() {
    constructors = new TreeMap<String, Declaration>();
    methods = new TreeMap<String, SortedSet<Function>>();
    attributes = new TreeMap<String, TypedDeclaration>();
    innerInterfaces = new TreeMap<String, Interface>();
    innerClasses = new TreeMap<String, Class>();
    innerExceptions = new TreeMap<String, Class>();
    innerAliases = new TreeMap<String, TypeAlias>();
    superClasses = getAncestors(klass);
    superInterfaces = getSuperInterfaces(klass);
    for (Declaration m : klass.getMembers()) {
        if (tool.shouldInclude(m)) {
            if (ModelUtil.isConstructor(m)) {
                addTo(constructors, m);
            } else if (m instanceof Value) {
                addTo(attributes, (Value) m);
            } else if (m instanceof Function) {
                if (m.isAbstraction() && m.getOverloads().size() > 0) {
                    // we want document each overloads, see https://github.com/ceylon/ceylon/issues/5748
                    continue;
                }
                addTo(methods, (Function) m);
            } else if (m instanceof Interface) {
                addTo(innerInterfaces, (Interface) m);
            } else if (m instanceof Class) {
                Class c = (Class) m;
                if (Util.isThrowable(c)) {
                    addTo(innerExceptions, c);
                } else {
                    addTo(innerClasses, c);
                }
            } else if (m instanceof TypeAlias) {
                addTo(innerAliases, (TypeAlias) m);
            }
        }
    }
    Collections.sort(superInterfaces, ReferenceableComparatorByName.INSTANCE);
    loadInheritedMembers(attributeSpecification, superClasses, superclassInheritedMembers);
    loadInheritedMembers(methodSpecification, superClasses, superclassInheritedMembers);
    loadInheritedMembers(attributeSpecification, superInterfaces, interfaceInheritedMembers);
    loadInheritedMembers(methodSpecification, superInterfaces, interfaceInheritedMembers);
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) SortedSet(java.util.SortedSet) Function(org.eclipse.ceylon.model.typechecker.model.Function) Value(org.eclipse.ceylon.model.typechecker.model.Value) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)

Example 32 with TypeAlias

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

the class GenerateJsVisitor method qualifiedPath.

public String qualifiedPath(final Node that, final Declaration d, final boolean inProto) {
    if (d instanceof Constructor) {
        Class c = (Class) d.getContainer();
        final String rval = qualifiedPath(that, c, inProto);
        return rval.isEmpty() ? names.name(c) : rval + "." + names.name(c);
    }
    final boolean isMember = d.isClassOrInterfaceMember();
    final boolean imported = isImported(that == null ? null : that.getUnit().getPackage(), d);
    if (!isMember && imported) {
        return names.moduleAlias(d.getUnit().getPackage().getModule());
    } else if (opts.isOptimize() && !inProto) {
        if (isMember && !(d.isParameter() && !d.isJsCaptured())) {
            TypeDeclaration id = that.getScope().getInheritingDeclaration(d);
            TypeDeclaration nd = null;
            if (id == null) {
                // a local declaration of some kind,
                // perhaps in an outer scope
                id = (TypeDeclaration) d.getContainer();
                if (id.isNativeHeader()) {
                    nd = (TypeDeclaration) ModelUtil.getNativeDeclaration(id, Backend.JavaScript);
                }
            }
            Scope scope = ModelUtil.getRealScope(that.getScope());
            if (scope instanceof Value && !(ModelUtil.getRealScope(scope) instanceof ClassOrInterface)) {
                scope = ModelUtil.getRealScope(scope.getContainer());
            }
            if ((scope != null) && (that instanceof Tree.ClassDeclaration || that instanceof Tree.InterfaceDeclaration || that instanceof Tree.Constructor)) {
                // class/interface aliases have no own "this"
                scope = scope.getContainer();
            }
            final StringBuilder path = new StringBuilder();
            final Declaration innermostDeclaration = ModelUtil.getContainingDeclarationOfScope(scope);
            while (scope != null) {
                if (scope instanceof Constructor && scope == innermostDeclaration) {
                    TypeDeclaration consCont = (TypeDeclaration) scope.getContainer();
                    if (that instanceof Tree.BaseTypeExpression) {
                        path.append(names.name(consCont));
                    } else if (d.isStatic()) {
                        path.append(names.name(consCont)).append(".$st$");
                    } else {
                        path.append(names.self(consCont));
                    }
                    if (scope == id || (nd != null && scope == nd)) {
                        break;
                    }
                    scope = consCont;
                } else if (scope instanceof TypeDeclaration) {
                    if (path.length() > 0) {
                        if (scope instanceof Constructor == false) {
                            Constructor constr = scope instanceof Class ? ((Class) scope).getDefaultConstructor() : null;
                            if ((constr == null || !ModelUtil.contains(constr, (Scope) innermostDeclaration)) && !d.isStatic()) {
                                path.append(".outer$");
                            }
                        }
                    } else if (d instanceof Constructor && ModelUtil.getContainingDeclaration(d) == scope) {
                        if (!d.getName().equals(((TypeDeclaration) scope).getName())) {
                            if (path.length() > 0) {
                                path.append('.');
                            }
                            path.append(names.name((TypeDeclaration) scope));
                        }
                    } else {
                        if (path.length() > 0) {
                            path.append('.');
                        }
                        if (d.isStatic()) {
                            if (d instanceof TypedDeclaration) {
                                TypedDeclaration orig = ((TypedDeclaration) d).getOriginalDeclaration();
                                path.append(names.name((ClassOrInterface) (orig == null ? d : orig).getContainer())).append(".$st$");
                            } else if (d instanceof TypeDeclaration) {
                                path.append(names.name((ClassOrInterface) d.getContainer())).append(".$st$");
                            }
                        } else {
                            path.append(names.self((TypeDeclaration) scope));
                        }
                    }
                } else {
                    path.setLength(0);
                }
                if (scope == id || (nd != null && scope == nd)) {
                    break;
                }
                scope = scope.getContainer();
            }
            if (id != null && path.length() == 0 && !ModelUtil.contains(id, that.getScope())) {
                // Import of toplevel object or constructor
                if (imported) {
                    path.append(names.moduleAlias(id.getUnit().getPackage().getModule())).append('.');
                }
                if (id.isAnonymous()) {
                    path.append(names.objectName(id));
                } else {
                    Import imp = findImport(that, d);
                    if (imp == null) {
                        path.append(names.name(id));
                    } else {
                        path.append(names.objectName(imp.getTypeDeclaration()));
                    }
                }
            }
            return path.toString();
        }
    } else if (d != null) {
        if (isMember && (d.isShared() || inProto || !d.isParameter() && AttributeGenerator.defineAsProperty(d))) {
            TypeDeclaration id = d instanceof TypeAlias ? (TypeDeclaration) d : that.getScope().getInheritingDeclaration(d);
            if (id == null) {
                // a local declaration of some kind,
                // perhaps in an outer scope
                id = (TypeDeclaration) d.getContainer();
                if (id.isToplevel() && !ModelUtil.contains(id, that.getScope())) {
                    // Import of toplevel object or constructor
                    final StringBuilder sb = new StringBuilder();
                    if (imported) {
                        sb.append(names.moduleAlias(id.getUnit().getPackage().getModule())).append('.');
                    }
                    sb.append(id.isAnonymous() ? names.objectName(id) : names.name(id));
                    return sb.toString();
                } else if (d instanceof Constructor) {
                    return names.name(id);
                } else {
                    // a shared local declaration
                    return names.self(id);
                }
            } else {
                // inherited by an outer scope
                return names.self(id);
            }
        }
    }
    return "";
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Import(org.eclipse.ceylon.model.typechecker.model.Import) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) AttributeDeclaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Aggregations

TypeAlias (org.eclipse.ceylon.model.typechecker.model.TypeAlias)32 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)23 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)20 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)16 Class (org.eclipse.ceylon.model.typechecker.model.Class)15 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)14 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)13 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)13 Type (org.eclipse.ceylon.model.typechecker.model.Type)12 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)11 Function (org.eclipse.ceylon.model.typechecker.model.Function)10 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)9 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)9 ArrayList (java.util.ArrayList)8 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)8 Value (org.eclipse.ceylon.model.typechecker.model.Value)8 NothingType (org.eclipse.ceylon.model.typechecker.model.NothingType)6 LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)5 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)5 Package (org.eclipse.ceylon.model.typechecker.model.Package)5