Package com.redhat.ceylon.compiler.typechecker.model

Examples of com.redhat.ceylon.compiler.typechecker.model.Module


        out(".findPackage('", pkg.getNameAsString(), "')");
    }

    @Override
    public void visit(Tree.ModuleLiteral that) {
        Module m = (Module)that.getImportPath().getModel();
        MetamodelHelper.findModule(m, this);
    }
View Full Code Here


import com.redhat.ceylon.compiler.typechecker.tree.Tree.ValueLiteral;

public class MetamodelHelper {

    static void generateOpenType(final Node that, Declaration d, final GenerateJsVisitor gen) {
        final Module m = d.getUnit().getPackage().getModule();
        if (d instanceof TypeParameter == false) {
            if (JsCompiler.isCompilingLanguageModule()) {
                gen.out("$init$Open");
            } else {
                gen.out(gen.getClAlias(), "Open");
            }
        }
        if (d instanceof com.redhat.ceylon.compiler.typechecker.model.Interface) {
            gen.out("Interface$jsint");
        } else if (d instanceof com.redhat.ceylon.compiler.typechecker.model.Class) {
            gen.out("Class$jsint");
        } else if (d instanceof Method) {
            gen.out("Function");
        } else if (d instanceof Value) {
            gen.out("Value$jsint");
        } else if (d instanceof com.redhat.ceylon.compiler.typechecker.model.IntersectionType) {
            gen.out("Intersection");
        } else if (d instanceof com.redhat.ceylon.compiler.typechecker.model.UnionType) {
            gen.out("Union");
        } else if (d instanceof TypeParameter) {
            generateOpenType(that, ((TypeParameter)d).getDeclaration(),gen);
            gen.out(".getTypeParameterDeclaration('", d.getName(), "')");
            return;
        } else if (d instanceof com.redhat.ceylon.compiler.typechecker.model.NothingType) {
            gen.out("NothingType");
        } else if (d instanceof TypeAlias) {
            gen.out("Alias$jsint(");
            if (JsCompiler.isCompilingLanguageModule()) {
                gen.out(")(");
            }
            if (d.isMember()) {
                //Make the chain to the top-level container
                ArrayList<Declaration> parents = new ArrayList<Declaration>(2);
                Declaration pd = (Declaration)d.getContainer();
                while (pd!=null) {
                    parents.add(0,pd);
                    pd = pd.isMember()?(Declaration)pd.getContainer():null;
                }
                for (Declaration _d : parents) {
                    gen.out(gen.getNames().name(_d), ".$$.prototype.");
                }
            }
            gen.out(gen.getNames().name(d), ")");
            return;
        }
        //TODO optimize for local declarations
        if (JsCompiler.isCompilingLanguageModule()) {
            gen.out("()");
        }
        gen.out("(", gen.getClAlias());
        final String pkgname = d.getUnit().getPackage().getNameAsString();
        if (Objects.equals(that.getUnit().getPackage().getModule(), d.getUnit().getPackage().getModule())) {
            gen.out("lmp$(ex$,'");
        } else {
            gen.out("fmp$('", m.getNameAsString(), "','", m.getVersion(), "','");
        }
        gen.out("ceylon.language".equals(pkgname) ? "$" : pkgname, "'),");
        if (d.isMember()) {
            outputPathToDeclaration(that, d, gen);
        }
View Full Code Here

        return Arrays.asList("js");
    }

    @Override
    protected Module createModule(List<String> moduleName, String version) {
        final Module module = new JsonModule();
        module.setName(moduleName);
        module.setVersion(version);
        Unit u = new Unit();
        u.setFilename(Constants.MODULE_DESCRIPTOR);
        u.setFullPath(moduleName+"/"+version);
        module.setUnit(u);
        JsonModule dep = (JsonModule)findLoadedModule(Module.LANGUAGE_MODULE_NAME, null);
        //This can only happen during initCoreModules()
        if (!(module.getNameAsString().equals(Module.DEFAULT_MODULE_NAME) || module.getNameAsString().equals(Module.LANGUAGE_MODULE_NAME)) && dep == null) {
            //Load the language module if we're not inside initCoreModules()
            dep = (JsonModule)getContext().getModules().getLanguageModule();
            //Add language module as a dependency
            //This will cause the dependency to be loaded later
            ModuleImport imp = new ModuleImport(dep, false, false);
            module.addImport(imp);
            module.setLanguageModule(dep);
            //Fix 280 part 1
            getContext().getModules().getDefaultModule().addImport(new ModuleImport(module, false, false));
        }
        return module;
    }
View Full Code Here

