Search in sources :

Example 11 with Package

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

the class ModuleDoc method generate.

public void generate() throws IOException {
    writeHeader("Overview");
    writeNavBar();
    open("div class='container-fluid'");
    writeDescription();
    writePackagesTable("Packages", tool.getPackages(module));
    writeDependencies();
    close("div");
    for (Package pkg : module.getPackages()) {
        if (tool.isRootPackage(module, pkg) && !pkg.getMembers().isEmpty()) {
            rootPackageDoc = new PackageDoc(tool, writer, pkg);
            rootPackageDoc.generate();
        }
    }
    writeFooter();
}
Also used : Package(org.eclipse.ceylon.model.typechecker.model.Package)

Example 12 with Package

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

the class PackageDoc method writeSubpackages.

private void writeSubpackages() throws IOException {
    if (!sharingPageWithModule) {
        List<Package> subpackages = new ArrayList<Package>();
        for (Package p : module.getPackages()) {
            if (p.getName().size() == pkg.getName().size() + 1 && p.getNameAsString().startsWith(pkg.getNameAsString()) && tool.shouldInclude(p)) {
                subpackages.add(p);
            }
        }
        Collections.sort(subpackages, ReferenceableComparatorByName.INSTANCE);
        writePackagesTable("Subpackages", subpackages);
    }
}
Also used : ArrayList(java.util.ArrayList) Package(org.eclipse.ceylon.model.typechecker.model.Package)

Example 13 with Package

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

the class ExpressionVisitor method resolveQualifiedTypeExpression.

private TypeDeclaration resolveQualifiedTypeExpression(Tree.QualifiedTypeExpression that, boolean error) {
    if (checkMember(that)) {
        Tree.Primary primary = that.getPrimary();
        Tree.Identifier id = that.getIdentifier();
        List<Type> signature = that.getSignature();
        boolean spread = that.getEllipsis();
        String name = name(id);
        String container;
        boolean ambiguous;
        TypeDeclaration type;
        Type pt;
        if (primary instanceof Tree.Package) {
            Package pack = unit.getPackage();
            container = "package '" + pack.getNameAsString() + "'";
            type = getPackageTypeDeclaration(name, signature, spread, unit);
            ambiguous = false;
            pt = null;
        } else {
            pt = primary.getTypeModel().resolveAliases();
            TypeDeclaration d = getDeclaration(that, pt);
            if (d instanceof Constructor) {
                d = d.getExtendedType().getDeclaration();
            }
            container = "type '" + d.getName(unit) + "'";
            Scope scope = that.getScope();
            type = getTypeMember(d, name, signature, spread, unit, scope);
            ambiguous = type == null && d.isMemberAmbiguous(name, unit, signature, spread);
            if (type == null) {
                container += memberCorrectionMessage(name, d, scope, unit, cancellable);
            }
        }
        if (type == null) {
            if (error) {
                if (ambiguous) {
                    that.addError("member type is ambiguous: '" + name + "' for " + container);
                } else {
                    that.addError("member type is not defined: '" + name + "' in " + container, 100);
                    unit.setUnresolvedReferences();
                }
            }
        } else {
            type = (TypeDeclaration) handleAbstractionOrHeader(type, that, error);
            if (error) {
                checkStaticPrimary(that, primary, type, pt);
            }
            that.setDeclaration(type);
            resetSuperReference(that);
            if (!isSelfReference(primary) && !type.isShared()) {
                type.setOtherInstanceAccess(true);
            }
            if (error) {
                if (checkConcreteClass(type, that)) {
                    if (checkVisibleConstructor(that, type)) {
                        checkQualifiedTypeAndConstructorVisibility(that, type, name, container);
                    }
                }
                if (!inExtendsClause) {
                    checkSuperMember(that, signature, spread);
                }
            }
        }
        return type;
    } else {
        return null;
    }
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) NativeUtil.declarationScope(org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.declarationScope) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) AnalyzerUtil.unwrapAliasedTypeConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.unwrapAliasedTypeConstructor) ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnalyzerUtil.declaredInPackage(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.declaredInPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) AnalyzerUtil.importedPackage(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.importedPackage) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 14 with Package

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

the class AnalyzerUtil method importedPackage.

