JAutoDoc对@Annotations的评价?

时间:2012-03-02 10:13:39

标签: annotations jautodoc

我想知道是否可以通过JAutoDoc检查方法(字段)注释的内容。

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

在生成的javadoc中,我希望在这种情况下根据注释属性attribute输出一个值。使用#if(...)构建正则表达式和模板似乎很简单。当它在预览窗口中输入时,一切正常,但在我的代码中,它不起作用:JAutoDoc似乎完全忽略了注释。有没有办法说服它超越方法/字段签名?

我尝试了几个级别的插入模板,例如方法层次结构中的独立模板或“返回其他”模板的子模板。

谢谢,弗兰克

2 个答案:

答案 0 :(得分:1)

JAutodoc不直接支持注释,但也许这个模板符合您的需求:

/**
#set($found = 'false')
#if(${e.getMember().getMember().getAnnotations()})
    #foreach($a in ${e.getMember().getMember().getAnnotations()})
    #if(${a.getElementName()} == 'MyAnnotation')
        #set($found = 'true')
        Annotation found: ${a.getElementName()}
        #foreach($vp in ${a.getMemberValuePairs()})
        #if(${vp.getMemberName()} == 'attribute')
            #if(${vp.getValue()} == 'false')
            attribute is false
            #elseif(${vp.getValue()} == 'true')
            attribute is true
            #else
            attribute is ${vp.getValue()}
            #end
        #end
        #end
    #end
    #end
#end
#if($found == 'false')
 * No Annotation.
#end
 */

答案 1 :(得分:0)

使用版本1.10.0的JAutodoc,可以构建这样的模板:

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