Search in sources :

Example 1 with Backend

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

the class Pattern method getModules.

public Set<Module> getModules() {
    LinkedHashSet<Module> result = new LinkedHashSet<Module>();
    if (match != null) {
        Backend be = null;
        if (backend != null) {
            be = Backend.fromAnnotation(backend);
            if (be == null) {
                throw new RuntimeException("Unknown backend for pattern: " + backend);
            }
        }
        Collection<String> mods = ModuleWildcardsHelper.expandWildcards(getSrc(), Collections.singletonList(match), be);
        for (String mod : mods) {
            result.add(new Module(mod));
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Backend(org.eclipse.ceylon.common.Backend)

Example 2 with Backend

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

the class ModuleVisitor method visit.

@Override
public void visit(Tree.ImportModule that) {
    super.visit(that);
    String version = getVersionString(that.getVersion(), that.getConstantVersion(), that);
    if (that.getVersion() == null && version != null) {
        that.setVersion(new Tree.QuotedLiteral(new CommonToken(STRING_LITERAL, "\"" + version + "\"")));
    }
    List<String> name;
    Node node;
    Tree.ImportPath importPath = that.getImportPath();
    Tree.QuotedLiteral quotedLiteral = that.getQuotedLiteral();
    if (importPath != null) {
        name = getNameAsList(importPath);
        node = importPath;
    } else if (quotedLiteral != null) {
        String nameString = getNameString(quotedLiteral);
        name = asList(nameString.split("\\."));
        node = quotedLiteral;
    } else {
        name = Collections.emptyList();
        node = null;
    }
    if (node != null) {
        Tree.QuotedLiteral artifact = that.getArtifact();
        if (artifact != null) {
            name = new ArrayList<String>(name);
            String nameString = getNameString(artifact);
            name.add("");
            name.addAll(asList(nameString.split("\\.")));
        }
        Tree.QuotedLiteral classifier = that.getClassifier();
        if (classifier != null) {
            String nameString = getNameString(classifier);
            name.add("");
            name.addAll(asList(nameString.split("\\.")));
        }
    }
    if (phase == Phase.SRC_MODULE) {
        String path = formatPath(name);
        that.setName(path);
    } else if (phase == Phase.REMAINING) {
        // set in previous phase
        String path = that.getName();
        Tree.Identifier ns = that.getNamespace();
        String namespace = ns != null ? ns.getText() : null;
        boolean hasMavenName = isMavenModule(path);
        boolean forCeylon = (importPath != null && namespace == null) || (importPath == null && namespace == null && !hasMavenName) || DefaultRepository.NAMESPACE.equals(namespace);
        if (name.isEmpty()) {
            that.addError("missing module name");
        } else if (name.get(0).equals(DEFAULT_MODULE_NAME)) {
            if (forCeylon) {
                node.addError("reserved module name: 'default'");
            }
        } else if (name.size() == 1 && name.get(0).equals("ceylon")) {
            if (forCeylon) {
                node.addError("reserved module name: 'ceylon'");
            }
        } else if (name.size() > 1 && name.get(0).equals("ceylon") && name.get(1).equals("language")) {
            if (forCeylon) {
                node.addError("the language module is imported implicitly");
            }
        } else {
            if (namespace == null && hasMavenName) {
                namespace = MavenRepository.NAMESPACE;
                node.addUsageWarning(Warning.missingImportPrefix, "use of old style Maven imports is deprecated, prefix with 'maven:'");
            }
            Tree.AnnotationList al = that.getAnnotationList();
            Unit u = unit.getUnit();
            Backends bs = getNativeBackend(al, u);
            if (!bs.none()) {
                for (Backend b : bs) {
                    if (!b.isRegistered()) {
                        node.addError("illegal native backend name: '\"" + b.nativeAnnotation + "\"' (must be either '\"jvm\"' or '\"js\"')");
                    }
                }
                if (!moduleBackends.none() && !moduleBackends.supports(bs)) {
                    node.addError("native backend name on import conflicts with module descriptor: '\"" + bs.names() + "\"' is not in '\"" + moduleBackends.names() + "\"'");
                }
            }
            Module importedModule = moduleManager.getOrCreateModule(name, version);
            if (importPath != null) {
                importPath.setModel(importedModule);
            }
            if (!completeOnlyAST && mainModule != null) {
                if (importedModule.getVersion() == null) {
                    importedModule.setVersion(version);
                }
                ModuleImport moduleImport = moduleManager.findImport(mainModule, importedModule);
                if (moduleImport == null) {
                    boolean optional = hasAnnotation(al, "optional", u);
                    boolean export = hasAnnotation(al, "shared", u);
                    moduleImport = new ModuleImport(namespace, importedModule, optional, export, bs);
                    moduleImport.getAnnotations().clear();
                    buildAnnotations(al, moduleImport.getAnnotations());
                    mainModule.addImport(moduleImport);
                }
                moduleManagerUtil.addModuleDependencyDefinition(moduleImport, that);
            }
        }
    }
}
Also used : Node(org.eclipse.ceylon.compiler.typechecker.tree.Node) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) Backends(org.eclipse.ceylon.common.Backends) Backend(org.eclipse.ceylon.common.Backend) TreeUtil.getNativeBackend(org.eclipse.ceylon.compiler.typechecker.tree.TreeUtil.getNativeBackend) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) CommonToken(org.antlr.runtime.CommonToken) Module(org.eclipse.ceylon.model.typechecker.model.Module) ModuleUtil.isMavenModule(org.eclipse.ceylon.common.ModuleUtil.isMavenModule)

Example 3 with Backend

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

the class DeclarationVisitor method handleNativeHeader.

private void handleNativeHeader(Declaration model, String name) {
    // Deal with implementations from the ModelLoader
    ArrayList<FunctionOrValue> loadedFunctionsOrValues = null;
    ArrayList<ClassOrInterface> loadedClasses = null;
    ArrayList<Constructor> loadedConstructors = null;
    for (Backend backendToSearch : Backend.getRegisteredBackends()) {
        Declaration overloadFromModelLoader = model.getContainer().getDirectMemberForBackend(name, backendToSearch.asSet());
        if (overloadFromModelLoader instanceof FunctionOrValue) {
            if (loadedFunctionsOrValues == null) {
                loadedFunctionsOrValues = new ArrayList<FunctionOrValue>();
            }
            FunctionOrValue fov = (FunctionOrValue) overloadFromModelLoader;
            loadedFunctionsOrValues.add(fov);
        } else if (overloadFromModelLoader instanceof ClassOrInterface) {
            if (loadedClasses == null) {
                loadedClasses = new ArrayList<ClassOrInterface>();
            }
            ClassOrInterface c = (ClassOrInterface) overloadFromModelLoader;
            loadedClasses.add(c);
        } else if (overloadFromModelLoader instanceof Constructor) {
            if (loadedConstructors == null) {
                loadedConstructors = new ArrayList<Constructor>();
            }
            Constructor c = (Constructor) overloadFromModelLoader;
            loadedConstructors.add(c);
        }
    }
    // Initialize the header's overloads
    if (model instanceof FunctionOrValue) {
        FunctionOrValue m = (FunctionOrValue) model;
        if (loadedFunctionsOrValues != null) {
            m.initOverloads(loadedFunctionsOrValues.toArray(NO_FUNCTIONS_OR_VALUES));
        } else {
            m.initOverloads();
        }
    } else if (model instanceof ClassOrInterface) {
        ClassOrInterface c = (ClassOrInterface) model;
        if (loadedClasses != null) {
            c.initOverloads(loadedClasses.toArray(NO_CLASSES));
        } else {
            c.initOverloads();
        }
    } else if (model instanceof Constructor) {
        Constructor c = (Constructor) model;
        if (loadedConstructors != null) {
            c.initOverloads(loadedConstructors.toArray(NO_CONSTRUCTORS));
        } else {
            c.initOverloads();
        }
    }
}
Also used : ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) Backend(org.eclipse.ceylon.common.Backend) TreeUtil.getNativeBackend(org.eclipse.ceylon.compiler.typechecker.tree.TreeUtil.getNativeBackend) ModelUtil.isDefaultConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isDefaultConstructor) ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) ArrayList(java.util.ArrayList) 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.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 4 with Backend

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

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

