Search in sources :

Example 6 with TypeChecker

use of org.eclipse.ceylon.compiler.typechecker.TypeChecker in project ceylon by eclipse.

the class CeylonVersionTool method run.

@Override
public void run() throws IOException, RecognitionException {
    // TODO if version is empty? Prompt? Or should --set have an optional argument?
    TypeCheckerBuilder tcb = new TypeCheckerBuilder();
    for (File path : this.sourceFolders) {
        tcb.addSrcDirectory(applyCwd(path));
    }
    TypeChecker tc = tcb.getTypeChecker();
    PhasedUnits pus = tc.getPhasedUnits();
    pus.visitModules();
    ArrayList<Module> moduleList = new ArrayList<Module>(pus.getModuleSourceMapper().getCompiledModules());
    Collections.sort(moduleList, new Comparator<Module>() {

        @Override
        public int compare(Module m1, Module m2) {
            if (match(m1) && !match(m2)) {
                return -1;
            } else if (!match(m1) && match(m2)) {
                return +1;
            }
            int cmp = m1.getNameAsString().compareToIgnoreCase(m2.getNameAsString());
            if (cmp == 0) {
                cmp = m1.getVersion().compareTo(m2.getVersion());
            }
            return cmp;
        }
    });
    // first update all module versions and remember which version we assigned to which module
    // because the user can update every individual version
    Map<String, String> updatedModuleVersions = new HashMap<String, String>();
    for (Module module : moduleList) {
        boolean isMatch = match(module);
        if (newVersion == null) {
            output(module, isMatch);
        } else if (isMatch) {
            if (!updateModuleVersion(module, updatedModuleVersions)) {
                return;
            }
        }
    }
    if (updateDistribution) {
        updatedModuleVersions.put("ceylon.bootstrap", newVersion);
        updatedModuleVersions.put("ceylon.language", newVersion);
        updatedModuleVersions.put("ceylon.runtime", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.compiler.java", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.compiler.js", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.typechecker", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.common", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.cli", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.model", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.module-loader", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.module-resolver", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.module-resolver-aether", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.module-resolver-webdav", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.module-resolver-javascript", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.langtools.classfile", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.tool.provider", newVersion);
        updatedModuleVersions.put("org.eclipse.ceylon.tools", newVersion);
    }
    // now do dependencies because we know which modules we did update
    if (newVersion != null && !noUpdateDependencies) {
        for (Module module : moduleList) {
            if (!updateModuleImports(module, updatedModuleVersions)) {
                return;
            }
        }
    }
}
Also used : TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) PhasedUnits(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits) ImportModule(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportModule) Module(org.eclipse.ceylon.model.typechecker.model.Module) File(java.io.File)

Example 7 with TypeChecker

use of org.eclipse.ceylon.compiler.typechecker.TypeChecker in project ceylon by eclipse.

the class MainForTest method main.

/**
 * Files that are not under a proper module structure are
 * placed under a <nomodule> module.
 */
public static void main(String[] args) throws Exception {
    long start = System.nanoTime();
    RepositoryManager repositoryManager = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").outRepo("test/modules").logger(new LeakingLogger()).buildManager();
    TypeChecker typeChecker = new TypeCheckerBuilder().statistics(true).verbose(false).addSrcDirectory(new File("test/main")).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    int errors = typeChecker.getErrors();
    Tree.CompilationUnit compilationUnit = typeChecker.getPhasedUnitFromRelativePath("ceylon/language/Object.ceylon").getCompilationUnit();
    if (compilationUnit == null) {
        throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for files in .src");
    }
    compilationUnit = typeChecker.getPhasedUnitFromRelativePath("capture/Capture.ceylon").getCompilationUnit();
    if (compilationUnit == null) {
        throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for files in real src dir");
    }
    compilationUnit = typeChecker.getPhasedUnitFromRelativePath("org/eclipse/sample/multisource/Boo.ceylon").getCompilationUnit();
    Module module = compilationUnit.getUnit().getPackage().getModule();
    if (!"org.eclipse.sample.multisource".equals(module.getNameAsString())) {
        throw new RuntimeException("Unable to extract module name");
    }
    if (!"0.2".equals(module.getVersion())) {
        throw new RuntimeException("Unable to extract module version");
    }
    typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(new File("test/main/capture")).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    errors += typeChecker.getErrors();
    compilationUnit = typeChecker.getPhasedUnitFromRelativePath("Capture.ceylon").getCompilationUnit();
    if (compilationUnit == null) {
        throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for top level files (no package) in real src dir");
    }
    typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(new File("test/moduledep1")).addSrcDirectory(new File("test/moduledep2")).addSrcDirectory(new File("test/moduletest")).addSrcDirectory(new File("test/restricted")).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    errors += typeChecker.getErrors();
    ClosableVirtualFile latestZippedLanguageSourceFile = MainHelper.getLatestZippedLanguageSourceFile();
    typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(latestZippedLanguageSourceFile).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    errors += typeChecker.getErrors();
    latestZippedLanguageSourceFile.close();
    System.out.println("Tests took " + ((System.nanoTime() - start) / 1000000) + " ms");
    if (errors > 0) {
        System.exit(1);
    }
}
Also used : ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) LeakingLogger(org.eclipse.ceylon.compiler.typechecker.io.cmr.impl.LeakingLogger) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) Module(org.eclipse.ceylon.model.typechecker.model.Module) ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) File(java.io.File)

Example 8 with TypeChecker

use of org.eclipse.ceylon.compiler.typechecker.TypeChecker in project ceylon by eclipse.

the class ModelLoaderTests method compareNativeRuntimeWithJavaRuntime.

@Test
public void compareNativeRuntimeWithJavaRuntime() {
    // parse the ceylon sources from the language module and
    // build a map of all the native declarations
    final Map<String, Declaration> nativeFromSource = new HashMap<String, Declaration>();
    ClosableVirtualFile latestZippedLanguageSourceFile = getLatestZippedLanguageSourceFile();
    try {
        TypeCheckerBuilder typeCheckerBuilder = new TypeCheckerBuilder().verbose(false).addSrcDirectory(latestZippedLanguageSourceFile);
        TypeChecker typeChecker = typeCheckerBuilder.getTypeChecker();
        typeChecker.process();
        for (PhasedUnit pu : typeChecker.getPhasedUnits().getPhasedUnits()) {
            for (Declaration d : pu.getDeclarations()) {
                if (d.isNativeHeader() && d.isToplevel()) {
                    String qualifiedNameString = d.getQualifiedNameString();
                    String key = d.getDeclarationKind() + ":" + qualifiedNameString;
                    Declaration prev = nativeFromSource.put(key, d);
                    if (prev != null) {
                        Assert.fail("Two declarations with the same key " + key + ": " + d + " and: " + prev);
                    }
                }
            }
        }
    } finally {
        latestZippedLanguageSourceFile.close();
    }
    System.out.println(nativeFromSource);
    // now compile something (it doesn't matter what, we just need
    // to get our hands on from-binary models for the language module)
    RunnableTest tester = new RunnableTest() {

        @Override
        public void test(ModelLoader loader) {
            OtherModelCompare comparer = new OtherModelCompare();
            Module binaryLangMod = loader.getLoadedModule(AbstractModelLoader.CEYLON_LANGUAGE, Versions.CEYLON_VERSION_NUMBER);
            for (Map.Entry<String, Declaration> entry : nativeFromSource.entrySet()) {
                System.out.println(entry.getKey());
                Declaration source = entry.getValue();
                ModelLoader.DeclarationType dt = null;
                switch(source.getDeclarationKind()) {
                    case TYPE:
                    case TYPE_PARAMETER:
                        dt = DeclarationType.TYPE;
                        break;
                    case MEMBER:
                    case SETTER:
                        dt = DeclarationType.VALUE;
                        break;
                }
                // Ensure the package is loaded
                binaryLangMod.getDirectPackage(source.getQualifiedNameString().replaceAll("::.*", ""));
                Declaration binary = loader.getDeclaration(binaryLangMod, source.getQualifiedNameString().replace("::", "."), dt);
                comparer.compareDeclarations(source.getQualifiedNameString(), source, binary);
            }
        }
    };
    verifyCompilerClassLoading("Any.ceylon", tester, defaultOptions);
    verifyRuntimeClassLoading(tester);
}
Also used : ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) HashMap(java.util.HashMap) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) ModelLoader(org.eclipse.ceylon.model.loader.ModelLoader) CeylonModelLoader(org.eclipse.ceylon.compiler.java.loader.CeylonModelLoader) RuntimeModelLoader(org.eclipse.ceylon.compiler.java.runtime.model.RuntimeModelLoader) AbstractModelLoader(org.eclipse.ceylon.model.loader.AbstractModelLoader) DeclarationType(org.eclipse.ceylon.model.loader.ModelLoader.DeclarationType) 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) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 9 with TypeChecker

use of org.eclipse.ceylon.compiler.typechecker.TypeChecker in project ceylon by eclipse.

the class CompileSomething method main.

public static void main(String[] x) throws IOException {
    final Options opts = new Options().outRepo("/tmp/modules").addRepo("compiler-js/build/runtime").addRepo("../ceylon.ast/modules").addRepo("../ceylon-sdk/modules").addRepo("compiler-js/build/test/proto").addRepo("npm:").optimize(true).verbose("all").generateSourceArchive(false).suppressWarnings(EnumUtil.enumsFromStrings(Warning.class, Arrays.asList("unusedImport"))).addSrcDir("/tmp/source");
    final TypeCheckerBuilder tcb = new TypeCheckerBuilder().statistics(false).encoding("UTF-8");
    for (File sd : opts.getSrcDirs()) {
        tcb.addSrcDirectory(sd);
    }
    final RepositoryManager repoman = CeylonUtils.repoManager().systemRepo(opts.getSystemRepo()).userRepos(opts.getRepos()).outRepo(opts.getOutRepo()).buildManager();
    tcb.setRepositoryManager(repoman);
    JsModuleManagerFactory.setVerbose(true);
    tcb.moduleManagerFactory(new JsModuleManagerFactory("UTF-8"));
    final TypeChecker tc = tcb.getTypeChecker();
    TypeCache.setEnabled(false);
    tc.process(true);
    TypeCache.setEnabled(true);
    final JsCompiler jsc = new JsCompiler(tc, opts);
    ArrayList<File> individualSources = new ArrayList<>();
    for (File srcdir : opts.getSrcDirs()) {
        for (File sd : srcdir.listFiles()) {
            if (sd.isFile() && sd.getName().endsWith(".js") || !individualSources.isEmpty()) {
                System.out.println("Especificando archivos para incluir fuentes js");
                individualSources.addAll(Arrays.asList(srcdir.listFiles()));
                break;
            }
        }
    }
    if (!individualSources.isEmpty()) {
        jsc.setSourceFiles(individualSources);
    }
    jsc.stopOnErrors(true);
    boolean ok = jsc.generate();
    jsc.printErrors(new java.io.PrintWriter(System.out));
    if (ok) {
        System.out.println("OK");
    } else {
        System.out.println("EXIT CODE: " + jsc.getExitCode());
    }
}
Also used : Options(org.eclipse.ceylon.compiler.js.util.Options) JsModuleManagerFactory(org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) ArrayList(java.util.ArrayList) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) File(java.io.File) JsCompiler(org.eclipse.ceylon.compiler.js.JsCompiler)

Example 10 with TypeChecker

use of org.eclipse.ceylon.compiler.typechecker.TypeChecker in project ceylon by eclipse.

the class TestJavaDeps method testJavaDependencies.

@Test
public void testJavaDependencies() throws IOException {
    final RepositoryManager repoman = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").outRepo("test-modules").buildManager();
    final TypeCheckerBuilder builder = new TypeCheckerBuilder().setRepositoryManager(repoman).addSrcDirectory(new File("src/test/resources/javadeps"));
    final TypeChecker tc = builder.getTypeChecker();
    tc.process();
    final Options opts = new Options().addSrcDir("src/test/resources/javadeps").outRepo("./build").comment(false).generateSourceArchive(false).encoding("UTF-8");
    final JsCompiler comp = new JsCompiler(tc, opts);
    comp.generate();
}
Also used : Options(org.eclipse.ceylon.compiler.js.util.Options) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) File(java.io.File) JsCompiler(org.eclipse.ceylon.compiler.js.JsCompiler) Test(org.junit.Test)

Aggregations

TypeChecker (org.eclipse.ceylon.compiler.typechecker.TypeChecker)15 TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)14 File (java.io.File)11 Options (org.eclipse.ceylon.compiler.js.util.Options)8 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)7 JsCompiler (org.eclipse.ceylon.compiler.js.JsCompiler)6 JsModuleManagerFactory (org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory)5 ArrayList (java.util.ArrayList)4 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)4 Test (org.junit.Test)4 ClosableVirtualFile (org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile)3 Module (org.eclipse.ceylon.model.typechecker.model.Module)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 LeakingLogger (org.eclipse.ceylon.compiler.typechecker.io.cmr.impl.LeakingLogger)2 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1