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