本文整理汇总了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;
}