Search in sources :

Example 16 with Backends

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

the class DeclarationVisitor method handleNativeAnnotation.

private void handleNativeAnnotation(Tree.Declaration that, Declaration model, Tree.AnnotationList al) {
    Tree.Annotation na = getAnnotation(al, "native", unit);
    Backends backends = Backends.ANY;
    if (na != null) {
        int cnt = getAnnotationArgumentCount(na);
        if (cnt == 0) {
            backends = Backends.HEADER;
        } else {
            for (int i = 0; i < cnt; i++) {
                String be = getAnnotationArgument(na, i, unit);
                Backend backend = Backend.fromAnnotation(be);
                if (backend != null) {
                    if (!backend.isRegistered()) {
                        na.addError("illegal native backend name: '\"" + backend.nativeAnnotation + "\"' (must be either '\"jvm\"' or '\"js\"')");
                    }
                    backends = backends.merged(backend);
                }
            }
        }
    }
    model.setNativeBackends(backends);
    if (model.isNative() && model.isFormal()) {
        that.addError("declaration may not be annotated both 'formal' and 'native'");
    }
}
Also used : Backends(org.eclipse.ceylon.common.Backends) Backend(org.eclipse.ceylon.common.Backend) TreeUtil.getNativeBackend(org.eclipse.ceylon.compiler.typechecker.tree.TreeUtil.getNativeBackend) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 17 with Backends

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

the class ModuleSourceMapper method overrideModuleImports.

protected void overrideModuleImports(Module module, ArtifactResult artifact) {
    Overrides overrides = getContext().getRepositoryManager().getOverrides();
    if (overrides != null) {
        Set<ModuleDependencyInfo> existingModuleDependencies = new HashSet<>();
        for (ModuleImport i : module.getImports()) {
            Module m = i.getModule();
            if (m != null) {
                existingModuleDependencies.add(new ModuleDependencyInfo(i.getNamespace(), m.getNameAsString(), m.getVersion(), i.isOptional(), i.isExport(), i.getNativeBackends()));
            }
        }
        ModuleInfo sourceModuleInfo = new ModuleInfo(artifact.namespace(), artifact.name(), artifact.version(), artifact.groupId(), artifact.artifactId(), artifact.classifier(), null, existingModuleDependencies);
        ModuleInfo newModuleInfo = overrides.applyOverrides(artifact.name(), artifact.version(), sourceModuleInfo);
        List<ModuleImport> newModuleImports = new ArrayList<>();
        for (ModuleDependencyInfo dep : newModuleInfo.getDependencies()) {
            Module dependency = getModuleManager().getOrCreateModule(ModuleManager.splitModuleName(dep.getName()), dep.getVersion());
            Backends backends = dependency.getNativeBackends();
            ModuleImport newImport = new ModuleImport(dep.getNamespace(), dependency, dep.isOptional(), dep.isExport(), backends);
            newModuleImports.add(newImport);
        }
        module.overrideImports(newModuleImports);
    }
}
Also used : Backends(org.eclipse.ceylon.common.Backends) ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) ArrayList(java.util.ArrayList) Overrides(org.eclipse.ceylon.cmr.api.Overrides) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) Module(org.eclipse.ceylon.model.typechecker.model.Module) HashSet(java.util.HashSet)

Example 18 with Backends

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

the class TypeVisitor method handleNativeHeader.

private Declaration handleNativeHeader(Declaration hdr, Node that) {
    if (hdr.isNativeHeader()) {
        Scope scope = that.getScope();
        if (scope == hdr) {
            scope = scope.getScope();
        }
        Backends inBackends = scope.getScopedBackends();
        Backends backends = inBackends.none() ? unit.getSupportedBackends() : inBackends;
        Declaration impl = getNativeDeclaration(hdr, backends);
        return inBackends == null || impl == null ? hdr : impl;
    }
    return hdr;
}
Also used : Backends(org.eclipse.ceylon.common.Backends) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 19 with Backends

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

the class AbstractModelLoader method loadCompiledModule.

