Search in sources :

Example 46 with Package

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

the class RuntimeModelLoader method loadStandardModules.

@Override
public void loadStandardModules() {
    // set up the type factory and that's it: do not try to load the language module package before it's set up
    // by Metamodel.loadModule
    jdkProvider = new JdkProvider();
    Module languageModule = findOrCreateModule(CEYLON_LANGUAGE, null);
    addModuleToClassPath(languageModule, (ArtifactResult) null);
    Package languagePackage = findOrCreatePackage(languageModule, CEYLON_LANGUAGE);
    typeFactory.setPackage(languagePackage);
    // make sure the jdk modules are loaded because those are not initialised by jboss modules nor the IDE Launcher
    for (String jdkModule : JDKUtils.getJDKModuleNames()) findOrCreateModule(jdkModule, JDKUtils.jdk.version);
    for (String jdkOracleModule : JDKUtils.getOracleJDKModuleNames()) findOrCreateModule(jdkOracleModule, JDKUtils.jdk.version);
}
Also used : JdkProvider(org.eclipse.ceylon.model.loader.JdkProvider) Package(org.eclipse.ceylon.model.typechecker.model.Package) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) Module(org.eclipse.ceylon.model.typechecker.model.Module)

Example 47 with Package

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

the class LazyModule method getPackage.

@Override
public Package getPackage(String name) {
    // try here first
    Package pkg = null;
    // unless we're the default module, in which case we have to check this at the end,
    // since every package can be part of the default module
    boolean defaultModule = isDefaultModule();
    if (!defaultModule) {
        pkg = findPackageInModule(this, name);
        if (pkg != null)
            return loadPackage(pkg);
    }
    // then try in dependencies
    Set<Module> visited = new HashSet<Module>();
    for (ModuleImport dependency : getImports()) {
        // we don't have to worry about the default module here since we can't depend on it
        pkg = findPackageInImport(name, dependency, visited);
        if (pkg != null)
            return loadPackage(pkg);
    }
    AbstractModelLoader modelLoader = getModelLoader();
    JdkProvider jdkProvider = modelLoader.getJdkProvider();
    // so we pretend the JDK imports the language module
    if (jdkProvider != null && jdkProvider.isJDKModule(getNameAsString())) {
        Module languageModule = getModelLoader().getLanguageModule();
        if (languageModule instanceof LazyModule) {
            pkg = findPackageInModule((LazyModule) languageModule, name);
            if (pkg != null)
                return loadPackage(pkg);
        }
    }
    // work and appear to come from there
    if (jdkProvider.isJDKPackage(name)) {
        return null;
    }
    // do the lookup of the default module last
    if (defaultModule)
        pkg = modelLoader.findExistingPackage(this, name);
    return pkg;
}
Also used : AbstractModelLoader(org.eclipse.ceylon.model.loader.AbstractModelLoader) JdkProvider(org.eclipse.ceylon.model.loader.JdkProvider) 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 48 with Package

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.PackageLiteral that) {
    super.visit(that);
    Tree.ImportPath path = that.getImportPath();
    if (path == null) {
        path = new Tree.ImportPath(null);
        that.setImportPath(path);
    }
    Package pack = path.getIdentifiers().isEmpty() ? unit.getPackage() : importedPackage(path, unit);
    path.setModel(pack);
    that.setTypeModel(unit.getPackageDeclarationType());
}
Also used : 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)

Example 49 with Package

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

the class AnnotationVisitor method visit.

