org.mdkt.compiler.SourceCode 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.SimpleJavaFileObject;
import java.io.IOException;
import java.net.URI;
/**
* Created by trung on 5/3/15.
*/
public class SourceCode extends SimpleJavaFileObject {
private String contents = null;
public SourceCode(String className, String contents) throws Exception {
super(URI.create("string:///" + className.replace('.', '/') + Kind.SOURCE.extension), Kind.SOURCE);
this.contents = contents;
}
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return contents;
}
}