Commit e019915f authored by duanledexianxianxian's avatar duanledexianxianxian 😁

add comment

parent 19054687
...@@ -9,46 +9,68 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; ...@@ -9,46 +9,68 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter; import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
/**
* The type Visitor parser.
*/
public class VisitorParser extends VoidVisitorAdapter<Node> { public class VisitorParser extends VoidVisitorAdapter<Node> {
/**
* The Parser strategy.
*/
private ParserStrategy parserStrategy; private ParserStrategy parserStrategy;
/**
* Sets parser strategy.
*
* @param parserStrategy the parser strategy
*/
public void setParserStrategy(ParserStrategy parserStrategy) { public void setParserStrategy(ParserStrategy parserStrategy) {
this.parserStrategy = parserStrategy; this.parserStrategy = parserStrategy;
} }
/**
* 类或者接口声明
* @param classOrInterfaceDeclaration
* @param arg
*/
@Override @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; Project project = (Project) arg;
// 章节
Chapter chapter = new Chapter(); Chapter chapter = new Chapter();
n.getFullyQualifiedName().ifPresent(chapter::setId); classOrInterfaceDeclaration.getFullyQualifiedName().ifPresent(chapter::setId);
chapter.setName(n.getNameAsString()); chapter.setName(classOrInterfaceDeclaration.getNameAsString());
n.getComment().ifPresent(chapter::accept); classOrInterfaceDeclaration.getComment().ifPresent(chapter::accept);
OptionalHelper.any(chapter.getTag("book"),chapter.getTag("group")) OptionalHelper.any(chapter.getTag("book"),chapter.getTag("group"))
.ifPresent(tag -> chapter.setBookName(tag.getContent())); .ifPresent(tag -> chapter.setBookName(tag.getContent()));
parserStrategy.visit(n, chapter); parserStrategy.visit(classOrInterfaceDeclaration, chapter);
project.addChapter(chapter); project.addChapter(chapter);
super.visit(n, chapter); super.visit(classOrInterfaceDeclaration, chapter);
} }
} }
/**
* 方法声明
* @param methodDeclaration
* @param arg
*/
@Override @Override
public void visit(final MethodDeclaration n, final Node arg) { public void visit(final MethodDeclaration methodDeclaration, final Node arg) {
if (arg instanceof Chapter && parserStrategy.accept(n)) { if (arg instanceof Chapter && parserStrategy.accept(methodDeclaration)) {
Chapter chapter = (Chapter) arg; Chapter chapter = (Chapter) arg;
Section section = new Section(); Section section = new Section();
section.setId(n.getNameAsString()); section.setId(methodDeclaration.getNameAsString());
section.setName(n.getNameAsString()); section.setName(methodDeclaration.getNameAsString());
section.setIndex(chapter.getSections().size()); 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); chapter.getSections().add(section);
super.visit(n, section); super.visit(methodDeclaration, section);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment