com.github.javaparser.ast.CompilationUnit.getComment()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(2.4k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中com.github.javaparser.ast.CompilationUnit.getComment()方法的一些代码示例,展示了CompilationUnit.getComment()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CompilationUnit.getComment()方法的具体详情如下:
包路径:com.github.javaparser.ast.CompilationUnit
类名称:CompilationUnit
方法名:getComment

CompilationUnit.getComment介绍

暂无

代码示例

代码示例来源:origin: com.reprezen.jsonoverlay/jsonoverlay

private void copyFileComment(SimpleJavaGenerator gen, CompilationUnit existing) {
  Optional<Comment> fileComment = existing.getComment();
  if (fileComment.isPresent()) {
    gen.setFileComment(fileComment.get().toString());
  }
}

代码示例来源:origin: treeleafj/xDoc

@Override
public DocTag converter(String comment) {
  DocTag docTag = super.converter(comment);
  String path = ClassMapperUtils.getPath((String) docTag.getValues());
  if (StringUtils.isBlank(path)) {
    return null;
  }
  Class<?> returnClassz;
  CompilationUnit cu;
  try (FileInputStream in = new FileInputStream(path)) {
    cu = JavaParser.parse(in);
    if (cu.getTypes().size() <= 0) {
      return null;
    }
    returnClassz = Class.forName(cu.getPackageDeclaration().get().getNameAsString() + "." + cu.getTypes().get(0).getNameAsString());
  } catch (Exception e) {
    log.warn("读取java原文件失败:{}", path, e.getMessage());
    return null;
  }
  String text = cu.getComment().isPresent() ? CommentUtils.parseCommentText(cu.getComment().get().getContent()) : "";
  Map<String, String> commentMap = this.analysisFieldComments(returnClassz);
  List<FieldInfo> fields = this.analysisFields(returnClassz, commentMap);
  ObjectInfo objectInfo = new ObjectInfo();
  objectInfo.setType(returnClassz);
  objectInfo.setFieldInfos(fields);
  objectInfo.setComment(text);
  return new SeeTagImpl(docTag.getTagName(), objectInfo);
}

代码示例来源:origin: beihaifeiwu/dolphin

public static String mergeContent(CompilationUnit one, CompilationUnit two) throws Exception {
  // 包声明不同,返回null
  if (!one.getPackage().equals(two.getPackage())) return null;
  CompilationUnit cu = new CompilationUnit();
  // add package declaration to the compilation unit
  PackageDeclaration pd = new PackageDeclaration();
  pd.setName(one.getPackage().getName());
  cu.setPackage(pd);
  // check and merge file comment;
  Comment fileComment = mergeSelective(one.getComment(), two.getComment());
  cu.setComment(fileComment);
  // check and merge imports
  List<ImportDeclaration> ids = mergeListNoDuplicate(one.getImports(), two.getImports());
  cu.setImports(ids);
  // check and merge Types
  List<TypeDeclaration> types = mergeTypes(one.getTypes(), two.getTypes());
  cu.setTypes(types);
  return cu.toString();
}

相关文章