protected void prepareFieldComment(FieldDeclaration fieldDeclaration, TypeDocMeta typeDocMeta) { if (fieldDeclaration.getVariables().stream().anyMatch(variable -> variable.getNameAsString().equals(typeDocMeta.getName()))) { String comment = adjustComment(fieldDeclaration); if (DfStringUtil.is_NotNull_and_NotEmpty(comment)) { if (DfStringUtil.is_Null_or_Empty(typeDocMeta.getComment()) || fieldDeclaration.getParentNode().map(parentNode -> { @SuppressWarnings("unchecked") TypeDeclaration<TypeDeclaration<?>> typeDeclaration = (TypeDeclaration<TypeDeclaration<?>>) parentNode; return typeDeclaration.getNameAsString().equals(clazz.getSimpleName()); }).orElse(false)) { typeDocMeta.setComment(comment); Matcher matcher = FIELD_COMMENT_END_PATTERN.matcher(saveFieldCommentSpecialExp(comment)); if (matcher.find()) { String description = matcher.group(1).trim(); typeDocMeta.setDescription(restoreFieldCommentSpecialExp(description)); } } } } }
public void index(TypeDeclaration<?> type, int cuId) { EnumSet<Modifier> modifiers = type.getModifiers(); boolean isInterface = type instanceof ClassOrInterfaceDeclaration && ((ClassOrInterfaceDeclaration) type).isInterface(); boolean isAnnotation = type instanceof AnnotationDeclaration; boolean isEnumeration = type instanceof EnumDeclaration; boolean isClass = !isAnnotation && !isEnumeration && !isInterface; Type t = new Type(type.getNameAsString(), type.isPublic(), type.isStatic(), modifiers.contains(FINAL), modifiers.contains(ABSTRACT), isClass, isInterface, isEnumeration, isAnnotation, cuId); int typeId = typeDao.save(t); for (BodyDeclaration member : type.getMembers()) { bodyDeclarationIndexer.index(member, typeId); } } }
(node = pnode.get()) instanceof CompilationUnit) { CompilationUnit cu2 = (CompilationUnit) node; className = cu2.getType(0).getNameAsString(); String packageAndClassName = (className.contains("."))
final Class<?> moduleType = Class.forName(cu.getPackageDeclaration().get().getNameAsString() + "." + typeDeclaration.getNameAsString()); IgnoreApi ignoreApi = moduleType.getAnnotation(IgnoreApi.class); if (ignoreApi == null) { final Class<?> moduleType = Class.forName(cu.getPackageDeclaration().get().getNameAsString() + "." + typeDeclaration.getNameAsString());
private Collection<Member> gatherFinalMembers(List<Member> members, CompilationUnit cu) { Map<String, Member> memberMap = new LinkedHashMap<>(); for (Member member : members) { String key = member.getKey(); if (!memberMap.containsKey(key)) { memberMap.put(key, member); } else { BodyDeclaration<?> copy = member.getDeclaration().clone(); if (copy instanceof ConstructorDeclaration) { ((ConstructorDeclaration) copy).setBody(JavaParser.parseBlock("{}")); ((ConstructorDeclaration) copy).setComment(null); } else if (copy instanceof MethodDeclaration) { ((MethodDeclaration) copy).setBody(null); ((MethodDeclaration) copy).setComment(null); } else if (copy instanceof FieldDeclaration) { ((FieldDeclaration) copy).getVariable(0).setInitializer((Expression) null); ((FieldDeclaration) copy).setComment(null); } copy.setAnnotations(new NodeList<>()); Logger.getGlobal().warning(String.format("Suppressing already-present generated member in type %s: %s", cu.getType(0).getNameAsString(), copy.toString())); } } return memberMap.values(); }
@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); }