From ab0b94219c92da54dfb37df5cb51d06cd08436a2 Mon Sep 17 00:00:00 2001
From: oppofind <836575280@qq.com>
Date: Sat, 5 Sep 2020 13:45:32 +0800
Subject: [PATCH] support set order for rpc.
---
pom.xml | 2 +-
.../doc/template/RpcDocBuildTemplate.java | 35 ++++++++++++++-----
.../template/SpringBootDocBuildTemplate.java | 10 ++----
3 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/pom.xml b/pom.xml
index 5106990..60a202d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
4.0.0
smart-doc
jar
- 1.9.3
+ 1.9.4
smart-doc
https://github.com/smart-doc-group/smart-doc.git
diff --git a/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java b/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java
index dc10764..a9026e6 100644
--- a/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java
+++ b/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java
@@ -23,6 +23,7 @@
package com.power.doc.template;
import com.power.common.util.StringUtil;
+import com.power.common.util.ValidateUtil;
import com.power.doc.builder.ProjectDocConfigBuilder;
import com.power.doc.constants.DocAnnotationConstants;
import com.power.doc.constants.DocGlobalConstants;
@@ -41,6 +42,8 @@ import com.power.doc.utils.JavaClassValidateUtil;
import com.thoughtworks.qdox.model.*;
import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
import static com.power.doc.constants.DocTags.IGNORE;
@@ -49,28 +52,42 @@ import static com.power.doc.constants.DocTags.IGNORE;
*/
public class RpcDocBuildTemplate implements IDocBuildTemplate {
+ /**
+ * api index
+ */
+ private final AtomicInteger atomicInteger = new AtomicInteger(1);
+
public List getApiData(ProjectDocConfigBuilder projectBuilder) {
ApiConfig apiConfig = projectBuilder.getApiConfig();
List apiDocList = new ArrayList<>();
int order = 0;
+ boolean setCustomOrder = false;
for (JavaClass cls : projectBuilder.getJavaProjectBuilder().getClasses()) {
if (!checkDubboInterface(cls)) {
continue;
}
if (StringUtil.isNotEmpty(apiConfig.getPackageFilters())) {
- if (DocUtil.isMatch(apiConfig.getPackageFilters(), cls.getCanonicalName())) {
- order++;
- List apiMethodDocs = buildServiceMethod(cls, apiConfig, projectBuilder);
- this.handleJavaApiDoc(cls, apiDocList, apiMethodDocs, order, projectBuilder);
+ if (!DocUtil.isMatch(apiConfig.getPackageFilters(), cls.getCanonicalName())) {
+ continue;
}
- } else {
- order++;
- List apiMethodDocs = buildServiceMethod(cls, apiConfig, projectBuilder);
- this.handleJavaApiDoc(cls, apiDocList, apiMethodDocs, order, projectBuilder);
}
+ String strOrder = JavaClassUtil.getClassTagsValue(cls, DocTags.ORDER, Boolean.TRUE);
+ order++;
+ if (ValidateUtil.isNonnegativeInteger(strOrder)) {
+ order = Integer.parseInt(strOrder);
+ setCustomOrder = true;
+ }
+ List apiMethodDocs = buildServiceMethod(cls, apiConfig, projectBuilder);
+ this.handleJavaApiDoc(cls, apiDocList, apiMethodDocs, order, projectBuilder);
}
+ // sort
if (apiConfig.isSortByTitle()) {
Collections.sort(apiDocList);
+ } else if (setCustomOrder) {
+ // while set custom oder
+ return apiDocList.stream()
+ .sorted(Comparator.comparing(RpcApiDoc::getOrder))
+ .peek(p -> p.setOrder(atomicInteger.getAndAdd(1))).collect(Collectors.toList());
}
return apiDocList;
}
@@ -97,7 +114,7 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate {
throw new RuntimeException("Unable to find comment for method " + method.getName() + " in " + cls.getCanonicalName());
}
boolean deprecated = false;
- //设置当前接口是否过时
+ //Deprecated
List annotations = method.getAnnotations();
for (JavaAnnotation annotation : annotations) {
String annotationName = annotation.getType().getName();
diff --git a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java
index 6f5c433..5ff2edb 100644
--- a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java
+++ b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java
@@ -56,7 +56,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
/**
* api index
*/
- private AtomicInteger atomicInteger = new AtomicInteger(1);
+ private final AtomicInteger atomicInteger = new AtomicInteger(1);
@Override
public List getApiData(ProjectDocConfigBuilder projectBuilder) {
@@ -90,13 +90,9 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
Collections.sort(apiDocList);
} else if (setCustomOrder) {
// while set custom oder
- List sortedApiDoc = apiDocList.stream()
+ return apiDocList.stream()
.sorted(Comparator.comparing(ApiDoc::getOrder))
- .map(p -> {
- p.setOrder(atomicInteger.getAndAdd(1));
- return p;
- }).collect(Collectors.toList());
- return sortedApiDoc;
+ .peek(p -> p.setOrder(atomicInteger.getAndAdd(1))).collect(Collectors.toList());
}
return apiDocList;
}