我想知道是否可以通过JAutoDoc检查方法(字段)注释的内容。
public interface A {
@MyAnnotation(attribute=false)
String getSomeValue();
}在生成的javadoc中,我希望根据注释属性输出一个值,在本例中为attribute。使用#if(...)构建正则表达式和模板似乎很简单。在预览窗口中输入时一切正常,但在我的代码中却不起作用: JAutoDoc似乎完全忽略了注释。有没有办法说服它看方法/字段签名之外的东西呢?
我尝试了几个级别的插入模板,例如方法层次结构中的独立模板或“返回其他”模板的子模板。
谢谢,弗兰克
发布于 2012-10-10 16:15:55
使用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发布于 2012-04-27 04:35:01
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
*/https://stackoverflow.com/questions/9531471
复制相似问题