the class ModuleDoc method writePlatform.

private void writePlatform(Module module) throws IOException {
    if (module.isNative()) {
        List<String> backendNames = new ArrayList<String>();
        for (Backend backend : module.getNativeBackends()) {
            backendNames.add(backend.name);
        }
        open("div class='platform section'");
        around("span class='title'", "Platform: ");
        around("span class='value'", Util.join(", ", backendNames));
        close("div");
    }
}
Also used : Backend(org.eclipse.ceylon.common.Backend) ArrayList(java.util.ArrayList)

Aggregations

Backend (org.eclipse.ceylon.common.Backend)5 TreeUtil.getNativeBackend (org.eclipse.ceylon.compiler.typechecker.tree.TreeUtil.getNativeBackend)3 ArrayList (java.util.ArrayList)2 Backends (org.eclipse.ceylon.common.Backends)2 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)2 LinkedHashSet (java.util.LinkedHashSet)1 CommonToken (org.antlr.runtime.CommonToken)1 ModuleUtil.isMavenModule (org.eclipse.ceylon.common.ModuleUtil.isMavenModule)1 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)1 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)1 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)1 Node (org.eclipse.ceylon.compiler.typechecker.tree.Node)1 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)1 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)1 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)1 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)1 ModelUtil.getContainingClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface)1 ModelUtil.isConstructor (org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor)1 ModelUtil.isDefaultConstructor (org.eclipse.ceylon.model.typechecker.model.ModelUtil.isDefaultConstructor)1 Module (org.eclipse.ceylon.model.typechecker.model.Module)1