Search in sources :

Example 11 with Module

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

the class CachedTOCJarsTest method spacesOnPathTest.

@Test
public void spacesOnPathTest() throws IOException {
    CachedTOCJars cachedTOCJars = new CachedTOCJars();
    Module module = new Module();
    module.setName(Collections.singletonList("testModule"));
    module.setVersion("testVersion");
    final File artifactFile = File.createTempFile("path with spaces", ".jar");
    try {
        artifactFile.deleteOnExit();
        ZipOutputStream artifactOut = new ZipOutputStream(new FileOutputStream(artifactFile));
        try {
            artifactOut.putNextEntry(new ZipEntry(ALSO_INSIDE_JAR));
        } finally {
            artifactOut.close();
        }
        ArtifactResult artifact = new TestArtifactResult(artifactFile, module);
        cachedTOCJars.addJar(artifact, module);
        String uriPart = cachedTOCJars.getContentUri(module, ALSO_INSIDE_JAR).getSchemeSpecificPart();
        // I'm not comparing URI part for equality to avoid symbolic links resolution issues.
        Assert.assertTrue(uriPart, uriPart.endsWith(artifactFile.getName() + "!" + ALSO_INSIDE_JAR));
    } finally {
        artifactFile.delete();
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) CachedTOCJars(org.eclipse.ceylon.model.loader.impl.reflect.CachedTOCJars) Module(org.eclipse.ceylon.model.typechecker.model.Module) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) Test(org.junit.Test)

Example 12 with Module

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

the class TypeChecker method executePhases.

private void executePhases(PhasedUnits phasedUnits, boolean forceSilence) {
    List<PhasedUnit> listOfUnits = phasedUnits.getPhasedUnits();
    phasedUnits.getModuleManager().prepareForTypeChecking();
    phasedUnits.visitModules();
    phasedUnits.getModuleManager().modulesVisited();
    // By now le language module version should be known
    // (as local) or we should use the default one.
    Module languageModule = context.getModules().getLanguageModule();
    if (languageModule.getVersion() == null) {
        languageModule.setVersion(LANGUAGE_MODULE_VERSION);
    }
    ModuleValidator moduleValidator = new ModuleValidator(context, phasedUnits);
    if (verifyDependencies) {
        moduleValidator.verifyModuleDependencyTree();
    }
    phasedUnitsOfDependencies = moduleValidator.getPhasedUnitsOfDependencies();
    executePhases(listOfUnits);
    if (!forceSilence) {
        for (PhasedUnit pu : listOfUnits) {
            if (verbose) {
                pu.display();
            }
            pu.generateStatistics(statsVisitor);
            pu.runAssertions(assertionVisitor);
        }
        if (verbose || statistics) {
            statsVisitor.print();
        }
        assertionVisitor.print(verbose);
    }
}
Also used : Module(org.eclipse.ceylon.model.typechecker.model.Module) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) ModuleValidator(org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleValidator)

Example 13 with Module

use of org.eclipse.ceylon.model.typechecker.model.Module 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 14 with Module

use of org.eclipse.ceylon.model.typechecker.model.Module 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)

Example 15 with Module

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

the class ExpressionTransformer method transform.

public JCTree transform(Tree.ModuleLiteral expr) {
    at(expr);
    Module mod = (Module) expr.getImportPath().getModel();
    return makeModuleLiteralCall(mod);
}
Also used : Module(org.eclipse.ceylon.model.typechecker.model.Module)

Aggregations

Module (org.eclipse.ceylon.model.typechecker.model.Module)113 LazyModule (org.eclipse.ceylon.model.loader.model.LazyModule)37 Package (org.eclipse.ceylon.model.typechecker.model.Package)26 ModuleImport (org.eclipse.ceylon.model.typechecker.model.ModuleImport)25 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)20 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)19 ArrayList (java.util.ArrayList)18 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)16 File (java.io.File)14 Type (org.eclipse.ceylon.model.typechecker.model.Type)14 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 FunctionalInterfaceType (org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType)9 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)9 Test (org.junit.Test)9 Value (org.eclipse.ceylon.model.typechecker.model.Value)8 LinkedList (java.util.LinkedList)7 List (java.util.List)7 Backends (org.eclipse.ceylon.common.Backends)7 ClassMirror (org.eclipse.ceylon.model.loader.mirror.ClassMirror)7