org.mdkt.compiler.ExtendedStandardJavaFileManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of InMemoryJavaCompiler Show documentation
Show all versions of InMemoryJavaCompiler Show documentation
Small utility to compile java code in memory
package org.mdkt.compiler;
import javax.tools.FileObject;
import javax.tools.ForwardingJavaFileManager;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import java.io.IOException;
/**
* Created by trung on 5/3/15.
*/
public class ExtendedStandardJavaFileManager extends ForwardingJavaFileManager {
private CompiledCode compiledCode;
private DynamicClassLoader cl;
/**
* Creates a new instance of ForwardingJavaFileManager.
*
* @param fileManager delegate to this file manager
* @param cl
*/
protected ExtendedStandardJavaFileManager(JavaFileManager fileManager, CompiledCode compiledCode, DynamicClassLoader cl) {
super(fileManager);
this.compiledCode = compiledCode;
this.cl = cl;
this.cl.setCode(compiledCode);
}
@Override
public JavaFileObject getJavaFileForOutput(JavaFileManager.Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException {
return compiledCode;
}
@Override
public ClassLoader getClassLoader(JavaFileManager.Location location) {
return cl;
}
}