From e019915f3f3311e9b3250f78fc5492d904701030 Mon Sep 17 00:00:00 2001 From: duanledexianxianxian Date: Thu, 26 Mar 2020 18:10:17 +0800 Subject: [PATCH] add comment --- .../com/apidoc/core/parser/VisitorParser.java | 50 +++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/apidoc-core/src/main/java/com/apidoc/core/parser/VisitorParser.java b/apidoc-core/src/main/java/com/apidoc/core/parser/VisitorParser.java index 0fb2578..137edd5 100644 --- a/apidoc-core/src/main/java/com/apidoc/core/parser/VisitorParser.java +++ b/apidoc-core/src/main/java/com/apidoc/core/parser/VisitorParser.java @@ -9,46 +9,68 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.visitor.VoidVisitorAdapter; +/** + * The type Visitor parser. + */ public class VisitorParser extends VoidVisitorAdapter { + /** + * The Parser strategy. + */ private ParserStrategy parserStrategy; + /** + * Sets parser strategy. + * + * @param parserStrategy the parser strategy + */ public void setParserStrategy(ParserStrategy parserStrategy) { this.parserStrategy = parserStrategy; } + /** + * 类或者接口声明 + * @param classOrInterfaceDeclaration + * @param arg + */ @Override - public void visit(final ClassOrInterfaceDeclaration n, final Node arg) { + public void visit(final ClassOrInterfaceDeclaration classOrInterfaceDeclaration, final Node arg) { - if (arg instanceof Project && parserStrategy.accept(n)) { + if (arg instanceof Project && parserStrategy.accept(classOrInterfaceDeclaration)) { Project project = (Project) arg; + // 章节 Chapter chapter = new Chapter(); - n.getFullyQualifiedName().ifPresent(chapter::setId); - chapter.setName(n.getNameAsString()); - n.getComment().ifPresent(chapter::accept); + classOrInterfaceDeclaration.getFullyQualifiedName().ifPresent(chapter::setId); + chapter.setName(classOrInterfaceDeclaration.getNameAsString()); + classOrInterfaceDeclaration.getComment().ifPresent(chapter::accept); OptionalHelper.any(chapter.getTag("book"),chapter.getTag("group")) .ifPresent(tag -> chapter.setBookName(tag.getContent())); - parserStrategy.visit(n, chapter); + parserStrategy.visit(classOrInterfaceDeclaration, chapter); project.addChapter(chapter); - super.visit(n, chapter); + super.visit(classOrInterfaceDeclaration, chapter); } } + /** + * 方法声明 + * @param methodDeclaration + * @param arg + */ @Override - public void visit(final MethodDeclaration n, final Node arg) { - if (arg instanceof Chapter && parserStrategy.accept(n)) { + public void visit(final MethodDeclaration methodDeclaration, final Node arg) { + if (arg instanceof Chapter && parserStrategy.accept(methodDeclaration)) { Chapter chapter = (Chapter) arg; Section section = new Section(); - section.setId(n.getNameAsString()); - section.setName(n.getNameAsString()); + section.setId(methodDeclaration.getNameAsString()); + section.setName(methodDeclaration.getNameAsString()); section.setIndex(chapter.getSections().size()); - n.getComment().ifPresent(section::accept); + methodDeclaration.getComment().ifPresent(section::accept); - parserStrategy.visit(n, chapter, section); + parserStrategy.visit(methodDeclaration, chapter, section); chapter.getSections().add(section); - super.visit(n, section); + super.visit(methodDeclaration, section); } } -- GitLab