        Package p = getDirectPackage(name);
        if (p != null) {
            return p;
        }
        for (ModuleImport imp : getImports()) {
            final Module mod = imp.getModule();
            p = mod.getDirectPackage(name);
            if (p != null) {
                return p;
            }
            for (ModuleImport im2 : mod.getImports()) {
                if (im2.isExport()) {
                    p = im2.getModule().getDirectPackage(name);
                }
                if (p != null) {
                    return p;
View Full Code Here

            }
            List<PhasedUnit> phasedUnits = tc.getPhasedUnits().getPhasedUnits();
            boolean generatedCode = false;
           
            //First generate the metamodel
            final Module defmod = tc.getContext().getModules().getDefaultModule();
            for (PhasedUnit pu: phasedUnits) {
                File path = getFullPath(pu);
                //#416 default module with packages
                Module mod = pu.getPackage().getModule();
                if (mod.getVersion() == null && !mod.isDefault()) {
                    //Switch with the default module
                    for (com.redhat.ceylon.compiler.typechecker.model.Package pkg : mod.getPackages()) {
                        defmod.getPackages().add(pkg);
                        pkg.setModule(defmod);
                    }
                }
                if (srcFiles == null || FileUtil.containsFile(srcFiles, path)) {
                    pu.getCompilationUnit().visit(getOutput(pu).mmg);
                    if (opts.isVerbose()) {
                        logger.debug(pu.getCompilationUnit().toString());
                    }
                }
            }
            //Then write it out and output the reference in the module file
            final JsIdentifierNames names = new JsIdentifierNames();
            if (!compilingLanguageModule) {
                for (Map.Entry<Module,JsOutput> e : output.entrySet()) {
                    e.getValue().encodeModel(names);
                }
            }
            //Output all the require calls for any imports
            final Visitor importVisitor = new Visitor() {
                public void visit(Tree.Import that) {
                    ImportableScope scope =
                            that.getImportMemberOrTypeList().getImportList().getImportedScope();
                    Module _m = that.getUnit().getPackage().getModule();
                    if (scope instanceof Package && !((Package)scope).getModule().equals(_m)) {
                        output.get(_m).require(((Package) scope).getModule(), names);
                    }
                }
            };
View Full Code Here

    }

    /** Creates a JsOutput if needed, for the PhasedUnit.
     * Right now it's one file per module. */
    private JsOutput getOutput(PhasedUnit pu) throws IOException {
        Module mod = pu.getPackage().getModule();
        JsOutput jsout = output.get(mod);
        if (jsout==null) {
            jsout = newJsOutput(mod);
            output.put(mod, jsout);
            if (opts.isModulify()) {
View Full Code Here

            out("\nvar _CTM$;function $CCMM$(){if (_CTM$===undefined)_CTM$=");
            writeModelRetriever();
            out(";return _CTM$;}\n");
            getWriter().write("ex$.$CCMM$=$CCMM$;\n");
            if (!JsCompiler.isCompilingLanguageModule()) {
                Module clm = module.getLanguageModule();
                clalias = names.moduleAlias(clm) + ".";
                require(clm, names);
                out(clalias, "$addmod$(ex$,'", module.getNameAsString(), "/", module.getVersion(), "');\n");
            }
        }
View Full Code Here

            ImportDepth importDepth,
            Map<Module, ArtifactResult> alreadySearchedArtifacts) {
        List<Module> visibleDependencies = new ArrayList<Module>();
        visibleDependencies.add(dependencyTree.getLast()); //first addition => no possible conflict
        for (ModuleImport moduleImport : moduleImports) {
            Module module = moduleImport.getModule();
            if (moduleManager.findModule(module, dependencyTree, true) != null) {
                //circular dependency: stop right here
                return;
            }
            Iterable<String> searchedArtifactExtensions = moduleManager.getSearchedArtifactExtensions();
            ImportDepth newImportDepth = importDepth.forModuleImport(moduleImport);
           
            boolean forCompiledModule = newImportDepth.isVisibleToCompiledModules();
            if ( ! module.isAvailable()) {
                ArtifactResult artifact = null;
                if (alreadySearchedArtifacts.containsKey(module)) {
                    artifact = alreadySearchedArtifacts.get(module);
                } else {
                    //try and load the module from the repository
                    RepositoryManager repositoryManager = context.getRepositoryManager();
                    Exception exceptionOnGetArtifact = null;
                    ArtifactContext artifactContext = new ArtifactContext(module.getNameAsString(), module.getVersion(), getArtifactSuffixes(searchedArtifactExtensions));
                    listener.retrievingModuleArtifact(module, artifactContext);
                    try {
                        artifact = repositoryManager.getArtifactResult(artifactContext);
                    } catch (Exception e) {
                        exceptionOnGetArtifact = catchIfPossible(e);
                    }
                    if (artifact == null) {
                        //not there => error
                        ModuleHelper.buildErrorOnMissingArtifact(artifactContext, module, moduleImport, dependencyTree, exceptionOnGetArtifact, moduleManager);
                    }
                    alreadySearchedArtifacts.put(module, artifact);
                }
               
                if (artifact != null) {
                    //parse module units and build module dependency and carry on
                    listener.resolvingModuleArtifact(module, artifact);
                    moduleManager.resolveModule(artifact, module, moduleImport, dependencyTree, phasedUnitsOfDependencies, forCompiledModule);
                }
            }
            moduleManager.visitedModule(module, forCompiledModule);
            dependencyTree.addLast(module);
            List<Module> subModulePropagatedDependencies = new ArrayList<Module>();
            verifyModuleDependencyTree( module.getImports(), dependencyTree, subModulePropagatedDependencies, newImportDepth, alreadySearchedArtifacts);
            //visible dependency += subModule + subModulePropagatedDependencies
            checkAndAddDependency(visibleDependencies, module, dependencyTree);
            for (Module submodule : subModulePropagatedDependencies) {
                checkAndAddDependency(visibleDependencies, submodule, dependencyTree);
            }
View Full Code Here

        }
        return suffixes.toArray(new String[suffixes.size()]);
    }
   
    private void checkAndAddDependency(List<Module> dependencies, Module module, LinkedList<Module> dependencyTree) {
        Module dupe = moduleManager.findModule(module, dependencies, false);
        if (dupe != null && !isSameVersion(module, dupe)) {
            //TODO improve by giving the dependency string leading to these two conflicting modules
            StringBuilder error = new StringBuilder("module (transitively) imports conflicting versions of dependency '");
            error.append(module.getNameAsString()).append("': ");
            String[] versions = VersionComparator.orderVersions(module.getVersion(), dupe.getVersion());
            error.append("version '").append(versions[0]).append("' and version '").append(versions[1]).append("'");
            moduleManager.addErrorToModule(dependencyTree.getFirst(), error.toString());
        }
        else {
            dependencies.add(module);
View Full Code Here

        phasedUnits.visitModules();
        phasedUnits.getModuleManager().modulesVisited();

        //By now le language module version should be known (as local)
        //or we should use the default one.
        Module languageModule = context.getModules().getLanguageModule();
        if (languageModule.getVersion() == null) {
            languageModule.setVersion(LANGUAGE_MODULE_VERSION);
        }

        final ModuleValidator moduleValidator = new ModuleValidator(context, phasedUnits);
        if (verifyDependencies) {
            moduleValidator.verifyModuleDependencyTree();
View Full Code Here

TOP

Related Classes of com.redhat.ceylon.compiler.typechecker.model.Module

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.