Search in sources :

Example 1 with MemJavaFileObject

use of org.codehaus.groovy.tools.javac.MemJavaFileObject in project groovy by apache.

the class JavaShell method doCompile.

private void doCompile(String className, String src, Iterable<String> options) throws IOException {
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    try (BytesJavaFileManager bjfm = new BytesJavaFileManager(compiler.getStandardFileManager(null, locale, charset))) {
        StringBuilderWriter out = new StringBuilderWriter();
        JavaCompiler.CompilationTask task = compiler.getTask(out, bjfm, null, options, Collections.emptyList(), Collections.singletonList(new MemJavaFileObject(className, src)));
        task.call();
        if (bjfm.isEmpty()) {
            throw new JavaShellCompilationException(out.toString());
        }
        final Map<String, byte[]> classMap = bjfm.getClassMap();
        jscl.setClassMap(classMap);
    }
}
Also used : StringBuilderWriter(org.apache.groovy.io.StringBuilderWriter) JavaCompiler(javax.tools.JavaCompiler) MemJavaFileObject(org.codehaus.groovy.tools.javac.MemJavaFileObject)

Aggregations

JavaCompiler (javax.tools.JavaCompiler)1 StringBuilderWriter (org.apache.groovy.io.StringBuilderWriter)1 MemJavaFileObject (org.codehaus.groovy.tools.javac.MemJavaFileObject)1