Commit 638a3728 authored by duanledexianxianxian's avatar duanledexianxianxian 😁

Refactoring code.

parent ac2eb0d4
......@@ -24,7 +24,7 @@ public class AnnotationHelper {
}
if (annotationExpr.isNormalAnnotationExpr()) {
for (MemberValuePair pair : annotationExpr.asNormalAnnotationExpr().getPairs()) {
if (Objects.equals(key, pair.getNameAsString())){
if (Objects.equals(key, pair.getNameAsString())) {
return Optional.of(pair.getValue());
}
}
......@@ -32,10 +32,10 @@ public class AnnotationHelper {
return Optional.empty();
}
public static Optional<Expression> getAnyAttribute(AnnotationExpr annotationExpr, String ... keys) {
public static Optional<Expression> getAnyAttribute(AnnotationExpr annotationExpr, String... keys) {
for (String key : keys) {
Optional<Expression> optional = getAttribute(annotationExpr, key);
if(optional.isPresent()){
if (optional.isPresent()) {
return optional;
}
}
......
package com.kim.apidoc.core.common.helper;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.github.javaparser.resolution.types.ResolvedReferenceType;
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration;
import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Slf4j
......@@ -28,9 +25,9 @@ public class ClassDeclarationHelper {
if (resolvedReferenceType.getTypeDeclaration() instanceof JavaParserClassDeclaration) {
JavaParserClassDeclaration typeDeclaration = (JavaParserClassDeclaration) resolvedReferenceType.getTypeDeclaration();
return Optional.of(typeDeclaration.getWrappedNode());
}else if(resolvedReferenceType.getTypeDeclaration() instanceof ReflectionClassDeclaration){
} else if (resolvedReferenceType.getTypeDeclaration() instanceof ReflectionClassDeclaration) {
ReflectionClassDeclaration typeDeclaration = (ReflectionClassDeclaration) resolvedReferenceType.getTypeDeclaration();
System.out.println("type Declaration:"+typeDeclaration);
System.out.println("type Declaration:" + typeDeclaration);
//TODO
}
} catch (Exception e) {
......@@ -39,4 +36,16 @@ public class ClassDeclarationHelper {
return Optional.empty();
}
public static String getClassOrInterfacePackageName(ClassOrInterfaceDeclaration classOrInterfaceDeclaration) {
final String[] result = {null};
classOrInterfaceDeclaration.findCompilationUnit().ifPresent(x -> {
x.getPackageDeclaration().ifPresent(y -> {
result[0] = y.getNameAsString() + "." + classOrInterfaceDeclaration.getName();
});
});
return result[0];
}
}
......@@ -26,7 +26,7 @@ public class CommentHelper {
* @param description the description
* @return string
*/
public static String getDescription(JavadocDescription description){
public static String getDescription(JavadocDescription description) {
return description.getElements()
.stream()
.filter(e -> !(e instanceof JavadocInlineTag))
......@@ -39,8 +39,8 @@ public class CommentHelper {
* @param comment the comment
* @return the string
*/
public static String getContent(Comment comment){
if(!comment.isJavadocComment()){
public static String getContent(Comment comment) {
if (!comment.isJavadocComment()) {
return comment.getContent();
}
return getDescription(comment.asJavadocComment().parse().getDescription());
......@@ -53,11 +53,11 @@ public class CommentHelper {
* @param it the it
* @return the string
*/
public static String getComment(MethodUsage it){
public static String getComment(MethodUsage it) {
if (it.getDeclaration() instanceof JavaParserMethodDeclaration) {
MethodDeclaration wrappedNode = ((JavaParserMethodDeclaration) it.getDeclaration()).getWrappedNode();
Optional<Comment> optional = wrappedNode.getComment();
if(optional.isPresent()){
if (optional.isPresent()) {
return CommentHelper.getContent(optional.get());
}
}
......@@ -70,14 +70,14 @@ public class CommentHelper {
* @param it the it
* @return the string
*/
public static String getComment(ResolvedFieldDeclaration it){
if(it instanceof JavaParserFieldDeclaration){
public static String getComment(ResolvedFieldDeclaration it) {
if (it instanceof JavaParserFieldDeclaration) {
FieldDeclaration wrappedNode = ((JavaParserFieldDeclaration) it).getWrappedNode();
Optional<Comment> optional = wrappedNode.getComment();
if(optional.isPresent()){
if (optional.isPresent()) {
return CommentHelper.getContent(optional.get());
}
}else if(it instanceof JavaParserClassDeclaration){
} else if (it instanceof JavaParserClassDeclaration) {
JavaParserClassDeclaration classDeclaration = (JavaParserClassDeclaration) it;
}
return null;
......
......@@ -10,9 +10,7 @@ import com.kim.apidoc.core.ApiDoc;
import com.kim.apidoc.core.common.URI;
import com.kim.apidoc.core.common.description.ObjectTypeDescription;
import com.kim.apidoc.core.common.description.TypeDescription;
import com.kim.apidoc.core.common.helper.AnnotationHelper;
import com.kim.apidoc.core.common.helper.ExpressionHelper;
import com.kim.apidoc.core.common.helper.StringHelper;
import com.kim.apidoc.core.common.helper.*;
import com.kim.apidoc.core.parser.ParserStrategy;
import com.kim.apidoc.core.schema.Chapter;
import com.kim.apidoc.core.schema.Header;
......@@ -313,6 +311,7 @@ public class SpringParser implements ParserStrategy {
ClassOrInterfaceType returnType = new ClassOrInterfaceType();
returnType.setName(resultDataClassOrInterfaceDeclaration.getName());
returnType.setTypeArguments(n.getType());
n.findCompilationUnit().get().addImport(ClassDeclarationHelper.getClassOrInterfacePackageName(resultDataClassOrInterfaceDeclaration));
n.setType(returnType);
}
TypeDescription description = ApiDoc.getInstance().getTypeResolvers().resolve(n.getType());
......
......@@ -17,7 +17,7 @@ public class SpringTest {
Context context = new Context();
context.setId("test");
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");
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