Search code examples
annotationsjautodoc

JAutoDoc evaluation of @Annotations?


I would like to know whether it is possible to examine the contents of method (fields) annotations through JAutoDoc.

public interface A {
  @MyAnnotation(attribute=false)
  String getSomeValue();
}

In the resulting javadoc, I would like to output a value based on the annotation attribute, attribute in this case. It seems simple enough to build the regexp and the template with #if(...). Everything works fine while it's entered in the preview window but in my code it's not working: JAutoDoc seems to ignore the annotation alltogether. Is there any way to convince it to look at beyond method/field signature?

I tried several levels of inserting the template, e.g. a standalone template in the method hierarchy or a sub-template of the "Returns other" template.

Thanks, Frank


Solution

  • With JAutodoc at version 1.10.0, a template like this can be built:

    #if(${e.hasAnnotation('MyAnnotation')})
    #set($vc=$e.getAnnotation('MyAnnotation'))
    #if(${$vc.getValue('mandatory')})
    The value is mandatory.
    #else
    The value is optional.
    #end