private boolean loadCompiledModule(Module module, ClassMirror moduleClass, boolean loadModuleImports) {
    String moduleClassName = moduleClass.getQualifiedName();
    String name = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "name");
    String version = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "version");
    if (name == null || name.isEmpty()) {
        logWarning("Module class " + moduleClassName + " contains no name, ignoring it");
        return false;
    }
    if (!name.equals(module.getNameAsString())) {
        logWarning("Module class " + moduleClassName + " declares an invalid name: " + name + ". It should be: " + module.getNameAsString());
        return false;
    }
    if (version == null || version.isEmpty()) {
        logWarning("Module class " + moduleClassName + " contains no version, ignoring it");
        return false;
    }
    if (!version.equals(module.getVersion())) {
        logWarning("Module class " + moduleClassName + " declares an invalid version: " + version + ". It should be: " + module.getVersion());
        return false;
    }
    // String label = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "label");
    // module.setLabel(label);
    int major = getAnnotationIntegerValue(moduleClass, CEYLON_CEYLON_ANNOTATION, "major", 0);
    int minor = getAnnotationIntegerValue(moduleClass, CEYLON_CEYLON_ANNOTATION, "minor", 0);
    module.setJvmMajor(major);
    module.setJvmMinor(minor);
    // no need to load the "nativeBackends" annotation value, it's loaded from annotations
    setAnnotations(module, moduleClass, false);
    if (loadModuleImports) {
        List<AnnotationMirror> imports = getAnnotationArrayValue(moduleClass, CEYLON_MODULE_ANNOTATION, "dependencies");
        if (imports != null) {
            boolean supportsNamespaces = ModuleUtil.supportsImportsWithNamespaces(major, minor);
            for (AnnotationMirror importAttribute : imports) {
                String dependencyName = (String) importAttribute.getValue("name");
                if (dependencyName != null) {
                    String namespace;
                    if (supportsNamespaces) {
                        namespace = (String) importAttribute.getValue("namespace");
                        if (namespace != null && namespace.isEmpty()) {
                            namespace = null;
                        }
                    } else {
                        if (ModuleUtil.isMavenModule(dependencyName)) {
                            namespace = "maven";
                        } else {
                            namespace = null;
                        }
                    }
                    String dependencyVersion = (String) importAttribute.getValue("version");
                    Module dependency = moduleManager.getOrCreateModule(ModuleManager.splitModuleName(dependencyName), dependencyVersion);
                    Boolean optionalVal = (Boolean) importAttribute.getValue("optional");
                    Boolean exportVal = (Boolean) importAttribute.getValue("export");
                    List<String> nativeBackends = (List<String>) importAttribute.getValue("nativeBackends");
                    Backends backends = nativeBackends == null ? Backends.ANY : Backends.fromAnnotations(nativeBackends);
                    ModuleImport moduleImport = moduleManager.findImport(module, dependency);
                    if (moduleImport == null) {
                        boolean optional = optionalVal != null && optionalVal;
                        boolean export = exportVal != null && exportVal;
                        moduleImport = new ModuleImport(namespace, dependency, optional, export, backends);
                        module.addImport(moduleImport);
                    }
                }
            }
        }
    }
    module.setAvailable(true);
    modules.getListOfModules().add(module);
    Module languageModule = modules.getLanguageModule();
    module.setLanguageModule(languageModule);
    if (loadModuleImports) {
        if (!ModelUtil.equalModules(module, languageModule)) {
            boolean found = false;
            for (ModuleImport mi : module.getImports()) {
                if (mi.getModule().isLanguageModule()) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                // It's not really a LazyModule because we're not loading
                // it lazily. It's only here for module version analysis.
                // But other stuff expects non-source modules to be lazy.
                LazyModule oldLangMod = new LazyModule() {

                    @Override
                    protected AbstractModelLoader getModelLoader() {
                        return AbstractModelLoader.this;
                    }
                };
                oldLangMod.setLanguageModule(oldLangMod);
                oldLangMod.setName(Arrays.asList("ceylon", "language"));
                oldLangMod.setVersion(getJvmLanguageModuleVersion(major, minor));
                oldLangMod.setNativeBackends(Backends.JAVA);
                oldLangMod.setJvmMajor(major);
                oldLangMod.setJvmMinor(minor);
                ModuleImport moduleImport = new ModuleImport(null, oldLangMod, false, false);
                module.addImport(moduleImport);
            }
        }
    }
    return true;
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) Backends(org.eclipse.ceylon.common.Backends) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule)

Example 20 with Backends

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

the class AbstractModelLoader method manageNativeBackend.

private void manageNativeBackend(Annotated annotated, AnnotatedMirror mirror, boolean isNativeHeader) {
    if (mirror == null)
        return;
    // Set "native" annotation
    @SuppressWarnings("unchecked") List<String> nativeBackends = (List<String>) getAnnotationValue(mirror, CEYLON_LANGUAGE_NATIVE_ANNOTATION, "backends");
    if (nativeBackends != null) {
        Backends backends = Backends.fromAnnotations(nativeBackends);
        if (isNativeHeader) {
            backends = Backends.HEADER;
        } else if (backends.header()) {
            // Elements in the class file marked `native("")` are actually
            // default implementations taken from the header that were
            // copied to the output, so here we reset them to `native("jvm")`
            backends = Backends.JAVA;
        }
        if (annotated instanceof Declaration) {
            Declaration decl = (Declaration) annotated;
            decl.setNativeBackends(backends);
            if (isNativeHeader) {
                List<Declaration> al = new ArrayList<Declaration>(1);
                setOverloads(decl, al);
            }
        } else if (annotated instanceof Module) {
            ((Module) annotated).setNativeBackends(backends);
        }
    } else {
        // Mark native Classes and Interfaces as well, but don't deal with overloads and such
        if (annotated instanceof LazyClass && !((LazyClass) annotated).isCeylon() || annotated instanceof LazyInterface && !((LazyInterface) annotated).isCeylon()) {
            ((Declaration) annotated).setNativeBackends(Backend.Java.asSet());
        }
    }
}
Also used : Backends(org.eclipse.ceylon.common.Backends) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface) ArrayList(java.util.ArrayList) List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass)

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