/*** 根据方法名,生成完整的方法行** @param clazz 字节码* @param method java.lang.reflect method* @return public static Annotation getAnnotation(Class<?> clazz, ConstPool constPool);*/public static String getSrcMethod(Class<?> clazz, Method method) {ExtClassDoc classDoc = getClassDoc(clazz);ProgramElementDocImpl programElementDoc = (ProgramElementDocImpl) classDoc.getMethodDoc(method);JCTree.JCMethodDecl jcTree = (JCTree.JCMethodDecl) BeanUtil.getFieldValue(programElementDoc, "tree");if (Objects.isNull(jcTree)) {return null;}String mods = jcTree.getModifiers().toString();String returnStr = jcTree.restype.toString();String methodName = method.getName();List<String> params = jcTree.params.stream().map(JCTree::toString).collect(Collectors.toList());String param = StringUtils.join(params, ",");return StrUtil.format("{} {} {}({});", mods, returnStr, methodName, param);}
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.7.22</version></dependency><dependency><groupId>com.gitee.l0km</groupId><artifactId>javadocreader</artifactId><version>1.1.0</version></dependency>