Search in sources :

Example 1 with ModuleImport

use of com.redhat.ceylon.model.typechecker.model.ModuleImport in project ceylon-compiler by ceylon.

the class CeylonDoc method getIcons.

protected final List<String> getIcons(Object obj) {
    List<String> icons = new ArrayList<String>();
    if (obj instanceof Declaration) {
        Declaration decl = (Declaration) obj;
        Annotation deprecated = Util.findAnnotation(decl, "deprecated");
        if (deprecated != null) {
            icons.add("icon-decoration-deprecated");
        }
        if (decl instanceof ClassOrInterface || decl instanceof Constructor) {
            if (decl instanceof Interface) {
                icons.add("icon-interface");
                if (Util.isEnumerated((ClassOrInterface) decl)) {
                    icons.add("icon-decoration-enumerated");
                }
            }
            if (decl instanceof Class) {
                Class klass = (Class) decl;
                if (klass.isAnonymous()) {
                    icons.add("icon-object");
                } else {
                    icons.add("icon-class");
                }
                if (klass.isAbstract()) {
                    icons.add("icon-decoration-abstract");
                }
                if (klass.isFinal() && !klass.isAnonymous() && !klass.isAnnotation()) {
                    icons.add("icon-decoration-final");
                }
                if (Util.isEnumerated(klass)) {
                    icons.add("icon-decoration-enumerated");
                }
            }
            if (decl instanceof Constructor) {
                icons.add("icon-class");
            }
            if (!decl.isShared()) {
                icons.add("icon-decoration-local");
            }
        }
        if (decl instanceof TypedDeclaration) {
            if (decl.isShared()) {
                icons.add("icon-shared-member");
            } else {
                icons.add("icon-local-member");
            }
            if (decl.isFormal()) {
                icons.add("icon-decoration-formal");
            }
            if (decl.isActual()) {
                Declaration refinedDeclaration = decl.getRefinedDeclaration();
                if (refinedDeclaration != null) {
                    if (refinedDeclaration.isFormal()) {
                        icons.add("icon-decoration-impl");
                    }
                    if (refinedDeclaration.isDefault()) {
                        icons.add("icon-decoration-over");
                    }
                }
            }
            if (((TypedDeclaration) decl).isVariable()) {
                icons.add("icon-decoration-variable");
            }
        }
        if (decl instanceof TypeAlias || decl instanceof NothingType) {
            icons.add("icon-type-alias");
        }
        if (decl.isAnnotation()) {
            icons.add("icon-decoration-annotation");
        }
    }
    if (obj instanceof Package) {
        Package pkg = (Package) obj;
        icons.add("icon-package");
        if (!pkg.isShared()) {
            icons.add("icon-decoration-local");
        }
    }
    if (obj instanceof ModuleImport) {
        ModuleImport moduleImport = (ModuleImport) obj;
        icons.add("icon-module");
        if (moduleImport.isExport()) {
            icons.add("icon-module-exported-decoration");
        }
        if (moduleImport.isOptional()) {
            icons.add("icon-module-optional-decoration");
        }
    }
    if (obj instanceof Module) {
        icons.add("icon-module");
    }
    return icons;
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Constructor(com.redhat.ceylon.model.typechecker.model.Constructor) ArrayList(java.util.ArrayList) TypeAlias(com.redhat.ceylon.model.typechecker.model.TypeAlias) Annotation(com.redhat.ceylon.model.typechecker.model.Annotation) ModuleImport(com.redhat.ceylon.model.typechecker.model.ModuleImport) Class(com.redhat.ceylon.model.typechecker.model.Class) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) Package(com.redhat.ceylon.model.typechecker.model.Package) Module(com.redhat.ceylon.model.typechecker.model.Module) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) NothingType(com.redhat.ceylon.model.typechecker.model.NothingType)

Example 2 with ModuleImport

use of com.redhat.ceylon.model.typechecker.model.ModuleImport in project ceylon-compiler by ceylon.

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(com.redhat.ceylon.model.typechecker.model.ModuleImport) ArrayList(java.util.ArrayList)

Example 3 with ModuleImport

use of com.redhat.ceylon.model.typechecker.model.ModuleImport in project ceylon-compiler by ceylon.

the class CMRTests method testOverridesCeylonModuleShareImport.

@Test
public void testOverridesCeylonModuleShareImport() {
    setupBinaryModulesForOverridesCeylonModuleTests();
    ErrorCollector collector = new ErrorCollector();
    CeyloncTaskImpl compilerTask = getCompilerTask(Arrays.asList("-src", getPackagePath() + "/modules", "-overrides", getPackagePath() + "modules/overridesCeylonModule/overrides-share-c-import.xml"), collector, "modules/overridesCeylonModule/module.ceylon");
    ModulesRetriever modulesRetriever = new ModulesRetriever(compilerTask.getContext());
    compilerTask.setTaskListener(modulesRetriever);
    Boolean result = compilerTask.call();
    Assert.assertEquals(Boolean.TRUE, result);
    Module a = modulesRetriever.modules.get("a");
    assert (a != null);
    ModuleImport cImport = getModuleImport(a, "c");
    assert (cImport != null);
    assertEquals("The 'c' module import should be seen as 'exported' after applying the overrides file", true, cImport.isExport());
}
Also used : ModuleImport(com.redhat.ceylon.model.typechecker.model.ModuleImport) ErrorCollector(com.redhat.ceylon.compiler.java.test.ErrorCollector) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) Module(com.redhat.ceylon.model.typechecker.model.Module) Test(org.junit.Test)

