use of act.apidoc.javadoc.Javadoc in project actframework by actframework.
the class ApiManager method exploreDeclaration.
private void exploreDeclaration(ClassOrInterfaceDeclaration classDeclaration, Map<String, Javadoc> methodJavaDocs, String prefix) {
String className = classDeclaration.getName();
String newPrefix = S.blank(prefix) ? className : S.concat(prefix, ".", className);
for (Node node : classDeclaration.getChildrenNodes()) {
if (node instanceof ClassOrInterfaceDeclaration) {
exploreDeclaration((ClassOrInterfaceDeclaration) node, methodJavaDocs, newPrefix);
} else if (node instanceof MethodDeclaration) {
MethodDeclaration methodDeclaration = (MethodDeclaration) node;
List<AnnotationExpr> annoList = methodDeclaration.getAnnotations();
boolean needJavadoc = false;
if (null != annoList && !annoList.isEmpty()) {
for (AnnotationExpr anno : annoList) {
String annoName = anno.getName().getName();
if (actionAnnotations.contains(annoName)) {
needJavadoc = true;
break;
}
}
}
if (!needJavadoc) {
continue;
}
Comment comment = methodDeclaration.getComment();
if (!(comment instanceof JavadocComment)) {
continue;
}
JavadocComment javadocComment = (JavadocComment) comment;
Javadoc javadoc = JavadocParser.parse(javadocComment);
methodJavaDocs.put(S.concat(newPrefix, ".", methodDeclaration.getName()), javadoc);
}
}
}
use of act.apidoc.javadoc.Javadoc in project actframework by actframework.
the class ApiManager method exploreDescriptions.
private void exploreDescriptions(Set<Class> controllerClasses) {
DevModeClassLoader cl = $.cast(Act.app().classLoader());
Map<String, Javadoc> methodJavaDocs = new HashMap<>();
for (Class controllerClass : controllerClasses) {
Source src = cl.source(controllerClass);
if (null == src) {
continue;
}
try {
CompilationUnit compilationUnit = JavaParser.parse(IO.reader(src.code()), true);
List<TypeDeclaration> types = compilationUnit.getTypes();
for (TypeDeclaration type : types) {
if (type instanceof ClassOrInterfaceDeclaration) {
exploreDeclaration((ClassOrInterfaceDeclaration) type, methodJavaDocs, "");
}
}
} catch (Exception e) {
LOGGER.warn(e, "error parsing source for " + controllerClass);
}
}
for (Endpoint endpoint : endpoints) {
Javadoc javadoc = methodJavaDocs.get(endpoint.getId());
if (null != javadoc) {
String desc = javadoc.getDescription().toText();
if (S.notBlank(desc)) {
endpoint.setDescription(desc);
}
List<ParamInfo> params = endpoint.getParams();
if (params.isEmpty()) {
continue;
}
Map<String, ParamInfo> paramLookup = new HashMap<>();
for (ParamInfo param : params) {
paramLookup.put(param.getName(), param);
}
List<JavadocBlockTag> blockTags = javadoc.getBlockTags();
for (JavadocBlockTag tag : blockTags) {
if ("param".equals(tag.getTagName())) {
String paramName = tag.getName().get();
ParamInfo paramInfo = paramLookup.get(paramName);
if (null != paramInfo) {
paramInfo.setDescription(tag.getContent().toText());
}
}
}
}
}
}
Aggregations