Search in sources :

Example 1 with VFS

use of org.eclipse.ceylon.compiler.typechecker.io.VFS in project ceylon by eclipse.

the class ModuleComplianceVisitor method main.

public static void main(String[] args) throws IOException {
    System.out.println("Finding JS language module...");
    File jsmod = findModule("build/runtime", "js");
    if (jsmod == null && System.getenv("ceylon.repo") != null) {
        jsmod = findModule(System.getenv("ceylon.repo"), "js");
    }
    if (jsmod == null && System.getProperty("user.home") != null) {
        jsmod = findModule(System.getProperty("user.home"), "js");
    }
    if (jsmod == null) {
        throw new IllegalStateException("Cannot find JS language module");
    }
    System.out.println("Finding Ceylon Language Module");
    File mod = findModule("../language/build/dist", "src");
    if (mod == null && System.getenv("ceylon.repo") != null) {
        mod = findModule(System.getenv("ceylon.repo"), "src");
    }
    if (mod == null && System.getProperty("user.home") != null) {
        mod = findModule(System.getProperty("user.home"), "src");
    }
    if (mod == null) {
        throw new IllegalStateException("Cannot find JVM language module");
    }
    System.out.println("Reading JS language module into memory...");
    FileReader reader = new FileReader(jsmod);
    char[] buf = new char[16384];
    StringWriter writer = new StringWriter();
    while (reader.ready()) {
        reader.read(buf);
        writer.write(buf);
    }
    reader.close();
    ModuleComplianceVisitor v = new ModuleComplianceVisitor(writer.toString());
    System.out.println("Checking Ceylon vs JS modules...");
    VFS vfs = new VFS();
    TypeChecker tc = new TypeCheckerBuilder().verbose(false).addSrcDirectory(vfs.getFromZipFile(mod)).getTypeChecker();
    tc.process();
    for (PhasedUnit pu : tc.getPhasedUnits().getPhasedUnits()) {
        pu.getCompilationUnit().visit(v);
    }
}
Also used : VFS(org.eclipse.ceylon.compiler.typechecker.io.VFS) StringWriter(java.io.StringWriter) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) FileReader(java.io.FileReader) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) File(java.io.File) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 2 with VFS

use of org.eclipse.ceylon.compiler.typechecker.io.VFS in project ceylon by eclipse.

the class NamingTests method getDecls.

protected List<Declaration> getDecls(String resource) throws Exception {
    final String name = PKGNAME.replace('.', '/') + "/" + resource;
    File file = new File("test/src", name);
    if (!file.exists()) {
        throw new RuntimeException("Unable to find resource " + name);
    }
    RepositoryManagerBuilder builder = new RepositoryManagerBuilder(new NullLogger(), false, 20000, java.net.Proxy.NO_PROXY);
    RepositoryManager repoManager = builder.buildRepository();
    VFS vfs = new VFS();
    Context context = new Context(repoManager, vfs);
    PhasedUnits pus = new PhasedUnits(context);
    // Make the module manager think we're looking at this package
    // even though there's no module descriptor
    pus.getModuleSourceMapper().push(PKGNAME);
    pus.parseUnit(vfs.getFromFile(file), vfs.getFromFile(new File("test-src")));
    final java.util.List<PhasedUnit> listOfUnits = pus.getPhasedUnits();
    PhasedUnit pu = listOfUnits.get(0);
    pu.validateTree();
    pu.scanDeclarations();
    pu.scanTypeDeclarations();
    pu.validateRefinement();
    pu.analyseTypes();
    pu.analyseFlow();
    return pu.getDeclarations();
}
Also used : Context(org.eclipse.ceylon.compiler.typechecker.context.Context) VFS(org.eclipse.ceylon.compiler.typechecker.io.VFS) RepositoryManagerBuilder(org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder) PhasedUnits(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) File(java.io.File) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 3 with VFS

use of org.eclipse.ceylon.compiler.typechecker.io.VFS in project ceylon by eclipse.

the class ModelLoaderTests method verifyRuntimeClassLoading.

