|  | 
| 4 | 4 | import com.github.javaparser.ast.CompilationUnit; | 
| 5 | 5 | import com.github.javaparser.ast.PackageDeclaration; | 
| 6 | 6 | import com.github.javaparser.ast.body.TypeDeclaration; | 
| 7 |  | -import com.github.javaparser.javadoc.description.JavadocInlineTag; | 
| 8 | 7 | import com.google.common.collect.Sets; | 
| 9 |  | -import com.hsjfans.github.model.Param; | 
|  | 8 | +import com.hsjfans.github.model.ControllerClass; | 
| 10 | 9 | import com.hsjfans.github.util.ClassUtils; | 
| 11 |  | -import com.hsjfans.github.util.CommentUtil; | 
|  | 10 | +import com.hsjfans.github.util.CollectionUtil; | 
| 12 | 11 | import com.hsjfans.github.util.Constant; | 
| 13 | 12 | import com.hsjfans.github.util.LogUtil; | 
|  | 13 | +import org.springframework.web.bind.annotation.*; | 
| 14 | 14 | 
 | 
| 15 | 15 | import java.io.File; | 
|  | 16 | +import java.lang.annotation.Annotation; | 
|  | 17 | +import java.util.Map; | 
| 16 | 18 | import java.util.Optional; | 
| 17 | 19 | import java.util.Set; | 
| 18 | 20 | 
 | 
| @@ -52,26 +54,40 @@ protected Set<CompilationUnit> getAllControllerClass(Set<File> javaFiles) { | 
| 52 | 54 |  } | 
| 53 | 55 | 
 | 
| 54 | 56 |  @Override | 
| 55 |  | - protected void parseCompilationUnit(CompilationUnit compilationUnit) { | 
|  | 57 | + protected ControllerClass parseCompilationUnit(CompilationUnit compilationUnit) { | 
|  | 58 | + ControllerClass controllerClass = null; | 
| 56 | 59 |  Optional<PackageDeclaration> packageDeclaration = compilationUnit.getPackageDeclaration(); | 
| 57 | 60 |  if(!packageDeclaration.isPresent()){ | 
| 58 |  | - return; | 
|  | 61 | + returnnull; | 
| 59 | 62 |  } | 
| 60 | 63 |  String packageName = packageDeclaration.get().getNameAsString(); | 
| 61 | 64 |  Optional<TypeDeclaration<?>> typeDeclaration = compilationUnit.getPrimaryType(); | 
| 62 | 65 |  if(!typeDeclaration.isPresent()){ | 
| 63 |  | - return; | 
|  | 66 | + returnnull; | 
| 64 | 67 |  } | 
| 65 | 68 |  String className = packageName+"."+typeDeclaration.get().getName(); | 
| 66 | 69 |  Class<?> cl ; | 
| 67 | 70 |  try { | 
| 68 | 71 |  cl = classLoader.loadClass(className); | 
| 69 | 72 |  }catch (Exception e){ | 
| 70 | 73 |  LogUtil.warn(e.getMessage()); | 
| 71 |  | - return; | 
|  | 74 | + returnnull; | 
| 72 | 75 |  } | 
| 73 | 76 | 
 | 
| 74 |  | - Param param = ClassUtils.parseClassComment(typeDeclaration.get().getComment().orElse(null),cl); | 
|  | 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 | + } | 
|  | 84 | + | 
|  | 85 | + // contain `RequestMapping(Value="")` | 
|  | 86 | + if(annotationMap.containsKey(RequestMapping.class)){ | 
|  | 87 | + ((RequestMapping)annotationMap.get(RequestMapping.class)) | 
|  | 88 | + } | 
|  | 89 | + | 
|  | 90 | + controllerClass = ClassUtils.parseClassComment(typeDeclaration.get().getComment().orElse(null),cl); | 
| 75 | 91 | 
 | 
| 76 | 92 | 
 | 
| 77 | 93 | 
 | 
|  | 
0 commit comments