本文整理汇总了Java中javax.tools.FileObject.getCharContent方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.getCharContent方法的具体用法?Java FileObject.getCharContent怎么用?Java FileObject.getCharContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.tools.FileObject
的用法示例。
在下文中一共展示了FileObject.getCharContent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extract
import javax.tools.FileObject; //导入方法依赖的package包/类
@Override
public CharSequence extract(ProcessingEnvironment environment, TypeElement element) throws IOException {
try {
FileObject resource = environment.getFiler().getResource(
StandardLocation.SOURCE_PATH,
"",
toFilename(element));
return resource.getCharContent(true);
} catch (UnsupportedOperationException | IllegalArgumentException ex) {
return UNABLE_TO_EXTRACT;
}
}
示例2: doWithOriAndPrintWriter
import javax.tools.FileObject; //导入方法依赖的package包/类
public static void doWithOriAndPrintWriter(Filer filer, JavaFileManager.Location location, String relativePath, String filename, BiConsumer<String, PrintWriter> consumer){
try {
FileObject resource = filer.getResource(location, relativePath, filename);
String data;
try{
CharSequence cs = resource.getCharContent(false);
data = cs.toString();
resource.delete();
}catch (FileNotFoundException ignored){
data = "";
}
resource = filer.createResource(location, relativePath, filename);
try(OutputStream outputStream = resource.openOutputStream()){
consumer.accept(data,new PrintWriter(outputStream));
}
} catch (IOException e) {
note("do with resource file failed"+relativePath+filename+" Exception: " + e.toString());
}
}
示例3: getDocCommentTree
import javax.tools.FileObject; //导入方法依赖的package包/类
@Override @DefinedBy(Api.COMPILER_TREE)
public DocCommentTree getDocCommentTree(FileObject fileObject) {
JavaFileObject jfo = asJavaFileObject(fileObject);
DiagnosticSource diagSource = new DiagnosticSource(jfo, log);
final Comment comment = new Comment() {
int offset = 0;
@Override
public String getText() {
try {
CharSequence rawDoc = fileObject.getCharContent(true);
Pattern bodyPat =
Pattern.compile("(?is).*?<body\\b[^>]*>(.*)</body\\b.*");
Matcher m = bodyPat.matcher(rawDoc);
if (m.matches()) {
offset = m.end(1);
return m.group(1);
} else {
// Assume doclint will do the right thing.
return "";
}
} catch (IOException ignore) {
// do nothing
}
return "";
}
@Override
public int getSourcePos(int index) {
return offset + index;
}
@Override
public CommentStyle getStyle() {
throw new UnsupportedOperationException();
}
@Override
public boolean isDeprecated() {
throw new UnsupportedOperationException();
}
};
return new DocCommentParser(parser, diagSource, comment).parse();
}