Search in sources :

Example 1 with JavadocBlockTag

use of act.apidoc.javadoc.JavadocBlockTag 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());
                    }
                }
            }
        }
    }
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) Javadoc(act.apidoc.javadoc.Javadoc) JavadocBlockTag(act.apidoc.javadoc.JavadocBlockTag) TypeDeclaration(com.github.javaparser.ast.body.TypeDeclaration) ParamInfo(act.apidoc.Endpoint.ParamInfo)

Aggregations

ParamInfo (act.apidoc.Endpoint.ParamInfo)1 Javadoc (act.apidoc.javadoc.Javadoc)1 JavadocBlockTag (act.apidoc.javadoc.JavadocBlockTag)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)1 TypeDeclaration (com.github.javaparser.ast.body.TypeDeclaration)1