Search in sources :

Example 41 with Module

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

the class LanguageCompiler method loadModuleFromSource.

private Module loadModuleFromSource(String pkgName, LinkedList<JCCompilationUnit> moduleTrees, List<JCCompilationUnit> parsedTrees) {
    if (pkgName.isEmpty())
        return null;
    String moduleClassName = pkgName + ".module";
    JavaFileObject fileObject;
    try {
        if (options.get(Option.VERBOSE) != null) {
            log.printRawLines(WriterKind.NOTICE, "[Trying to load source for module " + moduleClassName + "]");
        }
        fileObject = fileManager.getJavaFileForInput(StandardLocation.SOURCE_PATH, moduleClassName, Kind.SOURCE);
        if (options.get(Option.VERBOSE) != null) {
            log.printRawLines(WriterKind.NOTICE, "[Got file object: " + fileObject + "]");
        }
    } catch (IOException e) {
        e.printStackTrace();
        return loadModuleFromSource(getParentPackage(pkgName), moduleTrees, parsedTrees);
    }
    if (fileObject != null) {
        // we really want to compile.
        for (JCCompilationUnit parsedTree : parsedTrees) {
            if (parsedTree.sourcefile.equals(fileObject) && parsedTree instanceof CeylonCompilationUnit) {
                // same file! we already parsed it, let's return this one's module
                PhasedUnit phasedUnit = ((CeylonCompilationUnit) parsedTree).phasedUnit;
                // the module visitor does load the module but does not set the unit's package module
                if (phasedUnit.getPackage().getModule() == null) {
                    // so find the module it created
                    for (Module mod : ceylonContext.getModules().getListOfModules()) {
                        // we recognise it with the unit
                        if (mod.getUnit() == phasedUnit.getUnit()) {
                            // set the package's module
                            Package pkg = phasedUnit.getPackage();
                            pkg.setModule(mod);
                            mod.getPackages().add(pkg);
                            modulesLoadedFromSource.add(mod);
                            break;
                        }
                    }
                }
                // now return it
                return phasedUnit.getPackage().getModule();
            }
        }
        JCCompilationUnit javaCompilationUnit = parse(fileObject);
        Module module;
        if (javaCompilationUnit instanceof CeylonCompilationUnit) {
            CeylonCompilationUnit ceylonCompilationUnit = (CeylonCompilationUnit) javaCompilationUnit;
            moduleTrees.add(ceylonCompilationUnit);
            // parse the module info from there
            module = ceylonCompilationUnit.phasedUnit.visitSrcModulePhase();
            ceylonCompilationUnit.phasedUnit.visitRemainingModulePhase();
            // now set the module
            if (module != null) {
                ceylonCompilationUnit.phasedUnit.getPackage().setModule(module);
            }
        } else {
            // there was a syntax error in the module descriptor, make a pretend module so that we can
            // correctly mark all declarations as part of that module, but we won't generate any code
            // for it
            ModuleManager moduleManager = phasedUnits.getModuleManager();
            module = moduleManager.getOrCreateModule(Arrays.asList(pkgName.split("\\.")), "bogus");
        }
        // now remember it
        if (module != null) {
            modulesLoadedFromSource.add(module);
            return module;
        }
    }
    return loadModuleFromSource(getParentPackage(pkgName), moduleTrees, parsedTrees);
}
Also used : JCCompilationUnit(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit) JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) CeylonCompilationUnit(org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit) IOException(java.io.IOException) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) ModuleManager(org.eclipse.ceylon.model.typechecker.util.ModuleManager) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 42 with Module

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

the class CeyloncCompilerDelegate method loadStandardModules.

@Override
public void loadStandardModules(AbstractModelLoader modelLoader) {
    org.eclipse.ceylon.compiler.typechecker.context.Context ceylonContext = LanguageCompiler.getCeylonContextInstance(context);
    Module languageModule = ceylonContext.getModules().getLanguageModule();
    if (languageModule.getVersion() == null) {
        languageModule.setVersion(TypeChecker.LANGUAGE_MODULE_VERSION);
    }
    modelLoader.loadStandardModules();
}
Also used : Module(org.eclipse.ceylon.model.typechecker.model.Module)

Example 43 with Module

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

the class LazyModuleSourceMapper method preResolveDependenciesIfRequired.

