1

JAutoDoc を介してメソッド (フィールド) アノテーションの内容を調べることができるかどうかを知りたいです。

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

この場合、結果の javadoc で、注釈属性に基づいて値を出力したいと思いますattribute。を使用して正規表現とテンプレートを作成するのは簡単に思え#if(...)ます。プレビュー ウィンドウに入力されている間はすべて正常に動作しますが、私のコードでは動作しません。JAutoDoc は注釈をすべて無視しているようです。メソッド/フィールド署名を超えて見るように説得する方法はありますか?

テンプレートをいくつかのレベルで挿入しようとしました。たとえば、メソッド階層のスタンドアロン テンプレートや、"Returns other" テンプレートのサブテンプレートです。

ありがとう、フランク

4

2 に答える 2

1

バージョン 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-10-10T08:15:54.720 に答える
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
 */
于 2012-04-26T20:35:01.423 に答える