本文整理匯總了Java中javax.tools.ForwardingJavaFileManager類的典型用法代碼示例。如果您正苦於以下問題:Java ForwardingJavaFileManager類的具體用法?Java ForwardingJavaFileManager怎麽用?Java ForwardingJavaFileManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ForwardingJavaFileManager類屬於javax.tools包,在下文中一共展示了ForwardingJavaFileManager類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: Compile
import javax.tools.ForwardingJavaFileManager; //導入依賴的package包/類
private Compile(String html, String code) throws IOException {
this.pkg = find("package", ';', code);
this.cls = find("class ", ' ', code);
this.html = html;
this.clfm = new ClassLoaderFileManager();
final JavaFileObject file = clfm.createMemoryFileObject(
ClassLoaderFileManager.convertFQNToResource(pkg.isEmpty() ? cls : pkg + "." + cls) + Kind.SOURCE.extension,
Kind.SOURCE,
code.getBytes());
final JavaFileObject htmlFile = clfm.createMemoryFileObject(
ClassLoaderFileManager.convertFQNToResource(pkg),
Kind.OTHER,
html.getBytes());
JavaFileManager jfm = new ForwardingJavaFileManager<JavaFileManager>(clfm) {
@Override
public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException {
if (location == StandardLocation.SOURCE_PATH) {
if (packageName.equals(pkg)) {
return htmlFile;
}
}
return null;
}
};
this.info = new CompilationInfo(file, jfm);
}
示例2: compile
import javax.tools.ForwardingJavaFileManager; //導入依賴的package包/類
private Map<String, byte[]> compile(final String html, final String code) throws IOException {
final ClassLoaderFileManager clfm = new ClassLoaderFileManager();
final JavaFileObject file = clfm.createMemoryFileObject(
ClassLoaderFileManager.convertFQNToResource(pkg.isEmpty() ? cls : pkg + "." + cls) + Kind.SOURCE.extension,
Kind.SOURCE,
code.getBytes());
final JavaFileObject htmlFile = clfm.createMemoryFileObject(
ClassLoaderFileManager.convertFQNToResource(pkg),
Kind.OTHER,
html.getBytes());
JavaFileManager jfm = new ForwardingJavaFileManager<JavaFileManager>(clfm) {
@Override
public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException {
if (location == StandardLocation.SOURCE_PATH) {
if (packageName.equals(pkg)) {
return htmlFile;
}
}
return null;
}
};
final Boolean res = ToolProvider.getSystemJavaCompiler().getTask(null, jfm, this, /*XXX:*/Arrays.asList("-source", "1.7", "-target", "1.7"), null, Arrays.asList(file)).call();
Map<String, byte[]> result = new HashMap<>();
for (MemoryFileObject generated : clfm.getGeneratedFiles(Kind.CLASS)) {
result.put(generated.getName().substring(1), generated.getContent());
}
return result;
}