【JavaParser】语法树解析-解析方法异常&注解名

 private static class MethodVisitor extends VoidVisitorAdapter<Void> {
        @Override
        public void visit(MethodDeclaration n, Void arg) {
            System.out.println("method:" + n.getName());
            List<AnnotationExpr> annotationList = n.getAnnotations();
            for (AnnotationExpr annotation : annotationList) {
                System.out.println(annotation.getName().toString());
            }
            NodeList<ReferenceType> typeList = n.getThrownExceptions();
            for (ReferenceType type : typeList) {
                System.out.println(type);
            }
            super.visit(n, arg);
        }
    }
   public static void main(String[] args) throws Exception {
        FileInputStream in = new FileInputStream("/Users/12dong/IdeaProjects/files-service/src/main/java/com/qiqu/filesservice/controller/FileController.java");
        CompilationUnit cu = JavaParser.parse(in);
        cu.accept(new MethodVisitor(), null);
    }
method:uploadFile
PostMapping
Exception
发布了119 篇原创文章 · 获赞 10 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/yr12Dong/article/details/88648273