Search in sources :

Example 1 with Backends

use of org.eclipse.ceylon.common.Backends in project ceylon by eclipse.

the class ModuleVersionReader method getModuleVersionDetailsFromSource.

/**
 * Reads a module descriptor and returns its information
 * @param moduleName The name of the module
 * @param srcDir The source directory where to find the descriptor
 * @return A <code>ModuleVersionsDetails</code> with the encountered information
 * @throws NoSuchModuleException if the module could not be found
 */
public static ModuleVersionDetails getModuleVersionDetailsFromSource(String moduleName, File srcDir) throws NoSuchModuleException {
    ModuleDescriptorReader mdr = new ModuleDescriptorReader(moduleName, srcDir);
    String module = mdr.getModuleName();
    String version = mdr.getModuleVersion();
    // PS In case the module descriptor was found but could not be parsed
    // we'll create an invalid details object
    ModuleVersionDetails mvd = new ModuleVersionDetails(module != null ? module : "", version != null ? version : "", mdr.getModuleGroupId(), mdr.getModuleArtifactId());
    mvd.setLabel(mdr.getModuleLabel());
    mvd.setLicense(mdr.getModuleLicense());
    List<String> by = mdr.getModuleAuthors();
    if (by != null) {
        mvd.getAuthors().addAll(by);
    }
    SortedSet<ModuleDependencyInfo> dependencies = new TreeSet<>();
    for (Object[] dep : mdr.getModuleImports()) {
        dependencies.add(new ModuleDependencyInfo((String) dep[0], (String) dep[1], (String) dep[2], (Boolean) dep[3], (Boolean) dep[4], (Backends) dep[5]));
    }
    mvd.setDependencies(dependencies);
    mvd.setRemote(false);
    mvd.setOrigin("Local source folder");
    return mvd;
}
Also used : ModuleDescriptorReader(org.eclipse.ceylon.common.ModuleDescriptorReader) Backends(org.eclipse.ceylon.common.Backends) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) TreeSet(java.util.TreeSet) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)

Example 2 with Backends

use of org.eclipse.ceylon.common.Backends in project ceylon by eclipse.

the class ModuleDoc method writeDependencyRow.

private void writeDependencyRow(ModuleImport moduleImport) throws IOException {
    StringBuilder tooltip = new StringBuilder();
    if (moduleImport.isExport()) {
        tooltip.append("shared ");
    }
    if (moduleImport.isOptional()) {
        tooltip.append("optional ");
    }
    tooltip.append("import of module ");
    tooltip.append(moduleImport.getModule().getNameAsString());
    tooltip.append(" ");
    tooltip.append(moduleImport.getModule().getVersion());
    open("tr");
    open("td class='shrink'");
    open("span title='" + tooltip + "'");
    writeIcon(moduleImport);
    close("span");
    open("code class='decl-label'");
    linkRenderer().to(moduleImport.getModule()).write();
    Backends backends = moduleImport.getNativeBackends();
    if (!backends.none()) {
        write(" (");
        write(backends.names());
        write(")");
    }
    close("code");
    close("td");
    open("td class='shrink'");
    open("code");
    write(moduleImport.getModule().getVersion());
    close("code");
    close("td");
    open("td");
    open("div class='description import-description'");
    write(getDoc(moduleImport, linkRenderer()));
    close("div");
    close("td");
    close("tr");
}
Also used : Backends(org.eclipse.ceylon.common.Backends)

Example 3 with Backends

use of org.eclipse.ceylon.common.Backends 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 4 with Backends

use of org.eclipse.ceylon.common.Backends in project ceylon by eclipse.

the class BytecodeUtils method getDependencies.

private static Set<ModuleDependencyInfo> getDependencies(ClassFile moduleInfo, Object[] dependencies, String module, String version, String groupId, String artifactId, Overrides overrides) {
    if (dependencies == null) {
        return Collections.<ModuleDependencyInfo>emptySet();
    }
    int[] binver = getBinaryVersions(moduleInfo);
    boolean supportsNamespaces = binver != null && ModuleUtil.supportsImportsWithNamespaces(binver[0], binver[1]);
    Set<ModuleDependencyInfo> result = new HashSet<ModuleDependencyInfo>(dependencies.length);
    for (Object depObject : dependencies) {
        Annotation dep = (Annotation) depObject;
        String namespace;
        String modName = (String) ClassFileUtil.getAnnotationValue(moduleInfo, dep, "name");
        if (supportsNamespaces) {
            namespace = (String) ClassFileUtil.getAnnotationValue(moduleInfo, dep, "namespace");
            if (namespace != null && namespace.isEmpty()) {
                namespace = null;
            }
        } else {
            if (ModuleUtil.isMavenModule(modName)) {
                namespace = MavenRepository.NAMESPACE;
            } else {
                namespace = null;
            }
        }
        String depVersion = (String) ClassFileUtil.getAnnotationValue(moduleInfo, dep, "version");
        boolean export = asBoolean(moduleInfo, dep, "export");
        boolean optional = asBoolean(moduleInfo, dep, "optional");
        Backends backends = Backends.ANY;
        Object[] backendNames = (Object[]) ClassFileUtil.getAnnotationValue(moduleInfo, dep, "dependencies");
        if (backendNames != null) {
            for (Object backend : backendNames) {
                backends = backends.merged(Backend.fromAnnotation((String) backend));
            }
        }
        result.add(new ModuleDependencyInfo(namespace, modName, depVersion, optional, export, backends));
    }
    if (overrides != null) {
        result = overrides.applyOverrides(module, version, new ModuleInfo(null, module, version, groupId, artifactId, null, null, result)).getDependencies();
    }
    return result;
}
Also used : Backends(org.eclipse.ceylon.common.Backends) ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) Annotation(org.eclipse.ceylon.langtools.classfile.Annotation) HashSet(java.util.HashSet)

