當前位置: 首頁>>代碼示例>>Java>>正文


Java JavaFileObject.getCharContent方法代碼示例

本文整理匯總了Java中javax.tools.JavaFileObject.getCharContent方法的典型用法代碼示例。如果您正苦於以下問題:Java JavaFileObject.getCharContent方法的具體用法?Java JavaFileObject.getCharContent怎麽用?Java JavaFileObject.getCharContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.tools.JavaFileObject的用法示例。


在下文中一共展示了JavaFileObject.getCharContent方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testRegularGetCharContent

import javax.tools.JavaFileObject; //導入方法依賴的package包/類
public void testRegularGetCharContent () throws Exception {
    final File wd = this.getWorkDir();
    final File testFile = createTestFile (wd);
    JavaFileObject jfo = FileObjects.fileFileObject(testFile, wd, null, null);
    CharSequence content = jfo.getCharContent(true);
    String expectedData = DATA+"\n";
    assertTrue (expectedData.contentEquals(content));
    
    Filter f = new Filter (null);
    jfo = FileObjects.fileFileObject(testFile, wd, f, null);
    content = jfo.getCharContent(true);
    expectedData = DATA+"\n";
    assertTrue (expectedData.contentEquals(content));
    assertEquals(EnumSet.of(Call.READER), f.calls);
    
    f = new Filter (PAD);
    jfo = FileObjects.fileFileObject(testFile, wd, f, null);
    content = jfo.getCharContent(true);
    expectedData = PAD + DATA+"\n";
    assertTrue (expectedData.contentEquals(content));
    assertEquals(EnumSet.of(Call.READER), f.calls);        
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:FileObjectsTest.java

示例2: readSource

import javax.tools.JavaFileObject; //導入方法依賴的package包/類
/**
 * Try to open input stream with given name.
 * Report an error if this fails.
 *
 * @param filename The file name of the input stream to be opened.
 */
public CharSequence readSource(JavaFileObject filename) {
    try {
        inputFiles.add(filename);
        return filename.getCharContent(false);
    } catch (IOException e) {
        log.error("error.reading.file", filename, JavacFileManager.getMessage(e));
        return null;
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:16,代碼來源:JavaCompiler.java

示例3: initBuf

import javax.tools.JavaFileObject; //導入方法依賴的package包/類
protected char[] initBuf(JavaFileObject fileObject) throws IOException {
    char[] buf;
    CharSequence cs = fileObject.getCharContent(true);
    if (cs instanceof CharBuffer) {
        CharBuffer cb = (CharBuffer) cs;
        buf = JavacFileManager.toArray(cb);
        bufLen = cb.limit();
    } else {
        buf = cs.toString().toCharArray();
        bufLen = buf.length;
    }
    refBuf = new SoftReference<char[]>(buf);
    return buf;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:15,代碼來源:DiagnosticSource.java

示例4: readSource

import javax.tools.JavaFileObject; //導入方法依賴的package包/類
/** Try to open input stream with given name.
 *  Report an error if this fails.
 *  @param filename   The file name of the input stream to be opened.
 */
public CharSequence readSource(JavaFileObject filename) {
    try {
        inputFiles.add(filename);
        return filename.getCharContent(false);
    } catch (IOException e) {
        log.error("error.reading.file", filename, JavacFileManager.getMessage(e));
        return null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:14,代碼來源:JavaCompiler.java

示例5: readSource

import javax.tools.JavaFileObject; //導入方法依賴的package包/類
/** Try to open input stream with given name.
 *  Report an error if this fails.
 *  @param filename   The file name of the input stream to be opened.
 */
public CharSequence readSource(JavaFileObject filename) {
    try {
        inputFiles.add(filename);
        return filename.getCharContent(false);
    } catch (IOException e) {
        log.error(Errors.ErrorReadingFile(filename, JavacFileManager.getMessage(e)));
        return null;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:JavaCompiler.java

示例6: initBuf

import javax.tools.JavaFileObject; //導入方法依賴的package包/類
protected char[] initBuf(JavaFileObject fileObject) throws IOException {
    char[] buf;
    CharSequence cs = fileObject.getCharContent(true);
    if (cs instanceof CharBuffer) {
        CharBuffer cb = (CharBuffer) cs;
        buf = JavacFileManager.toArray(cb);
        bufLen = cb.limit();
    } else {
        buf = cs.toString().toCharArray();
        bufLen = buf.length;
    }
    refBuf = new SoftReference<>(buf);
    return buf;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:DiagnosticSource.java

示例7: check

import javax.tools.JavaFileObject; //導入方法依賴的package包/類
@Override
void check(TreePath path, Name name) throws Exception {
    JavaFileObject fo = path.getCompilationUnit().getSourceFile();
    final CharSequence cs = fo.getCharContent(true);

    final DCDocComment dc = (DCDocComment) trees.getDocCommentTree(path);
    DCTree t = (DCTree) trees.getDocCommentTree(path);

    DocTreeScanner scanner = new DocTreeScanner<Void,Void>() {
        @Override
        public Void scan(DocTree node, Void ignore) {
            if (node != null) {
                try {
                    String expect = getExpectText(node);
                    long pos = ((DCTree) node).getSourcePosition(dc);
                    String found = getFoundText(cs, (int) pos, expect.length());
                    if (!found.equals(expect)) {
                        System.err.println("expect: " + expect);
                        System.err.println("found:  " + found);
                        error("mismatch");
                    }

                } catch (StringIndexOutOfBoundsException e) {
                    error(node.getClass() + ": " + e.toString());
                        e.printStackTrace();
                }
            }
            return super.scan(node, ignore);
        }
    };

    scanner.scan(t, null);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:DocCommentTester.java

示例8: test

import javax.tools.JavaFileObject; //導入方法依賴的package包/類
static void test(boolean genEndPos) throws Exception {
    Context context = new Context();

    Options options = Options.instance(context);
    options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m");

    Log log = Log.instance(context);
    Factory diagnosticFactory = JCDiagnostic.Factory.instance(context);
    Field defaultErrorFlagsField =
            JCDiagnostic.Factory.class.getDeclaredField("defaultErrorFlags");

    defaultErrorFlagsField.setAccessible(true);

    Set<DiagnosticFlag> defaultErrorFlags =
            (Set<DiagnosticFlag>) defaultErrorFlagsField.get(diagnosticFactory);

    defaultErrorFlags.add(DiagnosticFlag.MULTIPLE);

    JavacFileManager.preRegister(context);
    ParserFactory pfac = ParserFactory.instance(context);

    final String text =
          "public class Foo {\n"
        + "  public static void main(String[] args) {\n"
        + "    if (args.length == 0)\n"
        + "      System.out.println(\"no args\");\n"
        + "    else\n"
        + "      System.out.println(args.length + \" args\");\n"
        + "  }\n"
        + "}\n";
    JavaFileObject fo = new StringJavaFileObject("Foo", text);
    log.useSource(fo);

    CharSequence cs = fo.getCharContent(true);
    Parser parser = pfac.newParser(cs, false, genEndPos, false);
    JCTree.JCCompilationUnit tree = parser.parseCompilationUnit();
    log.setEndPosTable(fo, tree.endPositions);

    TreeScanner ts = new LogTester(log, tree.endPositions);
    ts.scan(tree);

    check(log.nerrors, 4, "errors");
    check(log.nwarnings, 4, "warnings");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:45,代碼來源:TestLog.java


注:本文中的javax.tools.JavaFileObject.getCharContent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。