Example 4 with ModuleImport

use of com.redhat.ceylon.model.typechecker.model.ModuleImport in project ceylon-compiler by ceylon.

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 (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("dependencies"), make().NewArray(null, null, imports.toList())));
    JCExpression nativeBackendsAnnotationValue = makeNativeBackendsAnnotationValue(module.getNativeBackends());
    if (nativeBackendsAnnotationValue != null)
        annotationArgs.add(nativeBackendsAnnotationValue);
    return makeModelAnnotation(syms().ceylonAtModuleType, annotationArgs.toList());
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) ListBuffer(com.sun.tools.javac.util.ListBuffer) ModuleImport(com.redhat.ceylon.model.typechecker.model.ModuleImport) JCTree(com.sun.tools.javac.tree.JCTree) Module(com.redhat.ceylon.model.typechecker.model.Module) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Example 5 with ModuleImport

use of com.redhat.ceylon.model.typechecker.model.ModuleImport in project ceylon-compiler by ceylon.

the class LazyModuleSourceMapper method resolveModule.

@Override
public void resolveModule(ArtifactResult artifact, Module module, ModuleImport moduleImport, LinkedList<Module> dependencyTree, List<PhasedUnits> phasedUnitsOfDependencies, boolean forCompiledModule) {
    String moduleName = module.getNameAsString();
    LazyModuleManager moduleManager = getModuleManager();
    boolean moduleLoadedFromSource = moduleManager.isModuleLoadedFromSource(moduleName);
    boolean isLanguageModule = module == module.getLanguageModule();
    // module in question will be in the classpath
    if (moduleLoadedFromSource || forCompiledModule) {
        String standardisedModuleName = ModuleUtil.toCeylonModuleName(moduleName);
        // check for an already loaded module with the same name but different version
        for (Module loadedModule : getContext().getModules().getListOfModules()) {
            String loadedModuleName = loadedModule.getNameAsString();
            String standardisedLoadedModuleName = ModuleUtil.toCeylonModuleName(loadedModuleName);
            boolean sameModule = loadedModuleName.equals(moduleName);
            boolean similarModule = standardisedLoadedModuleName.equals(standardisedModuleName);
            if ((sameModule || similarModule) && !loadedModule.getVersion().equals(module.getVersion()) && moduleManager.getModelLoader().isModuleInClassPath(loadedModule)) {
                if (sameModule) {
                    String[] versions = VersionComparator.orderVersions(module.getVersion(), loadedModule.getVersion());
                    String error = "source code imports two different versions of module '" + moduleName + "': " + "version '" + versions[0] + "' and version '" + versions[1] + "'";
                    addErrorToModule(dependencyTree.getFirst(), error);
                } else {
                    String moduleA;
                    String moduleB;
                    if (loadedModuleName.compareTo(moduleName) < 0) {
                        moduleA = ModuleUtil.makeModuleName(loadedModuleName, loadedModule.getVersion());
                        moduleB = ModuleUtil.makeModuleName(moduleName, module.getVersion());
                    } else {
                        moduleA = ModuleUtil.makeModuleName(moduleName, module.getVersion());
                        moduleB = ModuleUtil.makeModuleName(loadedModuleName, loadedModule.getVersion());
                    }
                    String error = "source code imports two different versions of similar modules '" + moduleA + "' and '" + moduleB + "'";
                    addWarningToModule(dependencyTree.getFirst(), Warning.similarModule, error);
                }
                return;
            }
        }
    }
    if (moduleLoadedFromSource) {
        super.resolveModule(artifact, module, moduleImport, dependencyTree, phasedUnitsOfDependencies, forCompiledModule);
    } else if (forCompiledModule || isLanguageModule || moduleManager.shouldLoadTransitiveDependencies()) {
        // we only add stuff to the classpath and load the modules if we need them to compile our modules
        // To be able to load it from the corresponding archive
        moduleManager.getModelLoader().addModuleToClassPath(module, artifact);
        if (!module.isDefault() && !moduleManager.getModelLoader().loadCompiledModule(module)) {
            // we didn't find module.class so it must be a java module if it's not the default module
            ((LazyModule) module).setJava(true);
            module.setNativeBackends(Backend.Java.asSet());
            List<ArtifactResult> deps = artifact.dependencies();
            for (ArtifactResult dep : deps) {
                Module dependency = moduleManager.getOrCreateModule(ModuleManager.splitModuleName(dep.name()), dep.version());
                ModuleImport depImport = moduleManager.findImport(module, dependency);
                if (depImport == null) {
                    moduleImport = new ModuleImport(dependency, dep.importType() == ImportType.OPTIONAL, dep.importType() == ImportType.EXPORT, Backend.Java);
                    module.addImport(moduleImport);
                }
            }
        }
        LazyModule lazyModule = (LazyModule) module;
        if (!lazyModule.isJava() && !module.isDefault()) {
            // it must be a Ceylon module
            // default modules don't have any module descriptors so we can't check them
            Overrides overrides = getContext().getRepositoryManager().getOverrides();
            if (overrides != null) {
                if (overrides.getArtifactOverrides(new ArtifactContext(artifact.name(), artifact.version())) != null) {
                    Set<ModuleDependencyInfo> existingModuleDependencies = new HashSet<>();
                    for (ModuleImport i : lazyModule.getImports()) {
                        Module m = i.getModule();
                        if (m != null) {
                            existingModuleDependencies.add(new ModuleDependencyInfo(m.getNameAsString(), m.getVersion(), i.isOptional(), i.isExport()));
                        }
                    }
                    ModuleInfo sourceModuleInfo = new ModuleInfo(null, existingModuleDependencies);
                    ModuleInfo newModuleInfo = overrides.applyOverrides(artifact.name(), artifact.version(), sourceModuleInfo);
                    List<ModuleImport> newModuleImports = new ArrayList<>();
                    for (ModuleDependencyInfo dep : newModuleInfo.getDependencies()) {
                        Module dependency = moduleManager.getOrCreateModule(ModuleManager.splitModuleName(dep.getName()), dep.getVersion());
                        Backends backends = dependency.getNativeBackends();
                        moduleImport = new ModuleImport(dependency, dep.isOptional(), dep.isExport(), backends);
                        newModuleImports.add(moduleImport);
                    }
                    module.overrideImports(newModuleImports);
                }
            }
            if (!Versions.isJvmBinaryVersionSupported(lazyModule.getMajor(), lazyModule.getMinor())) {
                attachErrorToDependencyDeclaration(moduleImport, dependencyTree, "version '" + lazyModule.getVersion() + "' of module '" + module.getNameAsString() + "' was compiled by an incompatible version of the compiler (binary version " + lazyModule.getMajor() + "." + lazyModule.getMinor() + " of module is not compatible with binary version " + Versions.JVM_BINARY_MAJOR_VERSION + "." + Versions.JVM_BINARY_MINOR_VERSION + " of this compiler)");
            }
        }
        // module is now available
        module.setAvailable(true);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) LazyModuleManager(com.redhat.ceylon.model.loader.model.LazyModuleManager) ArtifactContext(com.redhat.ceylon.cmr.api.ArtifactContext) LazyModule(com.redhat.ceylon.model.loader.model.LazyModule) ArtifactResult(com.redhat.ceylon.model.cmr.ArtifactResult) Backends(com.redhat.ceylon.common.Backends) ModuleInfo(com.redhat.ceylon.cmr.api.ModuleInfo) ModuleImport(com.redhat.ceylon.model.typechecker.model.ModuleImport) Overrides(com.redhat.ceylon.cmr.api.Overrides) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ModuleDependencyInfo(com.redhat.ceylon.cmr.api.ModuleDependencyInfo) LazyModule(com.redhat.ceylon.model.loader.model.LazyModule) Module(com.redhat.ceylon.model.typechecker.model.Module)

Aggregations

ModuleImport (com.redhat.ceylon.model.typechecker.model.ModuleImport)6 Module (com.redhat.ceylon.model.typechecker.model.Module)5 ArrayList (java.util.ArrayList)3 ArtifactContext (com.redhat.ceylon.cmr.api.ArtifactContext)1 ModuleDependencyInfo (com.redhat.ceylon.cmr.api.ModuleDependencyInfo)1 ModuleInfo (com.redhat.ceylon.cmr.api.ModuleInfo)1 Overrides (com.redhat.ceylon.cmr.api.Overrides)1 Backends (com.redhat.ceylon.common.Backends)1 ErrorCollector (com.redhat.ceylon.compiler.java.test.ErrorCollector)1 CeyloncTaskImpl (com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl)1 ArtifactResult (com.redhat.ceylon.model.cmr.ArtifactResult)1 LazyModule (com.redhat.ceylon.model.loader.model.LazyModule)1 LazyModuleManager (com.redhat.ceylon.model.loader.model.LazyModuleManager)1 Annotation (com.redhat.ceylon.model.typechecker.model.Annotation)1 Class (com.redhat.ceylon.model.typechecker.model.Class)1 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)1 Constructor (com.redhat.ceylon.model.typechecker.model.Constructor)1 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)1 Interface (com.redhat.ceylon.model.typechecker.model.Interface)1 NothingType (com.redhat.ceylon.model.typechecker.model.NothingType)1