Example 5 with Backends

use of org.eclipse.ceylon.common.Backends in project ceylon by eclipse.

the class ModuleVisitor method visit.

@Override
public void visit(Tree.ModuleDescriptor that) {
    Tree.AnnotationList al = that.getAnnotationList();
    Unit u = unit.getUnit();
    moduleBackends = getNativeBackend(al, u);
    super.visit(that);
    if (phase == Phase.SRC_MODULE) {
        String version = getVersionString(that.getVersion(), null, that);
        Tree.ImportPath importPath = that.getImportPath();
        for (Tree.Identifier id : importPath.getIdentifiers()) {
            if (containsDiscouragedChar(id)) {
                id.addUsageWarning(Warning.packageName, "all-lowercase ASCII module names are recommended");
            }
        }
        List<String> name = getNameAsList(importPath);
        if (pkg.getNameAsString().isEmpty()) {
            that.addError("module descriptor encountered in root source directory");
        } else if (name.isEmpty()) {
            that.addError("missing module name");
        } else {
            String initialName = name.get(0);
            Backends unitBackends = u.getSupportedBackends();
            if (initialName.equals(DEFAULT_MODULE_NAME)) {
                importPath.addError("reserved module name: 'default'");
            } else if (name.size() == 1 && initialName.equals("ceylon")) {
                importPath.addError("reserved module name: 'ceylon'");
            } else if (!moduleBackends.none() && moduleBackends.header()) {
                that.addError("missing backend argument for native annotation on module: " + formatPath(importPath.getIdentifiers()));
            } else if (!moduleBackends.none() && !unitBackends.none() && !unitBackends.supports(moduleBackends)) {
                that.addError("module not meant for this backend: " + formatPath(importPath.getIdentifiers()));
            } else {
                if (initialName.equals("ceylon")) {
                    importPath.addUsageWarning(Warning.ceylonNamespace, "discouraged module name: this namespace is used by Ceylon platform modules");
                } else if (initialName.equals("java") || initialName.equals("javax")) {
                    importPath.addUnsupportedError("unsupported module name: this namespace is used by Java platform modules");
                }
                mainModule = moduleManager.getOrCreateModule(name, version);
                importPath.setModel(mainModule);
                if (!completeOnlyAST) {
                    mainModule.setUnit(u);
                    mainModule.setVersion(version);
                // if (hasAnnotation(al, "label", u)) {
                // mainModule.setLabel(getAnnotationArgument(
                // getAnnotation(al, "label", u),
                // 0, u));
                // }
                }
                String nameString = formatPath(importPath.getIdentifiers());
                if (!pkg.getNameAsString().equals(nameString)) {
                    importPath.addError("module name does not match descriptor location: '" + nameString + "' should be '" + pkg.getNameAsString() + "'", 8000);
                }
                if (!completeOnlyAST) {
                    moduleManagerUtil.addLinkBetweenModuleAndNode(mainModule, that);
                    mainModule.setAvailable(true);
                    mainModule.getAnnotations().clear();
                    buildAnnotations(al, mainModule.getAnnotations());
                    mainModule.setNativeBackends(moduleBackends);
                    Tree.QuotedLiteral classifier = that.getClassifier();
                    if (classifier != null) {
                        mainModule.setClassifier(getNameString(classifier));
                        classifier.addUnsupportedError("classifiers not yet supported");
                    }
                    Tree.QuotedLiteral artifact = that.getArtifact();
                    if (artifact != null) {
                        mainModule.setArtifactId(getNameString(artifact));
                    }
                    Tree.ImportPath groupImportPath = that.getGroupImportPath();
                    Tree.QuotedLiteral groupQuotedLiteral = that.getGroupQuotedLiteral();
                    if (groupImportPath != null) {
                        mainModule.setGroupId(formatPath(groupImportPath.getIdentifiers()));
                    } else if (groupQuotedLiteral != null) {
                        mainModule.setGroupId(getNameString(groupQuotedLiteral));
                    }
                }
            }
        }
        HashSet<String> set = new HashSet<String>();
        Tree.ImportModuleList iml = that.getImportModuleList();
        if (iml != null) {
            for (Tree.ImportModule im : iml.getImportModules()) {
                String path = im.getName();
                if (path != null) {
                    if (!set.add(path)) {
                        im.addError("duplicate module import: '" + path + "'");
                    }
                }
            }
        }
    }
    moduleBackends = Backends.ANY;
}
Also used : Unit(org.eclipse.ceylon.model.typechecker.model.Unit) Backends(org.eclipse.ceylon.common.Backends) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) HashSet(java.util.HashSet)

Aggregations

Backends (org.eclipse.ceylon.common.Backends)21 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)7 Module (org.eclipse.ceylon.model.typechecker.model.Module)7 HashSet (java.util.HashSet)6 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)6 ModuleImport (org.eclipse.ceylon.model.typechecker.model.ModuleImport)6 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)5 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)4 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)3 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)3 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)3 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)3 ModelUtil.getNativeDeclaration (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration)3 Unit (org.eclipse.ceylon.model.typechecker.model.Unit)3 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)2 Backend (org.eclipse.ceylon.common.Backend)2 AnalyzerUtil.getPackageTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration)2