|
1 | 1 | package com.ztianzeng.apidoc;
|
2 | 2 |
|
3 |
| -import com.fasterxml.jackson.annotation.JsonInclude; |
4 |
| -import com.fasterxml.jackson.databind.DeserializationFeature; |
5 |
| -import com.fasterxml.jackson.databind.ObjectMapper; |
6 |
| -import com.fasterxml.jackson.databind.SerializationFeature; |
| 3 | +import com.fasterxml.jackson.databind.type.TypeFactory; |
7 | 4 | import com.thoughtworks.qdox.JavaProjectBuilder;
|
8 |
| -import com.thoughtworks.qdox.model.*; |
9 |
| -import com.ztianzeng.apidoc.constants.RequestMethod; |
| 5 | +import com.thoughtworks.qdox.model.JavaAnnotation; |
| 6 | +import com.thoughtworks.qdox.model.JavaClass; |
10 | 7 | import com.ztianzeng.apidoc.utils.DocUtils;
|
11 |
| -import org.apache.commons.lang3.StringUtils; |
12 | 8 |
|
13 | 9 | import java.io.File;
|
14 |
| -import java.util.Collection; |
15 |
| -import java.util.HashMap; |
16 |
| -import java.util.List; |
17 |
| -import java.util.Map; |
| 10 | +import java.lang.reflect.Type; |
| 11 | +import java.util.*; |
18 | 12 |
|
19 |
| -import static com.ztianzeng.apidoc.constants.GlobalConstants.IGNORE_TAG; |
20 |
| -import static com.ztianzeng.apidoc.constants.SpringMvcConstants.*; |
21 |
| -import static com.ztianzeng.apidoc.utils.DocUtils.getRequestMappingMethod; |
22 |
| -import static com.ztianzeng.apidoc.utils.DocUtils.isRequestMapping; |
| 13 | +import static com.ztianzeng.apidoc.constants.SpringMvcConstants.CONTROLLER_FULLY; |
| 14 | +import static com.ztianzeng.apidoc.constants.SpringMvcConstants.REST_CONTROLLER_FULLY; |
23 | 15 |
|
24 | 16 | /**
|
25 | 17 | * 核心处理器
|
@@ -57,7 +49,34 @@ private void loadJavaFiles(String uri) {
|
57 | 49 | }
|
58 | 50 | }
|
59 | 51 |
|
| 52 | + public Set<Class<?>> getControllerData() throws ClassNotFoundException { |
| 53 | + Set<Class<?>> apiMethodDocs = new HashSet<>(); |
| 54 | + for (JavaClass javaClass : javaClasses) { |
| 55 | + if (isController(javaClass)) { |
| 56 | + apiMethodDocs.add(TypeFactory.defaultInstance().findClass(javaClass.getBinaryName())); |
| 57 | + } |
| 58 | + } |
| 59 | + return apiMethodDocs; |
| 60 | + } |
60 | 61 |
|
| 62 | + /** |
| 63 | + * 检测controller上的注解 |
| 64 | + * |
| 65 | + * @param cls |
| 66 | + * @return |
| 67 | + */ |
| 68 | + private boolean isController(JavaClass cls) { |
| 69 | + List<JavaAnnotation> classAnnotations = cls.getAnnotations(); |
| 70 | + for (JavaAnnotation annotation : classAnnotations) { |
| 71 | + String annotationName = annotation.getType().getName(); |
| 72 | + if ("Controller".equals(annotationName) || "RestController".equals(annotationName) |
| 73 | + || REST_CONTROLLER_FULLY.equals(annotationName) |
| 74 | + || CONTROLLER_FULLY.equals(annotationName)) { |
| 75 | + return true; |
| 76 | + } |
| 77 | + } |
| 78 | + return false; |
| 79 | + } |
61 | 80 |
|
62 | 81 | public JavaProjectBuilder getBuilder() {
|
63 | 82 | return builder;
|
|
0 commit comments