Search in sources :

Example 31 with Package

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

the class ImportVisitor method visit.

@Override
public void visit(Tree.Import that) {
    Backends scopedBackends = that.getScope().getScopedBackends();
    if (!scopedBackends.none() && !scopedBackends.supports(unit.getSupportedBackends())) {
        return;
    }
    Tree.ImportPath path = that.getImportPath();
    Package importedPackage = importedPackage(path, unit);
    if (importedPackage != null) {
        path.setModel(importedPackage);
        Tree.ImportMemberOrTypeList imtl = that.getImportMemberOrTypeList();
        if (imtl != null) {
            ImportList il = imtl.getImportList();
            il.setImportedScope(importedPackage);
            Set<String> names = new HashSet<String>();
            List<Tree.ImportMemberOrType> list = imtl.getImportMemberOrTypes();
            for (Tree.ImportMemberOrType member : list) {
                names.add(importMember(member, importedPackage, il));
            }
            if (imtl.getImportWildcard() != null) {
                importAllMembers(importedPackage, names, il);
            } else if (list.isEmpty()) {
                imtl.addError("empty import list", 1020);
            }
        }
    }
}
Also used : Backends(org.eclipse.ceylon.common.Backends) ImportList(org.eclipse.ceylon.model.typechecker.model.ImportList) 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) HashSet(java.util.HashSet)

Example 32 with Package

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

the class MissingNativeVisitor method checkNativeExistence.

private boolean checkNativeExistence(Node node, Declaration model, boolean nodeIsDecl) {
    if (model == null)
        return true;
    if (!model.isToplevel() || !model.isNative())
        return true;
    Package pkg = ModelUtil.getPackage(model);
    if (pkg == null)
        return true;
    if (nodeIsDecl && !model.isNativeHeader() && !ModelUtil.isForBackend(model.getNativeBackends(), forBackend)) {
        // We don't care about declarations for other backends
        return false;
    }
    if (ModelUtil.isForBackend(model.getNativeBackends(), forBackend)) {
        return true;
    } else {
        Declaration hdr;
        if (model.isNativeHeader()) {
            hdr = model;
        } else {
            hdr = getNativeHeader(model);
        }
        if (hdr != null) {
            if (ModelUtil.isImplemented(hdr)) {
                return true;
            }
            Declaration impl = getNativeDeclaration(hdr, forBackend);
            if (impl != null) {
                return true;
            }
        } else {
            // already by the typechecker
            return true;
        }
    }
    boolean ok = checkNative(node, model);
    if (!ok) {
        String name = model.getName();
        String desc = name == null ? "header" : "'" + name + "'";
        node.addError("no native implementation for backend: native " + desc + " is not implemented for the '" + forBackend.nativeAnnotation + "' backend", forBackend);
    }
    return true;
}
Also used : Package(org.eclipse.ceylon.model.typechecker.model.Package) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration)

Example 33 with Package

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

the class ModuleSourceMapper method createPackageAndAddToModule.

private void createPackageAndAddToModule(String path) {
    final Package lastPkg = packageStack.peekLast();
    List<String> parentName = lastPkg.getName();
    final ArrayList<String> name = new ArrayList<String>(parentName.size() + 1);
    name.addAll(parentName);
    name.add(path);
    Package pkg = moduleManager.createPackage(formatPath(name), currentModule != null ? currentModule : modules.getDefaultModule());
    packageStack.addLast(pkg);
}
Also used : ArrayList(java.util.ArrayList) Package(org.eclipse.ceylon.model.typechecker.model.Package)

Example 34 with Package

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

the class ModuleSourceMapper method visitModuleFile.

public void visitModuleFile() {
    if (currentModule == null) {
        final Package currentPkg = packageStack.peekLast();
        final List<String> moduleName = currentPkg.getName();
        // we don't know the version at this stage, will be filled later
        currentModule = moduleManager.getOrCreateModule(moduleName, null);
        if (currentModule != null) {
            // TODO : not necessary anymore ? the phasedUnit will be added. And the buildModuleImport()
            currentModule.setAvailable(true);
            // function (which calls module.setAvailable()) will be called by the typeChecker
            // BEFORE the ModuleValidator.verifyModuleDependencyTree() call that uses
            // isAvailable()
            Package pkg = currentModule.getDirectPackage(currentPkg.getNameAsString());
            if (pkg == null) {
                moduleManager.bindPackageToModule(currentPkg, currentModule);
            } else {
                // Tako: this is a work-around for the fact that the Package gets
                // created before the Module it belongs to and that with multiple
                // source folders we could end up with duplicate Packages.
                // So we pop the newly created Package and replace it with the
                // existing one we found in the Module
                packageStack.pollLast();
                packageStack.addLast(pkg);
            }
        } else {
            addErrorToModule(new ArrayList<String>(), "module may not be defined at the top level of the hierarchy");
        }
    } else {
        StringBuilder error = new StringBuilder("two modules within the same hierarchy: '");
        error.append(formatPath(currentModule.getName())).append("' and '").append(formatPath(packageStack.peekLast().getName())).append("'");
        addErrorToModule(currentModule.getName(), error.toString());
        addErrorToModule(packageStack.peekLast().getName(), error.toString());
    }
}
Also used : Package(org.eclipse.ceylon.model.typechecker.model.Package)

Example 35 with Package

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

the class GenerateJsVisitor method visit.

@Override
public void visit(final Tree.PackageLiteral that) {
    Package pkg = (Package) that.getImportPath().getModel();
    MetamodelHelper.findModule(pkg.getModule(), this);
    out(".findPackage('", pkg.getNameAsString(), "')");
}
Also used : Package(org.eclipse.ceylon.model.typechecker.model.Package)

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