@Override
public void preResolveDependenciesIfRequired(RepositoryManager repositoryManager) {
    AbstractModelLoader modelLoader = getModuleManager().getModelLoader();
    if (!modelLoader.isFullyExportMavenDependencies())
        return;
    if (statusPrinter != null) {
        statusPrinter.clearLine();
        statusPrinter.log("Pre-resolving dependencies");
    }
    if (verbose) {
        log.printRawLines(WriterKind.NOTICE, "[Pre-resolving dependencies]");
    }
    Set<Module> compiledModules = getCompiledModules();
    Map<String, String> modules = new HashMap<>();
    ModuleImport anyImport = null;
    for (Module module : compiledModules) {
        for (ModuleImport imp : module.getImports()) {
            if (imp.getModule() == null || !compiledModules.contains(imp.getModule())) {
                if (anyImport == null)
                    anyImport = imp;
                String name = imp.getModule().getNameAsString();
                if (imp.getNamespace() != null)
                    name = imp.getNamespace() + ":" + name;
                modules.put(name, imp.getModule().getVersion());
            }
        }
    }
    if (statusPrinter != null) {
        statusPrinter.clearLine();
        statusPrinter.log("Pre-resolving found " + modules.size() + " to pre-resolve");
    }
    if (verbose) {
        log.printRawLines(WriterKind.NOTICE, "[Pre-resolving " + modules.size() + " modules]");
    }
    if (modules.isEmpty())
        return;
    Entry<String, String> first = modules.entrySet().iterator().next();
    CompilerModuleLoader ml = new CompilerModuleLoader(repositoryManager, null, modules, verbose, statusPrinter, log);
    boolean giveup = false;
    try {
        ml.loadModule(first.getKey(), first.getValue(), ModuleScope.COMPILE);
    } catch (ModuleNotFoundException e) {
        attachErrorToDependencyDeclaration(anyImport, "Pre-resolving of module failed: " + e.getMessage(), true);
        giveup = true;
    }
    if (statusPrinter != null) {
        statusPrinter.clearLine();
        // don't try to read the module count if pre-resolving failed
        if (giveup)
            statusPrinter.log("Pre-resolving failed");
        else
            statusPrinter.log("Pre-resolving resolved " + ml.getModuleCount());
    }
    if (verbose) {
        // don't try to read the module count if pre-resolving failed
        if (giveup)
            log.printRawLines(WriterKind.NOTICE, "[Pre-resolved failed]");
        else
            log.printRawLines(WriterKind.NOTICE, "[Pre-resolved " + ml.getModuleCount() + " modules]");
    }
    if (giveup)
        return;
    Overrides overrides = repositoryManager.getOverrides();
    if (overrides == null) {
        overrides = Overrides.create();
        repositoryManager.setOverrides(overrides);
    }
    ml.setupOverrides(overrides);
    ml.cleanup();
}
Also used : AbstractModelLoader(org.eclipse.ceylon.model.loader.AbstractModelLoader) ModuleNotFoundException(org.eclipse.ceylon.cmr.ceylon.loader.ModuleNotFoundException) HashMap(java.util.HashMap) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) Overrides(org.eclipse.ceylon.cmr.api.Overrides) CompilerModuleLoader(org.eclipse.ceylon.compiler.java.loader.CompilerModuleLoader) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) Module(org.eclipse.ceylon.model.typechecker.model.Module)

Example 44 with Module

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

the class LazyModuleSourceMapper method addModuleDependencyDefinition.

@Override
public void addModuleDependencyDefinition(ModuleImport moduleImport, Node definition) {
    super.addModuleDependencyDefinition(moduleImport, definition);
    Module module = moduleImport.getModule();
    if (module == null)
        return;
    String nameAsString = module.getNameAsString();
    String version = module.getVersion();
    if (version != null && (JDKUtils.isJDKModule(nameAsString) || JDKUtils.isOracleJDKModule(nameAsString))) {
        // FIXME: this does not work for JDK9 or Android
        if (JDKUtils.jdk.isLowerVersion(version)) {
            definition.addUsageWarning(Warning.importsOtherJdk, "You import JDK7, which is provided by the JDK8 you are running on, but" + " we cannot check that you are not using any JDK8-specific classes or methods. Upgrade your import to JDK8 if you depend on" + " JDK8 classes or methods.", Backend.Java);
        }
    }
}
Also used : LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) Module(org.eclipse.ceylon.model.typechecker.model.Module)

Example 45 with Module

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

the class CeylonDocToolTests method bug2346.

@Test
public void bug2346() throws Exception {
    String pathname = "test/ceylondoc";
    String moduleName = "org.eclipse.ceylon.ceylondoc.test.modules.bug2346";
    Module module = new Module();
    module.setName(Arrays.asList(moduleName));
    module.setVersion("1");
    CeylonDocTool tool = tool(Arrays.asList(new File(pathname)), Arrays.asList(new File("doc")), Arrays.asList(moduleName), true, false, false);
    tool.run();
}
Also used : CeylonDocTool(org.eclipse.ceylon.ceylondoc.CeylonDocTool) Module(org.eclipse.ceylon.model.typechecker.model.Module) File(java.io.File) Test(org.junit.Test)

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