Package org.teavm.vm

Examples of org.teavm.vm.TeaVM


        }
    }

    private void decompileClassesForTest(ClassLoader classLoader, ClassHolderSource classSource,
            MethodReference methodRef, String targetName) throws IOException {
        TeaVM vm = new TeaVMBuilder()
                .setClassLoader(classLoader)
                .setClassSource(classSource)
                .build();
        vm.setIncremental(incremental);
        vm.setAstCache(astCache);
        vm.setProgramCache(programCache);
        vm.setProperties(properties);
        vm.setMinifying(minifying);
        vm.installPlugins();
        new TestExceptionPlugin().install(vm);
        for (ClassHolderTransformer transformer : transformers) {
            vm.add(transformer);
        }
        File file = new File(outputDir, targetName);
        DebugInformationBuilder debugInfoBuilder = sourceMapsGenerated || debugInformationGenerated ?
                new DebugInformationBuilder() : null;
        try (Writer innerWriter = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) {
            MethodReference cons = new MethodReference(methodRef.getClassName(), "<init>", ValueType.VOID);
            MethodReference exceptionMsg = new MethodReference(ExceptionHelper.class, "showException",
                    Throwable.class, String.class);
            vm.entryPoint("initInstance", cons);
            vm.entryPoint("runTest", methodRef).withValue(0, cons.getClassName());
            vm.entryPoint("extractException", exceptionMsg);
            vm.exportType("TestClass", cons.getClassName());
            vm.setDebugEmitter(debugInfoBuilder);
            vm.build(innerWriter, new DirectoryBuildTarget(outputDir));
            if (!vm.hasMissingItems()) {
                innerWriter.append("\n");
                innerWriter.append("\nJUnitClient.run();");
                if (sourceMapsGenerated) {
                    String sourceMapsFileName = targetName.substring(targetName.lastIndexOf('/') + 1) + ".map";
                    innerWriter.append("\n//# sourceMappingURL=").append(sourceMapsFileName);
                }
            } else {
                innerWriter.append("JUnitClient.reportError(\n");
                StringBuilder sb = new StringBuilder();
                vm.showMissingItems(sb);
                escapeStringLiteral(sb.toString(), innerWriter);
                innerWriter.append(");");
                log.warning("Error building test " + methodRef);
                log.warning(sb.toString());
            }
        }
        if (sourceMapsGenerated) {
            DebugInformation debugInfo = debugInfoBuilder.getDebugInformation();
            try (OutputStream debugInfoOut = new FileOutputStream(new File(outputDir, targetName + ".teavmdbg"))) {
                debugInfo.write(debugInfoOut);
            }
        }
        if (sourceMapsGenerated) {
            DebugInformation debugInfo = debugInfoBuilder.getDebugInformation();
            String sourceMapsFileName = targetName + ".map";
            try (Writer sourceMapsOut = new OutputStreamWriter(new FileOutputStream(
                    new File(outputDir, sourceMapsFileName)), "UTF-8")) {
                debugInfo.writeAsSourceMaps(sourceMapsOut, "src", targetName);
            }
        }
        if (sourceFilesCopied && vm.getWrittenClasses() != null) {
            sourceFilesCopier.addClasses(vm.getWrittenClasses());
        }
    }
View Full Code Here

TOP

Related Classes of org.teavm.vm.TeaVM

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.