static Package importedPackage(Tree.ImportPath path, Unit unit) {
    if (path != null && !path.getIdentifiers().isEmpty()) {
        String nameToImport = formatPath(path.getIdentifiers());
        Module module = path.getUnit().getPackage().getModule();
        Package pkg = module.getPackage(nameToImport);
        if (pkg != null) {
            Module pkgMod = pkg.getModule();
            if (pkgMod.equals(module)) {
                return pkg;
            }
            if (!pkg.isShared()) {
                path.addError("imported package is not visible: package '" + nameToImport + "' is not shared by module '" + pkgMod.getNameAsString() + "'", 402);
            } else if (!pkg.withinRestrictions(unit)) {
                path.addError("imported package is not visible: package '" + nameToImport + "' is restricted by module '" + pkgMod.getNameAsString() + "'");
            }
            // if (module.isDefault() &&
            // !pkg.getModule().isDefault() &&
            // !pkg.getModule().getNameAsString()
            // .equals(Module.LANGUAGE_MODULE_NAME)) {
            // path.addError("package belongs to a module and may not be imported by default module: " +
            // nameToImport);
            // }
            // check that the package really does belong to
            // an imported module, to work around bug where
            // default package thinks it can see stuff in
            // all modules in the same source dir
            Set<Module> visited = new HashSet<Module>();
            for (ModuleImport mi : module.getImports()) {
                if (findModuleInTransitiveImports(mi.getModule(), pkgMod, visited)) {
                    return pkg;
                }
            }
        } else {
            for (ModuleImport mi : module.getImports()) {
                if (mi.isNative()) {
                    String name = mi.getModule().getNameAsString();
                    Backends backends = path.getUnit().getSupportedBackends();
                    if (!isForBackend(mi.getNativeBackends(), backends) && (nameToImport.equals(name) || nameToImport.startsWith(name + "."))) {
                        return null;
                    }
                    if (!isForBackend(Backend.Java.asSet(), backends) && unit.isJdkPackage(nameToImport)) {
                        return null;
                    }
                }
            }
        }
        String help = module.isDefaultModule() ? " (define a module and add module import to its module descriptor)" : " (add module import to module descriptor of '" + module.getNameAsString() + "')";
        path.addError("package not found in imported modules: '" + nameToImport + "'" + help, 7000);
    }
    return null;
}
Also used : Backends(org.eclipse.ceylon.common.Backends) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) HashSet(java.util.HashSet)

Example 15 with Package

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

the class AnalyzerUtil method importedModule.

static Module importedModule(Tree.ImportPath path, boolean restriction) {
    if (path != null && !path.getIdentifiers().isEmpty()) {
        String nameToImport = formatPath(path.getIdentifiers());
        Module module = path.getUnit().getPackage().getModule();
        Package pkg = module.getPackage(nameToImport);
        if (pkg != null) {
            Module mod = pkg.getModule();
            String moduleName = mod.getNameAsString();
            if (!pkg.getNameAsString().equals(moduleName)) {
                path.addError("not a module: '" + nameToImport + "' is a package belonging to '" + moduleName + "'");
                return null;
            }
            if (mod.equals(module)) {
                return mod;
            }
            // check that the package really does belong to
            // an imported module, to work around bug where
            // default package thinks it can see stuff in
            // all modules in the same source dir
            Set<Module> visited = new HashSet<Module>();
            for (ModuleImport mi : module.getImports()) {
                if (findModuleInTransitiveImports(mi.getModule(), mod, visited)) {
                    return mod;
                }
            }
        }
        if (!restriction) {
            path.addError("module not found in imported modules: '" + nameToImport + "'", 7000);
        }
    }
    return null;
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) HashSet(java.util.HashSet)

Aggregations

Package (org.eclipse.ceylon.model.typechecker.model.Package)84 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)31 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)31 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)27 Module (org.eclipse.ceylon.model.typechecker.model.Module)26 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)21 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)14 ArrayList (java.util.ArrayList)13 LazyPackage (org.eclipse.ceylon.model.loader.model.LazyPackage)11 Class (org.eclipse.ceylon.model.typechecker.model.Class)11 Function (org.eclipse.ceylon.model.typechecker.model.Function)9 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)9 Value (org.eclipse.ceylon.model.typechecker.model.Value)9 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)8 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)8 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)8 HashSet (java.util.HashSet)7 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)7 ModuleImport (org.eclipse.ceylon.model.typechecker.model.ModuleImport)7 Type (org.eclipse.ceylon.model.typechecker.model.Type)7