當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。