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


Java FileObject.getCharContent方法代码示例

本文整理汇总了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;
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:SourceExtraction.java

示例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());
    }
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:21,代码来源:ResourceHelper.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:JavacTrees.java


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