当前位置: 首页>>代码示例>>Java>>正文


Java ForwardingJavaFileManager类代码示例

本文整理汇总了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);
}
 
开发者ID:jtulach,项目名称:dew,代码行数:30,代码来源:Compile.java

示例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;
}
 
开发者ID:jtulach,项目名称:dew,代码行数:31,代码来源:Compile.java


注:本文中的javax.tools.ForwardingJavaFileManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。