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 0fb25788577678f1c3902c251fd45fb79e8277f2..137edd58f553c6698289a8e62a5bc324eed4e100 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); } }