Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6e1e408

Browse files
committed
back
1 parent 25e2839 commit 6e1e408

File tree

11 files changed

+317
-106
lines changed

11 files changed

+317
-106
lines changed

‎build.gradle‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies {
1818
compileOnly "org.projectlombok:lombok:1.16.16"
1919
implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.14.4-SNAPSHOT'
2020
// https://mvnrepository.com/artifact/org.springframework/spring-webmvc
21-
implementation 'org.springframework.boot:spring-boot-starter-web'
21+
compile group: 'org.springframework', name: 'spring-webmvc', version: '5.1.3.RELEASE'
22+
compile group: 'org.springframework', name: 'spring-context', version: '2.0.5'
2223

2324
}

‎src/main/java/com/hsjfans/github/model/ApiTree.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.hsjfans.github.model;
22

33
import com.google.common.collect.Maps;
4+
import org.springframework.stereotype.Controller;
5+
import org.springframework.web.bind.annotation.PatchMapping;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RequestMethod;
48

59
import java.io.Serializable;
610
import java.util.Map;
@@ -9,6 +13,8 @@
913
/**
1014
* @author hsjfans[hsjfans.scholar@gmail.com]
1115
*/
16+
@Controller
17+
@RequestMapping(value = "/123/",method = {RequestMethod.POST,RequestMethod.GET})
1218
public class ApiTree implements Serializable {
1319

1420
private static final ConcurrentMap<Class<?>,ControllerClass> controllerClassMap
@@ -18,10 +24,20 @@ public class ApiTree implements Serializable {
1824
* insert the controller cl
1925
* @param cl
2026
*/
27+
@PatchMapping(value ={ "/123","/456"})
2128
public void insert(Class<?> cl,ControllerClass controllerClass){
2229
controllerClassMap.putIfAbsent(cl,controllerClass);
2330
}
2431

32+
33+
/**
34+
*
35+
*/
36+
@RequestMapping(value = "/789")
37+
public void get(){
38+
return;
39+
}
40+
2541
public static ConcurrentMap<Class<?>, ControllerClass> getControllerClassMap() {
2642
return controllerClassMap;
2743
}

‎src/main/java/com/hsjfans/github/model/Constant.java‎

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package com.hsjfans.github.model;
22

3+
import lombok.Data;
4+
import org.springframework.web.bind.annotation.RequestMethod;
5+
36
import java.io.Serializable;
7+
import java.util.Arrays;
8+
import java.util.List;
49

510
/**
611
* @author hsjfans[hsjfans.scholar@gmail.com]
712
*/
13+
@Data
814
public class ControllerClass implements Serializable {
915

1016

@@ -15,31 +21,37 @@ public class ControllerClass implements Serializable {
1521
*/
1622
private String name;
1723

18-
/**
19-
* the description
20-
*/
21-
private String description;
24+
2225

2326
/**
2427
* the base url `@RequestMapping(value="/books")`
2528
*/
26-
private String url;
29+
private String[] url = {""};
30+
2731

32+
private boolean ignore ;
2833

2934
/**
3035
* the methods
3136
*/
3237
@Deprecated
33-
private Constant.RequestMethod[] methods;
34-
38+
private RequestMethod[] methods;
3539

3640
/**
3741
*
3842
*/
39-
private ControllerMethod controllerMethod;
40-
41-
42-
43-
44-
43+
private List<ControllerMethod> controllerMethod;
44+
45+
46+
@Override
47+
public String toString() {
48+
return "ControllerClass{" +
49+
"aClass=" + aClass +
50+
", name='" + name + '\'' +
51+
", url=" + Arrays.toString(url) +
52+
", ignore=" + ignore +
53+
", methods=" + Arrays.toString(methods) +
54+
", controllerMethod=" + controllerMethod +
55+
'}';
56+
}
4557
}

‎src/main/java/com/hsjfans/github/model/ControllerMethod.java‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package com.hsjfans.github.model;
22

3+
import com.hsjfans.github.util.StringUtil;
4+
import lombok.Data;
5+
import org.springframework.web.bind.annotation.RequestMethod;
6+
37
import java.io.Serializable;
48
import java.lang.reflect.Method;
59

610
/**
711
* @author hsjfans[hsjfans.scholar@gmail.com]
812
*/
13+
@Data
914
public class ControllerMethod implements Serializable {
1015

1116

@@ -18,7 +23,7 @@ public class ControllerMethod implements Serializable {
1823
*
1924
* the method url
2025
*/
21-
private String url;
26+
private String[] url;
2227

2328
/**
2429
* the method name `@name`
@@ -31,10 +36,6 @@ public class ControllerMethod implements Serializable {
3136
*/
3237
private Method method;
3338

34-
/**
35-
* the description
36-
*/
37-
private String description;
3839

3940
/**
4041
* the class
@@ -56,7 +57,24 @@ public class ControllerMethod implements Serializable {
5657
/**
5758
* the request that api support
5859
*/
59-
private Constant.RequestMethod[] methods;
60+
private RequestMethod[] methods;
61+
62+
63+
public void addRequestMethod(RequestMethod method){
64+
this.methods = new RequestMethod[]{method};
65+
}
66+
67+
68+
public void setRequestMethods(String methods){
69+
70+
for (String m: StringUtil.parseUrls(methods)
71+
) {
72+
RequestMethod method = RequestMethod.valueOf(m.trim());
73+
if(method!=null){
74+
this
75+
}
76+
}
77+
}
6078

6179

6280
}

‎src/main/java/com/hsjfans/github/parser/SpringParser.java‎

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
import com.github.javaparser.ast.CompilationUnit;
55
import com.github.javaparser.ast.PackageDeclaration;
66
import com.github.javaparser.ast.body.TypeDeclaration;
7+
import com.google.common.collect.Lists;
78
import com.google.common.collect.Sets;
89
import com.hsjfans.github.model.ControllerClass;
10+
import com.hsjfans.github.model.ControllerMethod;
911
import com.hsjfans.github.util.ClassUtils;
10-
import com.hsjfans.github.util.CollectionUtil;
11-
import com.hsjfans.github.util.Constant;
1212
import com.hsjfans.github.util.LogUtil;
13-
import org.springframework.web.bind.annotation.*;
1413

1514
import java.io.File;
16-
import java.lang.annotation.Annotation;
17-
import java.util.Map;
15+
import java.lang.reflect.Method;
16+
import java.util.List;
1817
import java.util.Optional;
1918
import java.util.Set;
2019

@@ -41,13 +40,7 @@ protected Set<CompilationUnit> getAllControllerClass(Set<File> javaFiles) {
4140
Set<CompilationUnit> compilationUnits = Sets.newHashSet();
4241
javaFiles.forEach(file->{
4342
CompilationUnit compilationUnit = ClassUtils.parseJavaFile(file);
44-
if(compilationUnit!=null){
45-
if(compilationUnit.getAnnotationDeclarationByName(Constant.SPRING_CONTROLLER).isPresent()){
46-
compilationUnits.add(compilationUnit);
47-
}else if(compilationUnit.getAnnotationDeclarationByName(Constant.SPRING_REST_CONTROLLER).isPresent()){
48-
compilationUnits.add(compilationUnit);
49-
}
50-
}
43+
compilationUnits.add(compilationUnit);
5144
});
5245

5346
return compilationUnits;
@@ -74,21 +67,22 @@ protected ControllerClass parseCompilationUnit(CompilationUnit compilationUnit)
7467
return null;
7568
}
7669

77-
Map<Class<?>, Annotation> annotationMap = CollectionUtil.convertToMap(
78-
cl.getAnnotations()
79-
);
80-
81-
if(!annotationMap.containsKey(Controller.class)&&!annotationMap.containsKey(RestController.class)){
82-
return null;
83-
}
70+
controllerClass = ClassUtils.parseClassComment(typeDeclaration.get().getComment().orElse(null),cl);
71+
if(controllerClass==null||controllerClass.isIgnore()){return null;}
8472

85-
// contain `RequestMapping(Value="")`
86-
if(annotationMap.containsKey(RequestMapping.class)){
87-
((RequestMapping)annotationMap.get(RequestMapping.class))
88-
}
73+
final List<ControllerMethod> controllerMethods = Lists.newArrayListWithCapacity(cl.getMethods().length);
8974

90-
controllerClass = ClassUtils.parseClassComment(typeDeclaration.get().getComment().orElse(null),cl);
75+
typeDeclaration.get().getMethods().forEach(
76+
methodDeclaration -> {
77+
ControllerMethod controllerMethod = ClassUtils.parseMethodComment(methodDeclaration.getComment().orElse(null),methodDeclaration);
78+
if(controllerMethod!=null){
79+
controllerMethods.add(controllerMethod);
80+
}
81+
}
82+
);
83+
controllerClass.setControllerMethod(controllerMethods);
9184

85+
return controllerClass;
9286

9387

9488
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /