<dependency>
<groupId>com.thoughtworks.qdox</groupId>
<artifactId>qdox</artifactId>
<version>2.0-M10</version>
</dependency>
JavaProjectBuilder builder = new JavaProjectBuilder();
//源码目录
// builder.addSourceTree(new File("src/main/java/com/example/swagger11/corn/HelloController.java"));
builder.addSourceTree(new File("/Users/aop/swagger11/src/main/java/com/example/swagger11/corn/HelloController.java"));
// Collection classes = builder.getClasses();
// System.out.println(classes);
JavaClass cls = builder.getClassByName("com.example.swagger11.corn.HelloController");
List methods = cls.getMethods();
for(Object method : methods){
System.out.println(((JavaMethod)method).getCodeBlock()); //方法体的源码
}
获取方法体代码
最新推荐文章于 2022-06-21 22:36:33 发布