Search in sources :

Example 1 with ClosableVirtualFile

use of com.redhat.ceylon.compiler.typechecker.io.ClosableVirtualFile in project ceylon-compiler by ceylon.

the class ModelLoaderTests method getLatestZippedLanguageSourceFile.

private static final ClosableVirtualFile getLatestZippedLanguageSourceFile() {
    VFS vfs = new VFS();
    File langDir = new File("../ceylon-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(com.redhat.ceylon.compiler.typechecker.io.VFS) ClosableVirtualFile(com.redhat.ceylon.compiler.typechecker.io.ClosableVirtualFile) File(java.io.File)

Example 2 with ClosableVirtualFile

use of com.redhat.ceylon.compiler.typechecker.io.ClosableVirtualFile in project ceylon-compiler by ceylon.

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(com.redhat.ceylon.compiler.typechecker.io.ClosableVirtualFile) TypeChecker(com.redhat.ceylon.compiler.typechecker.TypeChecker) HashMap(java.util.HashMap) TypeCheckerBuilder(com.redhat.ceylon.compiler.typechecker.TypeCheckerBuilder) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit) AbstractModelLoader(com.redhat.ceylon.model.loader.AbstractModelLoader) ModelLoader(com.redhat.ceylon.model.loader.ModelLoader) RuntimeModelLoader(com.redhat.ceylon.compiler.java.runtime.model.RuntimeModelLoader) CeylonModelLoader(com.redhat.ceylon.compiler.java.loader.CeylonModelLoader) DeclarationType(com.redhat.ceylon.model.loader.ModelLoader.DeclarationType) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Module(com.redhat.ceylon.model.typechecker.model.Module) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

ClosableVirtualFile (com.redhat.ceylon.compiler.typechecker.io.ClosableVirtualFile)2 CeylonModelLoader (com.redhat.ceylon.compiler.java.loader.CeylonModelLoader)1 RuntimeModelLoader (com.redhat.ceylon.compiler.java.runtime.model.RuntimeModelLoader)1 TypeChecker (com.redhat.ceylon.compiler.typechecker.TypeChecker)1 TypeCheckerBuilder (com.redhat.ceylon.compiler.typechecker.TypeCheckerBuilder)1 PhasedUnit (com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)1 VFS (com.redhat.ceylon.compiler.typechecker.io.VFS)1 AbstractModelLoader (com.redhat.ceylon.model.loader.AbstractModelLoader)1 ModelLoader (com.redhat.ceylon.model.loader.ModelLoader)1 DeclarationType (com.redhat.ceylon.model.loader.ModelLoader.DeclarationType)1 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)1 Module (com.redhat.ceylon.model.typechecker.model.Module)1 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1