Commit bf2a7907 authored by duanledexianxianxian's avatar duanledexianxianxian 😁

Refactoring code.

parent 2b76db72
...@@ -12,19 +12,38 @@ import java.util.List; ...@@ -12,19 +12,38 @@ import java.util.List;
/** /**
* 对象类型描述 * 对象类型描述
*
* @author fengyuchenglun
* @version 1.0.0
*/ */
@Setter @Setter
@Getter @Getter
public class ObjectTypeDescription extends TypeDescription { public class ObjectTypeDescription extends TypeDescription {
/**
* The Members.
*/
protected List<TypeDescription> members = Lists.newArrayList(); protected List<TypeDescription> members = Lists.newArrayList();
/**
* The Value.
*/
private ObjectNode value = ObjectMappers.instance.createObjectNode(); private ObjectNode value = ObjectMappers.instance.createObjectNode();
/**
* Merge.
*
* @param other the other
*/
public void merge(ObjectTypeDescription other) { public void merge(ObjectTypeDescription other) {
value.setAll(other.getValue()); value.setAll(other.getValue());
members.addAll(other.members); members.addAll(other.members);
} }
/**
* Add.
*
* @param component the component
*/
public void add(TypeDescription component) { public void add(TypeDescription component) {
members.add(component); members.add(component);
if (component.isPrimitive()) { if (component.isPrimitive()) {
...@@ -38,6 +57,11 @@ public class ObjectTypeDescription extends TypeDescription { ...@@ -38,6 +57,11 @@ public class ObjectTypeDescription extends TypeDescription {
} }
} }
/**
* Primitive.
*
* @param typeDescription the type description
*/
public void primitive(PrimitiveTypeDescription typeDescription) { public void primitive(PrimitiveTypeDescription typeDescription) {
switch (typeDescription.getType()) { switch (typeDescription.getType()) {
case "byte": case "byte":
......
package com.kim.apidoc.core.parser; package com.kim.apidoc.core.parser;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.EnumConstantDeclaration;
import com.github.javaparser.ast.body.EnumDeclaration; import com.github.javaparser.ast.body.EnumDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.comments.Comment;
import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.ast.comments.JavadocComment;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter; import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import com.github.javaparser.javadoc.Javadoc;
import com.github.javaparser.javadoc.JavadocBlockTag;
import com.github.javaparser.symbolsolver.core.resolution.Context;
import com.kim.apidoc.core.ApiDoc; import com.kim.apidoc.core.ApiDoc;
import com.kim.apidoc.core.common.helper.OptionalHelper; import com.kim.apidoc.core.common.helper.OptionalHelper;
import com.kim.apidoc.core.schema.*; import com.kim.apidoc.core.schema.*;
import java.util.Objects;
import java.util.Optional;
/** /**
* The type Visitor parser. * The type Visitor parser.
...@@ -89,11 +81,11 @@ public class VisitorParser extends VoidVisitorAdapter<Node> { ...@@ -89,11 +81,11 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
Chapter chapter = (Chapter) arg; Chapter chapter = (Chapter) arg;
OptionalHelper.any(chapter.getTag("code")) OptionalHelper.any(chapter.getTag("code"))
.ifPresent(tag -> { .ifPresent(tag -> {
if (javadocComment.getCommentedNode().isPresent()){ if (javadocComment.getCommentedNode().isPresent()) {
com.github.javaparser.ast.Node commentedNode=javadocComment.getCommentedNode().get(); com.github.javaparser.ast.Node commentedNode = javadocComment.getCommentedNode().get();
// 常量类||枚举类 // 常量类||枚举类
if (commentedNode instanceof ClassOrInterfaceDeclaration if (commentedNode instanceof ClassOrInterfaceDeclaration
|| commentedNode instanceof EnumDeclaration){ || commentedNode instanceof EnumDeclaration) {
Appendix appendix = Appendix.parse(javadocComment); Appendix appendix = Appendix.parse(javadocComment);
if (appendix != null) { if (appendix != null) {
ApiDoc.getInstance().getProject().getAppendices().add(appendix); ApiDoc.getInstance().getProject().getAppendices().add(appendix);
...@@ -104,7 +96,14 @@ public class VisitorParser extends VoidVisitorAdapter<Node> { ...@@ -104,7 +96,14 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
OptionalHelper.any(chapter.getTag("resultData")) OptionalHelper.any(chapter.getTag("resultData"))
.ifPresent(tag -> { .ifPresent(tag -> {
System.out.println(javadocComment); if (javadocComment.getCommentedNode().isPresent()) {
com.github.javaparser.ast.Node commentedNode = javadocComment.getCommentedNode().get();
// 常量类||枚举类
if (commentedNode instanceof ClassOrInterfaceDeclaration) {
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = (ClassOrInterfaceDeclaration) commentedNode;
ApiDoc.getInstance().getProject().setResultDataClassOrInterfaceDeclaration(classOrInterfaceDeclaration);
}
}
}); });
} }
super.visit(javadocComment, arg); super.visit(javadocComment, arg);
......
package com.kim.apidoc.core.schema; package com.kim.apidoc.core.schema;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -30,7 +31,10 @@ public class Project extends Node { ...@@ -30,7 +31,10 @@ public class Project extends Node {
* 附录 * 附录
*/ */
List<Appendix> appendices = new LinkedList<>(); List<Appendix> appendices = new LinkedList<>();
/**
* resultData
*/
ClassOrInterfaceDeclaration resultDataClassOrInterfaceDeclaration;
/** /**
* Add chapter. * Add chapter.
......
package com.kim.apidoc.springmvc; package com.kim.apidoc.springmvc;
import com.kim.apidoc.springmvc.resovler.SpringComponentTypeResolver; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.body.Parameter;
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.kim.apidoc.core.ApiDoc; import com.kim.apidoc.core.ApiDoc;
import com.kim.apidoc.core.common.URI; import com.kim.apidoc.core.common.URI;
import com.kim.apidoc.core.common.description.ObjectTypeDescription; import com.kim.apidoc.core.common.description.ObjectTypeDescription;
...@@ -13,11 +18,7 @@ import com.kim.apidoc.core.schema.Chapter; ...@@ -13,11 +18,7 @@ import com.kim.apidoc.core.schema.Chapter;
import com.kim.apidoc.core.schema.Header; import com.kim.apidoc.core.schema.Header;
import com.kim.apidoc.core.schema.Row; import com.kim.apidoc.core.schema.Row;
import com.kim.apidoc.core.schema.Section; import com.kim.apidoc.core.schema.Section;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.kim.apidoc.springmvc.resovler.SpringComponentTypeResolver;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.body.Parameter;
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.expr.Expression;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -307,6 +308,11 @@ public class SpringParser implements ParserStrategy { ...@@ -307,6 +308,11 @@ public class SpringParser implements ParserStrategy {
* @param section the section * @param section the section
*/ */
private void visitReturn(MethodDeclaration n, Chapter chapter, Section section) { private void visitReturn(MethodDeclaration n, Chapter chapter, Section section) {
ClassOrInterfaceType returnType = new ClassOrInterfaceType();
returnType.setName(ApiDoc.getInstance().getProject().getResultDataClassOrInterfaceDeclaration().getName());
returnType.setTypeArguments(n.getType());
n.setType(returnType);
TypeDescription description = ApiDoc.getInstance().getTypeResolvers().resolve(n.getType()); TypeDescription description = ApiDoc.getInstance().getTypeResolvers().resolve(n.getType());
if (description.isAvailable()) { if (description.isAvailable()) {
if (description.isPrimitive()) { if (description.isPrimitive()) {
......
...@@ -17,7 +17,7 @@ public class SpringTest { ...@@ -17,7 +17,7 @@ public class SpringTest {
Context context = new Context(); Context context = new Context();
context.setId("test"); context.setId("test");
context.setName("测试项目"); context.setName("测试项目");
context.addSource(Paths.get("F:\\@project@\\@dianli@\\tool\\apidoc\\apidoc-springmvc\\src\\test\\java")); context.addSource(Paths.get("K:\\@project-dianli@\\tool\\apidoc\\apidoc-springmvc\\src\\test\\java"));
// context.setCss("https://darshandsoni.com/asciidoctor-skins/css/monospace.css"); // context.setCss("https://darshandsoni.com/asciidoctor-skins/css/monospace.css");
ApiDoc apigcc = new ApiDoc(context); ApiDoc apigcc = new ApiDoc(context);
......
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