protected void verifyRuntimeClassLoading(RunnableTest test) {
    RepositoryManager repoManager = CeylonUtils.repoManager().systemRepo(getSysRepPath()).buildManager();
    VFS vfs = new VFS();
    org.eclipse.ceylon.compiler.typechecker.context.Context context = new org.eclipse.ceylon.compiler.typechecker.context.Context(repoManager, vfs);
    RuntimeModuleManager moduleManager = new RuntimeModuleManager(null);
    context.setModules(new Modules());
    moduleManager.initCoreModules(new Modules());
    moduleManager.loadModule(AbstractModelLoader.CEYLON_LANGUAGE, Versions.CEYLON_VERSION_NUMBER, repoManager.getArtifactResult(null, "ceylon.language", Versions.CEYLON_VERSION_NUMBER), getClass().getClassLoader());
    RuntimeModelLoader modelLoader = moduleManager.getModelLoader();
    modelLoader.setupWithNoStandardModules();
    modelLoader.loadStandardModules();
    test.test(modelLoader);
}
Also used : Context(org.eclipse.ceylon.langtools.tools.javac.util.Context) VFS(org.eclipse.ceylon.compiler.typechecker.io.VFS) RuntimeModuleManager(org.eclipse.ceylon.compiler.java.runtime.model.RuntimeModuleManager) Modules(org.eclipse.ceylon.model.typechecker.model.Modules) RuntimeModelLoader(org.eclipse.ceylon.compiler.java.runtime.model.RuntimeModelLoader) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager)

Example 4 with VFS

use of org.eclipse.ceylon.compiler.typechecker.io.VFS in project ceylon by eclipse.

the class LanguageCompiler method getCeylonContextInstance.

/**
 * Get the Ceylon context instance for this context.
 */
public static org.eclipse.ceylon.compiler.typechecker.context.Context getCeylonContextInstance(Context context) {
    org.eclipse.ceylon.compiler.typechecker.context.Context ceylonContext = context.get(ceylonContextKey);
    if (ceylonContext == null) {
        CeyloncFileManager fileManager = (CeyloncFileManager) context.get(JavaFileManager.class);
        VFS vfs = new VFS();
        ceylonContext = new org.eclipse.ceylon.compiler.typechecker.context.Context(fileManager.getRepositoryManager(), vfs);
        context.put(ceylonContextKey, ceylonContext);
    }
    return ceylonContext;
}
Also used : VFS(org.eclipse.ceylon.compiler.typechecker.io.VFS) JavaFileManager(org.eclipse.ceylon.javax.tools.JavaFileManager)

Example 5 with VFS

use of org.eclipse.ceylon.compiler.typechecker.io.VFS in project ceylon by eclipse.

the class MainHelper method getLatestZippedLanguageSourceFile.

public static final ClosableVirtualFile getLatestZippedLanguageSourceFile() {
    VFS vfs = new VFS();
    File langDir = new File("../dist/dist/repo/ceylon/language");
    if (!langDir.exists()) {
        System.err.println("Unable to test language module, not found in repository: " + langDir);
        System.exit(-1);
    }
    String[] versions = langDir.list();
    Arrays.sort(versions);
    // last
    String version = versions[versions.length - 1];
    return vfs.getFromZipFile(new File(langDir, version + "/ceylon.language-" + version + ".src"));
}
Also used : VFS(org.eclipse.ceylon.compiler.typechecker.io.VFS) ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) File(java.io.File)

Aggregations

VFS (org.eclipse.ceylon.compiler.typechecker.io.VFS)6 File (java.io.File)4 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)2 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)2 ClosableVirtualFile (org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile)2 FileReader (java.io.FileReader)1 StringWriter (java.io.StringWriter)1 RepositoryManagerBuilder (org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder)1 RuntimeModelLoader (org.eclipse.ceylon.compiler.java.runtime.model.RuntimeModelLoader)1 RuntimeModuleManager (org.eclipse.ceylon.compiler.java.runtime.model.RuntimeModuleManager)1 TypeChecker (org.eclipse.ceylon.compiler.typechecker.TypeChecker)1 TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)1 Context (org.eclipse.ceylon.compiler.typechecker.context.Context)1 PhasedUnits (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits)1 JavaFileManager (org.eclipse.ceylon.javax.tools.JavaFileManager)1 Context (org.eclipse.ceylon.langtools.tools.javac.util.Context)1 Modules (org.eclipse.ceylon.model.typechecker.model.Modules)1