Commit 80acc032 authored by duanledexianxianxian's avatar duanledexianxianxian 😁

Merge remote-tracking branch 'origin/master'

parents 46cafbb5 e019915f
......@@ -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<Node> {
/**
* 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);
}
}
......
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