@Override
public void visit(Tree.DocLink that) {
    super.visit(that);
    String text = that.getText();
    int pipeIndex = text.indexOf("|");
    if (pipeIndex != -1) {
        text = text.substring(pipeIndex + 1);
    }
    String kind = null;
    if (text.startsWith(DOC_LINK_MODULE)) {
        kind = DOC_LINK_MODULE;
        text = text.substring(DOC_LINK_MODULE.length());
    } else if (text.startsWith(DOC_LINK_PACKAGE)) {
        kind = DOC_LINK_PACKAGE;
        text = text.substring(DOC_LINK_PACKAGE.length());
    } else if (text.startsWith(DOC_LINK_CLASS)) {
        kind = DOC_LINK_CLASS;
        text = text.substring(DOC_LINK_CLASS.length());
    } else if (text.startsWith(DOC_LINK_INTERFACE)) {
        kind = DOC_LINK_INTERFACE;
        text = text.substring(DOC_LINK_INTERFACE.length());
    } else if (text.startsWith(DOC_LINK_FUNCTION)) {
        kind = DOC_LINK_FUNCTION;
        text = text.substring(DOC_LINK_FUNCTION.length());
    } else if (text.startsWith(DOC_LINK_VALUE)) {
        kind = DOC_LINK_VALUE;
        text = text.substring(DOC_LINK_VALUE.length());
    } else if (text.startsWith(DOC_LINK_ALIAS)) {
        kind = DOC_LINK_ALIAS;
        text = text.substring(DOC_LINK_ALIAS.length());
    }
    boolean parentheses = false;
    if (text.endsWith("()")) {
        parentheses = true;
        text = text.substring(0, text.length() - 2);
    }
    int scopeIndex = text.indexOf("::");
    String packageName;
    if (DOC_LINK_MODULE.equals(kind) || DOC_LINK_PACKAGE.equals(kind)) {
        packageName = text;
    } else {
        packageName = scopeIndex < 0 ? null : text.substring(0, scopeIndex);
    }
    String path = scopeIndex < 0 ? text : text.substring(scopeIndex + 2);
    String[] names = path.isEmpty() ? new String[0] : path.split("\\.");
    Declaration base = null;
    if (packageName == null) {
        if (names.length > 0) {
            base = that.getScope().getMemberOrParameter(that.getUnit(), names[0], null, false);
        }
    } else {
        Package pack = that.getUnit().getPackage().getModule().getPackage(packageName);
        if (pack == null) {
            if (DOC_LINK_MODULE.equals(kind)) {
                that.addUsageWarning(Warning.doclink, "module is missing: '" + packageName + "'");
            } else {
                that.addUsageWarning(Warning.doclink, "package is missing: '" + packageName + "'");
            }
        } else {
            that.setPkg(pack);
            if (DOC_LINK_MODULE.equals(kind)) {
                Package rootPack = pack.getModule().getRootPackage();
                if (pack.equals(rootPack)) {
                    that.setModule(pack.getModule());
                } else {
                    that.addUsageWarning(Warning.doclink, "module is missing: '" + packageName + "'");
                }
            }
            if (names.length > 0) {
                base = pack.getDirectMember(names[0], null, false);
            }
        }
        if (DOC_LINK_MODULE.equals(kind) || DOC_LINK_PACKAGE.equals(kind)) {
            return;
        }
    }
    if (base == null) {
        that.addUsageWarning(Warning.doclink, "declaration is missing: '" + (names.length > 0 ? names[0] : text) + "'");
    } else {
        that.setBase(base);
        if (names.length > 1) {
            that.setQualified(new ArrayList<Declaration>(names.length - 1));
        }
        for (int i = 1; i < names.length; i++) {
            if (base instanceof Value) {
                Value value = (Value) base;
                if (!value.isParameter() && !value.isTransient() && value.getTypeDeclaration() != null && value.getTypeDeclaration().isAnonymous()) {
                    base = value.getTypeDeclaration();
                }
            }
            if (base instanceof TypeDeclaration || base instanceof Functional) {
                Declaration qualified = base.getMember(names[i], null, false);
                if (qualified == null) {
                    that.addUsageWarning(Warning.doclink, "member declaration or parameter is missing: '" + names[i] + "'");
                    break;
                } else {
                    that.getQualified().add(qualified);
                    base = qualified;
                }
            } else {
                that.addUsageWarning(Warning.doclink, "not a type or functional declaration: '" + base.getName() + "'");
                break;
            }
        }
    }
    if (base != null) {
        if (kind != null && (names.length == 1 || names.length == that.getQualified().size() + 1)) {
            if (DOC_LINK_CLASS.equals(kind) && !(base instanceof Class)) {
                that.addUsageWarning(Warning.doclink, "linked declaration is not a class: '" + base.getName() + "'");
            } else if (DOC_LINK_INTERFACE.equals(kind) && !(base instanceof Interface)) {
                that.addUsageWarning(Warning.doclink, "linked declaration is not an interface: '" + base.getName() + "'");
            } else if (DOC_LINK_ALIAS.equals(kind) && !(base instanceof TypeAlias)) {
                that.addUsageWarning(Warning.doclink, "linked declaration is not a type alias: '" + base.getName() + "'");
            } else if (DOC_LINK_FUNCTION.equals(kind) && !(base instanceof Function)) {
                that.addUsageWarning(Warning.doclink, "linked declaration is not a function: '" + base.getName() + "'");
            } else if (DOC_LINK_VALUE.equals(kind) && !(base instanceof Value)) {
                that.addUsageWarning(Warning.doclink, "linked declaration is not a value: '" + base.getName() + "'");
            }
        }
        if (parentheses && !(base instanceof Functional)) {
            that.addUsageWarning(Warning.doclink, "linked declaration is not a function: '" + base.getName() + "'");
        }
    }
}
Also used : TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) Functional(org.eclipse.ceylon.model.typechecker.model.Functional) Function(org.eclipse.ceylon.model.typechecker.model.Function) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) 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) Package(org.eclipse.ceylon.model.typechecker.model.Package) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)

Example 50 with Package

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

the class ExpressionVisitor method resolveQualifiedMemberExpression.

private TypedDeclaration resolveQualifiedMemberExpression(Tree.QualifiedMemberExpression that, boolean error) {
    Tree.Identifier id = that.getIdentifier();
    boolean nameNonempty = id != null && !id.getText().equals("");
    if (nameNonempty && checkMember(that)) {
        Tree.Primary primary = that.getPrimary();
        String name = name(id);
        List<Type> signature = that.getSignature();
        boolean spread = that.getEllipsis();
        String container;
        boolean ambiguous;
        TypedDeclaration member;
        Type pt;
        if (primary instanceof Tree.Package) {
            Package pack = unit.getPackage();
            container = "package '" + pack.getNameAsString() + "'";
            member = getPackageTypedDeclaration(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();
            member = getTypedMember(d, name, signature, spread, unit, scope);
            ambiguous = member == null && d.isMemberAmbiguous(name, unit, signature, spread);
            if (member == null) {
                container += memberCorrectionMessage(name, d, scope, unit, cancellable);
            }
        }
        if (member == null) {
            if (error) {
                if (ambiguous) {
                    that.addError("method or attribute is ambiguous: '" + name + "' for " + container);
                } else {
                    that.addError("method or attribute is not defined: '" + name + "' in " + container, 100);
                    unit.setUnresolvedReferences();
                }
            }
        } else {
            member = (TypedDeclaration) handleAbstractionOrHeader(member, that, error);
            if (error) {
                checkStaticPrimary(that, primary, member, pt);
            }
            that.setDeclaration(member);
            resetSuperReference(that);
            boolean selfReference = isSelfReference(primary);
            if (!selfReference && !member.isShared()) {
                member.setOtherInstanceAccess(true);
            }
            if (error) {
                if (checkConcreteConstructor(member, that)) {
                    checkQualifiedVisibility(that, member, name, container, selfReference);
                }
                checkSuperMember(that, signature, spread);
            }
        }
        return member;
    } else {
        return null;
    }
}
Also used : AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) 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)

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