Search in sources :

Example 26 with ModuleImport

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

the class LazyModuleManager method addImplicitImports.

@Override
public void addImplicitImports() {
    Module languageModule = modules.getLanguageModule();
    for (Module m : modules.getListOfModules()) {
        // Java modules don't depend on ceylon.language
        if ((m instanceof LazyModule == false || !((LazyModule) m).isJava()) && !m.equals(languageModule)) {
            // add ceylon.language if required
            ModuleImport moduleImport = findImport(m, languageModule);
            if (moduleImport == null) {
                moduleImport = new ModuleImport(null, languageModule, false, true);
                m.addImport(moduleImport);
            }
        }
    }
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) Module(org.eclipse.ceylon.model.typechecker.model.Module)

Example 27 with ModuleImport

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

the class AbstractTransformer method makeAtModule.

List<JCAnnotation> makeAtModule(ModuleDescriptor moduleDescriptor) {
    Module module = moduleDescriptor.getUnit().getPackage().getModule();
    ListBuffer<JCExpression> imports = new ListBuffer<JCTree.JCExpression>();
    for (ModuleImport dependency : module.getImports()) {
        if (!isForBackend(dependency.getNativeBackends(), Backend.Java)) {
            continue;
        }
        Module dependencyModule = dependency.getModule();
        JCExpression dependencyName = make().Assign(naming.makeUnquotedIdent("name"), make().Literal(dependencyModule.getNameAsString()));
        JCExpression dependencyVersion = null;
        String versionInDescriptor = getImportVersionFromDescriptor(moduleDescriptor, dependency, dependencyModule);
        if (versionInDescriptor != null)
            dependencyVersion = make().Assign(naming.makeUnquotedIdent("version"), make().Literal(versionInDescriptor));
        List<JCExpression> spec;
        if (dependencyVersion != null)
            spec = List.<JCExpression>of(dependencyName, dependencyVersion);
        else
            spec = List.<JCExpression>of(dependencyName);
        if (dependency.getNamespace() != null && !DefaultRepository.NAMESPACE.equals(dependency.getNamespace())) {
            JCExpression dependencyNamespace = make().Assign(naming.makeUnquotedIdent("namespace"), make().Literal(dependency.getNamespace()));
            spec = spec.append(dependencyNamespace);
        }
        if (Util.getAnnotation(dependency, "shared") != null) {
            JCExpression exported = make().Assign(naming.makeUnquotedIdent("export"), make().Literal(true));
            spec = spec.append(exported);
        }
        if (Util.getAnnotation(dependency, "optional") != null) {
            JCExpression exported = make().Assign(naming.makeUnquotedIdent("optional"), make().Literal(true));
            spec = spec.append(exported);
        }
        JCExpression nativeBackendsAnnotationValue = makeNativeBackendsAnnotationValue(dependency.getNativeBackends());
        if (nativeBackendsAnnotationValue != null)
            spec = spec.append(nativeBackendsAnnotationValue);
        JCAnnotation atImport = make().Annotation(makeIdent(syms().ceylonAtImportType), spec);
        imports.add(atImport);
    }
    ListBuffer<JCExpression> annotationArgs = getLicenseAuthorsDocAnnotationArguments(module.getNameAsString(), module.getAnnotations());
    annotationArgs.add(make().Assign(naming.makeUnquotedIdent("version"), make().Literal(module.getVersion())));
    // annotationArgs.add(make().Assign(naming.makeUnquotedIdent("label"), make().Literal(module.getLabel())));
    annotationArgs.add(make().Assign(naming.makeUnquotedIdent("dependencies"), make().NewArray(null, null, imports.toList())));
    JCExpression nativeBackendsAnnotationValue = makeNativeBackendsAnnotationValue(module.getNativeBackends());
    if (nativeBackendsAnnotationValue != null)
        annotationArgs.add(nativeBackendsAnnotationValue);
    if (module.getGroupId() != null)
        annotationArgs.add(make().Assign(naming.makeUnquotedIdent("group"), make().Literal(module.getGroupId())));
    if (module.getArtifactId() != null)
        annotationArgs.add(make().Assign(naming.makeUnquotedIdent("artifact"), make().Literal(module.getArtifactId())));
    return makeModelAnnotation(syms().ceylonAtModuleType, annotationArgs.toList());
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Module(org.eclipse.ceylon.model.typechecker.model.Module) JCAnnotation(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation)

Example 28 with ModuleImport

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

the class ModuleDoc method writeDependencies.

private void writeDependencies() throws IOException {
    List<ModuleImport> moduleImports = new ArrayList<ModuleImport>(module.getImports());
    Iterator<ModuleImport> moduleImportIterator = moduleImports.listIterator();
    while (moduleImportIterator.hasNext()) {
        ModuleImport moduleImport = moduleImportIterator.next();
        if (moduleImport.getModule().getNameAsString().equals(AbstractModelLoader.CEYLON_LANGUAGE)) {
            moduleImportIterator.remove();
        }
    }
    Collections.sort(moduleImports, ModuleImportComparatorByName.INSTANCE);
    if (!moduleImports.isEmpty()) {
        openTable("section-dependencies", "Dependencies", 3, false);
        for (ModuleImport moduleImport : moduleImports) {
            writeDependencyRow(moduleImport);
        }
        closeTable();
    }
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) ArrayList(java.util.ArrayList)

Example 29 with ModuleImport

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

the class ModuleManager method overridesModule.

public Module overridesModule(ArtifactResult artifact, Module module, ModuleImport moduleImport) {
    String namespace = artifact.namespace();
    String realName = artifact.name();
    String realVersion = artifact.version();
    if (!realName.equals(module.getNameAsString()) || !realVersion.equals(module.getVersion())) {
        if (module != module.getLanguageModule()) {
            Module realModule = getOrCreateModule(splitModuleName(realName), realVersion);
            moduleImport.override(new ModuleImport(namespace, realModule, moduleImport.isOptional(), moduleImport.isExport()));
            return realModule;
        }
    }
    return null;
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) Module(org.eclipse.ceylon.model.typechecker.model.Module)

Example 30 with ModuleImport

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

the class ModuleManager method initCoreModules.

public void initCoreModules(Modules initialModules) {
    modules = initialModules;
    if (modules.getLanguageModule() == null) {
        // build empty package
        Package emptyPackage = createPackage("", null);
        // build default module
        // (module in which packages belong to when not explicitly under a module)
        List<String> defaultModuleName = singletonList(DEFAULT_MODULE_NAME);
        Module defaultModule = createModule(defaultModuleName, "unversioned");
        // defaultModule.setDefault(true);
        defaultModule.setAvailable(true);
        bindPackageToModule(emptyPackage, defaultModule);
        modules.getListOfModules().add(defaultModule);
        modules.setDefaultModule(defaultModule);
        // create language module and add it as a dependency of defaultModule
        // since packages outside a module cannot declare dependencies
        List<String> languageName = asList("ceylon", "language");
        Module languageModule = createModule(languageName, CEYLON_VERSION_NUMBER);
        languageModule.setLanguageModule(languageModule);
        // not available yet
        languageModule.setAvailable(false);
        modules.setLanguageModule(languageModule);
        modules.getListOfModules().add(languageModule);
        defaultModule.addImport(new ModuleImport(null, languageModule, false, false));
        defaultModule.setLanguageModule(languageModule);
    }
}
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)

Aggregations

ModuleImport (org.eclipse.ceylon.model.typechecker.model.ModuleImport)30 Module (org.eclipse.ceylon.model.typechecker.model.Module)25 HashSet (java.util.HashSet)8 ArrayList (java.util.ArrayList)7 LazyModule (org.eclipse.ceylon.model.loader.model.LazyModule)7 Package (org.eclipse.ceylon.model.typechecker.model.Package)7 Backends (org.eclipse.ceylon.common.Backends)6 LinkedList (java.util.LinkedList)3 List (java.util.List)3 HashMap (java.util.HashMap)2 Overrides (org.eclipse.ceylon.cmr.api.Overrides)2 ImportModule (org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportModule)2 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)2 AbstractModelLoader (org.eclipse.ceylon.model.loader.AbstractModelLoader)2 Annotation (org.eclipse.ceylon.model.typechecker.model.Annotation)2 Unit (org.eclipse.ceylon.model.typechecker.model.Unit)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1