クラス AnnotationUtils
このクラスのほとんどの機能は、JDK のイントロスペクション機能自体では提供されないことに注意してください。
実行時に保持されるアプリケーションアノテーション (トランザクション制御、認可、サービス公開など) の一般的なルールとして、JDK のプレーンアノテーションルックアップメソッドではなく、このクラスのルックアップメソッド ( findAnnotation(Method, Class)
や getAnnotation(Method, Class)
など) を常に使用します。指定されたクラスレベルのみの get ルックアップ ( getAnnotation(Method, Class)
) と、指定されたメソッドの継承階層全体での find ルックアップ ( findAnnotation(Method, Class)
) を明示的に選択することもできます。
用語
直接存在する、間接的に存在する、および存在 するという用語は、AnnotatedElement
SE(Java 8 内)のクラスレベルの javadoc で定義されているのと同じ意味を持っています。 アノテーションが要素上に存在するいくつかの他のアノテーションのメタアノテーションとして宣言されている場合、アノテーションは、要素上でメタ存在します。A
は、他のアノテーションに直接存在またはメタ存在する場合アノテーション A
は別のアノテーションにメタ存在しています。
メタアノテーションサポート
このクラスのほとんどの find*()
メソッドおよび一部の get*()
メソッドは、メタアノテーションとして使用されるアノテーションを検索するためのサポートを提供します。詳細については、このクラスの各メソッドの javadoc を参照してください。構成されたアノテーションで属性オーバーライドを使用したメタアノテーションをきめ細かくサポートするには、代わりに AnnotatedElementUtils
のより具象メソッドを使用することを検討してください。
属性エイリアス
アノテーション、アノテーションの配列、AnnotationAttributes
を返すこのクラスのすべての public メソッドは、@AliasFor
を介して構成された属性エイリアスを透過的にサポートします。詳細については、さまざまな synthesizeAnnotation*(..)
メソッドを参照してください。
検索の範囲
このクラスのメソッドで使用される検索アルゴリズムは、指定された型の最初のアノテーションが見つかると、アノテーションの検索を停止します。結果として、指定された型の追加のアノテーションは通知なく無視されます。
- 導入:
- 2.0
- 作成者:
- Rob Harrop, Juergen Hoeller, Sam Brannen, Mark Fisher, Chris Beams, Phillip Webb, Oleg Zhurakousky
- 関連事項:
フィールドサマリー
コンストラクターのサマリー
方法の概要
修飾子と型メソッド説明static void
内部アノテーションメタデータキャッシュをクリアします。static <A extends AnnotationSE>
AfindAnnotation
(ClassSE<?> clazz, ClassSE<A> annotationType) 提供されたClass
SE でannotationType
の単一のAnnotation
SE を検索し、そのインターフェース、アノテーション、スーパークラスをトラバースします(アノテーションが特定のクラス自体に直接存在しない場合)。static <A extends AnnotationSE>
AfindAnnotation
(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType) static <A extends AnnotationSE>
AfindAnnotation
(MethodSE method, ClassSE<A> annotationType) static ClassSE<?>
findAnnotationDeclaringClass
(ClassSE<? extends AnnotationSE> annotationType, ClassSE<?> clazz) 使用すべきではありません。static ClassSE<?>
findAnnotationDeclaringClassForTypes
(ListSE<ClassSE<? extends AnnotationSE>> annotationTypes, ClassSE<?> clazz) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換えstatic <A extends AnnotationSE>
AgetAnnotation
(AnnotationSE annotation, ClassSE<A> annotationType) 提供されたアノテーションからannotationType
の単一のAnnotation
SE を取得します: 指定されたアノテーション自体またはその直接メタアノテーションのいずれか。static <A extends AnnotationSE>
AgetAnnotation
(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType) 指定されたAnnotatedElement
SE からannotationType
の単一のAnnotation
SE を取得します。ここで、アノテーションはAnnotatedElement
に存在するかメタ存在します。static <A extends AnnotationSE>
AgetAnnotation
(MethodSE method, ClassSE<A> annotationType) getAnnotationAttributes
(AnnotationSE annotation) 指定されたアノテーションの属性をMap
SE として取得し、すべての属性型を保持します。getAnnotationAttributes
(AnnotationSE annotation, boolean classValuesAsString) 指定されたアノテーションの属性をMap
SE として取得します。static AnnotationAttributes
getAnnotationAttributes
(AnnotationSE annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap) 指定されたアノテーションの属性をAnnotationAttributes
マップとして取得します。static AnnotationAttributes
getAnnotationAttributes
(AnnotatedElementSE annotatedElement, AnnotationSE annotation) 指定されたアノテーションの属性をAnnotationAttributes
マップとして取得します。static AnnotationAttributes
getAnnotationAttributes
(AnnotatedElementSE annotatedElement, AnnotationSE annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap) 指定されたアノテーションの属性をAnnotationAttributes
マップとして取得します。static AnnotationSE[]
getAnnotations
(AnnotatedElementSE annotatedElement) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換えstatic AnnotationSE[]
getAnnotations
(MethodSE method) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換えstatic <A extends AnnotationSE>
SetSE<A>getDeclaredRepeatableAnnotations
(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換えstatic <A extends AnnotationSE>
SetSE<A>getDeclaredRepeatableAnnotations
(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType, ClassSE<? extends AnnotationSE> containerAnnotationType) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換えstatic ObjectSE
getDefaultValue
(AnnotationSE annotation) アノテーションインスタンスを指定して、単一要素アノテーションのvalue
属性のデフォルト値を取得します。static ObjectSE
getDefaultValue
(AnnotationSE annotation, StringSE attributeName) アノテーションインスタンスを指定して、名前付き属性のデフォルト値を取得します。static ObjectSE
getDefaultValue
(ClassSE<? extends AnnotationSE> annotationType) annotation type
SE を指定して、単一要素のアノテーションのvalue
属性のデフォルト値を取得します。static ObjectSE
getDefaultValue
(ClassSE<? extends AnnotationSE> annotationType, StringSE attributeName) annotation type
SE を指定して、名前付き属性のデフォルト値を取得します。static <A extends AnnotationSE>
SetSE<A>getRepeatableAnnotations
(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換えstatic <A extends AnnotationSE>
SetSE<A>getRepeatableAnnotations
(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType, ClassSE<? extends AnnotationSE> containerAnnotationType) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換えstatic ObjectSE
getValue
(AnnotationSE annotation) アノテーションインスタンスを指定して、単一要素のアノテーションのvalue
属性の値を取得します。static ObjectSE
getValue
(AnnotationSE annotation, StringSE attributeName) アノテーションインスタンスを指定して、名前付き属性の値を取得します。static boolean
isAnnotationDeclaredLocally
(ClassSE<? extends AnnotationSE> annotationType, ClassSE<?> clazz) 指定されたannotationType
のアノテーションがローカルで宣言されているかどうか(つまりstatic boolean
isAnnotationInherited
(ClassSE<? extends AnnotationSE> annotationType, ClassSE<?> clazz) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換えstatic boolean
isAnnotationMetaPresent
(ClassSE<? extends AnnotationSE> annotationType, ClassSE<? extends AnnotationSE> metaAnnotationType) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換えstatic boolean
isCandidateClass
(ClassSE<?> clazz, ClassSE<? extends AnnotationSE> annotationType) 指定されたクラスが、指定されたアノテーション(型、メソッド、フィールドレベル)を運ぶ候補であるかどうかを判断します。static boolean
isCandidateClass
(ClassSE<?> clazz, StringSE annotationName) 指定されたクラスが、指定されたアノテーション(型、メソッド、フィールドレベル)を運ぶ候補であるかどうかを判断します。static boolean
isCandidateClass
(ClassSE<?> clazz, CollectionSE<ClassSE<? extends AnnotationSE>> annotationTypes) 指定されたクラスが、(型、メソッド、フィールドレベルで)指定されたアノテーションの 1 つを運ぶ候補であるかどうかを判断します。static boolean
isInJavaLangAnnotationPackage
(AnnotationSE annotation) 提供されたAnnotation
SE がコア JDKjava.lang.annotation
パッケージで定義されているかどうかを確認します。static boolean
isInJavaLangAnnotationPackage
(StringSE annotationType) 指定された名前のAnnotation
SE がコア JDKjava.lang.annotation
パッケージで定義されているかどうかを確認します。static boolean
isSynthesizedAnnotation
(AnnotationSE annotation) 提供されたAnnotation
SE が Spring によって合成されたかどうかを判断します (つまりstatic void
postProcessAnnotationAttributes
(ObjectSE annotatedElement, AnnotationAttributes attributes, boolean classValuesAsString) 提供されたAnnotationAttributes
を後処理し、ネストされたアノテーションをAnnotation
インスタンスとして保持します。static void
registerDefaultValues
(AnnotationAttributes attributes) 可能な場合は、指定された属性のアノテーションで宣言されたデフォルト値を登録します。static <A extends AnnotationSE>
AsynthesizeAnnotation
(A annotation, AnnotatedElementSE annotatedElement) @AliasFor
でアノテーションが付けられたアノテーション属性の属性別名セマンティクスを透過的に実施する動的プロキシにラップすることにより、提供されたannotation
からアノテーションを合成します。static <A extends AnnotationSE>
AsynthesizeAnnotation
(ClassSE<A> annotationType) デフォルトの属性値からアノテーションを合成します。static <A extends AnnotationSE>
AsynthesizeAnnotation
(MapSE<StringSE, ObjectSE> attributes, ClassSE<A> annotationType, AnnotatedElementSE annotatedElement) 指定されたannotationType
のアノテーションを実装し、@AliasFor
でアノテーションが付けられたアノテーション属性に属性エイリアスセマンティクスを透過的に適用する動的プロキシでマップをラップすることにより、提供されたアノテーション属性のマップからアノテーションを合成します。static void
validateAnnotation
(AnnotationSE annotation) 指定されたアノテーションの宣言された属性を確認します。特に、Google App Engine のClass
値 (初期のClass.getAnnotations() failure
ではなく) のTypeNotPresentExceptionProxy
の遅れた到着をカバーします。
フィールドの詳細
VALUE
単一の要素を持つアノテーションの属性名。- 関連事項:
コンストラクターの詳細
AnnotationUtils
public AnnotationUtils()
メソッドの詳細
isCandidateClass
public static boolean isCandidateClass(ClassSE<?> clazz, CollectionSE<ClassSE<? extends AnnotationSE>> annotationTypes) 指定されたクラスが、(型、メソッド、フィールドレベルで)指定されたアノテーションの 1 つを運ぶ候補であるかどうかを判断します。- パラメーター:
clazz
- イントロスペクトするクラスannotationTypes
- 検索可能なアノテーション型- 戻り値:
false
(クラスにそのようなアノテーションがどのレベルにもないことがわかっている場合)。それ以外の場合はtrue
。ここでtrue
が返される場合、呼び出し元は通常、完全なメソッド / フィールドイントロスペクションを実行します。- 導入:
- 5.2
- 関連事項:
isCandidateClass
public static boolean isCandidateClass(ClassSE<?> clazz, @Nullable ClassSE<? extends AnnotationSE> annotationType) 指定されたクラスが、指定されたアノテーション(型、メソッド、フィールドレベル)を運ぶ候補であるかどうかを判断します。- パラメーター:
clazz
- イントロスペクトするクラスannotationType
- 検索可能なアノテーション型- 戻り値:
false
(クラスにそのようなアノテーションがどのレベルにもないことがわかっている場合)。それ以外の場合はtrue
。ここでtrue
が返される場合、呼び出し元は通常、完全なメソッド / フィールドイントロスペクションを実行します。- 導入:
- 5.2
- 関連事項:
isCandidateClass
指定されたクラスが、指定されたアノテーション(型、メソッド、フィールドレベル)を運ぶ候補であるかどうかを判断します。- パラメーター:
clazz
- イントロスペクトするクラスannotationName
- 検索可能なアノテーション型の完全修飾名- 戻り値:
false
(クラスにそのようなアノテーションがどのレベルにもないことがわかっている場合)。それ以外の場合はtrue
。ここでtrue
が返される場合、呼び出し元は通常、完全なメソッド / フィールドイントロスペクションを実行します。- 導入:
- 5.2
- 関連事項:
getAnnotation
@Nullable public static <A extends AnnotationSE> A getAnnotation(AnnotationSE annotation, ClassSE<A> annotationType) 提供されたアノテーションからannotationType
の単一のAnnotation
SE を取得します: 指定されたアノテーション自体またはその直接メタアノテーションのいずれか。このメソッドは、単一レベルのメタアノテーションのみをサポートすることに注意してください。任意のレベルのメタアノテーションをサポートするには、代わりに
find*()
メソッドの 1 つを使用してください。- パラメーター:
annotation
- チェックするアノテーションannotationType
- ローカルおよびメタアノテーションとして検索するアノテーション型- 戻り値:
- 最初に一致したアノテーション。見つからない場合は
null
- 導入:
- 4.0
getAnnotation
@Nullable public static <A extends AnnotationSE> A getAnnotation(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType) 指定されたAnnotatedElement
SE からannotationType
の単一のAnnotation
SE を取得します。ここで、アノテーションはAnnotatedElement
に存在するかメタ存在します。このメソッドは、単一レベルのメタアノテーションのみをサポートすることに注意してください。メタアノテーションの任意のレベルをサポートするには、代わりに
findAnnotation(AnnotatedElement, Class)
を使用してください。- パラメーター:
annotatedElement
- アノテーションを取得するAnnotatedElement
annotationType
- ローカルおよびメタアノテーションとして検索するアノテーション型- 戻り値:
- 最初に一致したアノテーション。見つからない場合は
null
- 導入:
- 3.1
getAnnotation
@Nullable public static <A extends AnnotationSE> A getAnnotation(MethodSE method, ClassSE<A> annotationType) 提供されているMethod
SE からannotationType
の単一のAnnotation
SE を取得します。ここで、アノテーションはメソッドに存在するか、メタに存在します。コンパイラーによって生成されたブリッジ
Methods
SE を正しく処理します。このメソッドは、単一レベルのメタアノテーションのみをサポートすることに注意してください。メタアノテーションの任意のレベルをサポートするには、代わりに
findAnnotation(Method, Class)
を使用してください。- パラメーター:
method
- アノテーションを探すメソッドannotationType
- 検索するアノテーション型- 戻り値:
- 最初に一致したアノテーション。見つからない場合は
null
- 関連事項:
getAnnotations
@DeprecatedSE @Nullable public static AnnotationSE[] getAnnotations(AnnotatedElementSE annotatedElement) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換え- パラメーター:
annotatedElement
- アノテーションを取得するメソッド、コンストラクター、フィールド- 戻り値:
- 見つかったアノテーション、空の配列、解決できない場合は
null
(たとえば、アノテーション属性内のネストされたクラス値が実行時に解決できなかったため) - 導入:
- 4.0.8
- 関連事項:
getAnnotations
使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換え提供されたMethod
SE に存在するすべてのAnnotations
SE を取得します。コンパイラーによって生成されたブリッジ
Methods
SE を正しく処理します。メタアノテーションは検索されません。
- パラメーター:
method
- アノテーションを取得するメソッド- 戻り値:
- 見つかったアノテーション、空の配列、解決できない場合は
null
(たとえば、アノテーション属性内のネストされたクラス値が実行時に解決できなかったため) - 関連事項:
getRepeatableAnnotations
@DeprecatedSE public static <A extends AnnotationSE> SetSE<A> getRepeatableAnnotations(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換え提供されたAnnotatedElement
SE からannotationType
の繰り返し可能なアノテーションSEを取得します。このようなアノテーションは、要素に存在するか、間接的に存在するか、メタに存在します。このメソッドは、Java 8 の
AnnotatedElement.getAnnotationsByType(Class)
SE の機能を模倣し、@Repeatable
SE(Java 8 以降で実行されている場合)を介して宣言されたコンテナーアノテーションの自動検出をサポートし、メタアノテーションを追加サポートします。単一のアノテーションとコンテナーアノテーション内にネストされたアノテーションの両方を処理します。
指定された要素が
Method
SE である場合、コンパイラーによって生成されたブリッジメソッドを正しく処理します。提供された要素にアノテーションが存在しない場合、メタアノテーションが検索されます。
- パラメーター:
annotatedElement
- アノテーションを探す要素annotationType
- 検索するアノテーション型- 戻り値:
- 見つかったアノテーションまたは空のセット (非
null
) - 導入:
- 4.2
- 関連事項:
getRepeatableAnnotations(AnnotatedElement, Class, Class)
getDeclaredRepeatableAnnotations(AnnotatedElement, Class, Class)
AnnotatedElementUtils.getMergedRepeatableAnnotations(AnnotatedElement, Class)
BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method)
Repeatable
SEAnnotatedElement.getAnnotationsByType(java.lang.Class<T>)
SE
getRepeatableAnnotations
@DeprecatedSE public static <A extends AnnotationSE> SetSE<A> getRepeatableAnnotations(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType, @Nullable ClassSE<? extends AnnotationSE> containerAnnotationType) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換え提供されたAnnotatedElement
SE からannotationType
の繰り返し可能なアノテーションSEを取得します。このようなアノテーションは、要素に存在するか、間接的に存在するか、メタに存在します。このメソッドは、メタアノテーションの追加サポートにより、Java 8 の
AnnotatedElement.getAnnotationsByType(Class)
SE の機能を模倣します。単一のアノテーションとコンテナーアノテーション内にネストされたアノテーションの両方を処理します。
指定された要素が
Method
SE である場合、コンパイラーによって生成されたブリッジメソッドを正しく処理します。提供された要素にアノテーションが存在しない場合、メタアノテーションが検索されます。
- パラメーター:
annotatedElement
- アノテーションを探す要素annotationType
- 検索するアノテーション型containerAnnotationType
- アノテーションを保持するコンテナーの型。コンテナーがサポートされていない場合、または Java 8 以上で実行するときに @Repeatable
SE を介して検索する必要がある場合は、null
になる可能性があります。- 戻り値:
- 見つかったアノテーションまたは空のセット (非
null
) - 導入:
- 4.2
- 関連事項:
getRepeatableAnnotations(AnnotatedElement, Class)
getDeclaredRepeatableAnnotations(AnnotatedElement, Class)
getDeclaredRepeatableAnnotations(AnnotatedElement, Class, Class)
AnnotatedElementUtils.getMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method)
Repeatable
SEAnnotatedElement.getAnnotationsByType(java.lang.Class<T>)
SE
getDeclaredRepeatableAnnotations
@DeprecatedSE public static <A extends AnnotationSE> SetSE<A> getDeclaredRepeatableAnnotations(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換え提供されたAnnotatedElement
SE からannotationType
の宣言された繰り返し可能な アノテーションSEを取得します。このようなアノテーションは、要素に直接存在するか、間接的に存在するか、メタ存在です。このメソッドは、Java 8 の
AnnotatedElement.getDeclaredAnnotationsByType(Class)
SE の機能を模倣し、@Repeatable
SE(Java 8 以降で実行されている場合)を介して宣言されたコンテナーアノテーションの自動検出をサポートし、メタアノテーションを追加サポートします。単一のアノテーションとコンテナーアノテーション内にネストされたアノテーションの両方を処理します。
指定された要素が
Method
SE である場合、コンパイラーによって生成されたブリッジメソッドを正しく処理します。提供された要素にアノテーションが存在しない場合、メタアノテーションが検索されます。
- パラメーター:
annotatedElement
- アノテーションを探す要素annotationType
- 検索するアノテーション型- 戻り値:
- 見つかったアノテーションまたは空のセット (非
null
) - 導入:
- 4.2
- 関連事項:
getRepeatableAnnotations(AnnotatedElement, Class)
getRepeatableAnnotations(AnnotatedElement, Class, Class)
getDeclaredRepeatableAnnotations(AnnotatedElement, Class, Class)
AnnotatedElementUtils.getMergedRepeatableAnnotations(AnnotatedElement, Class)
BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method)
Repeatable
SEAnnotatedElement.getDeclaredAnnotationsByType(java.lang.Class<T>)
SE
getDeclaredRepeatableAnnotations
@DeprecatedSE public static <A extends AnnotationSE> SetSE<A> getDeclaredRepeatableAnnotations(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType, @Nullable ClassSE<? extends AnnotationSE> containerAnnotationType) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換え提供されたAnnotatedElement
SE からannotationType
の宣言された繰り返し可能な アノテーションSEを取得します。このようなアノテーションは、要素に直接存在するか、間接的に存在するか、メタ存在です。このメソッドは、メタアノテーションの追加サポートにより、Java 8 の
AnnotatedElement.getDeclaredAnnotationsByType(Class)
SE の機能を模倣します。単一のアノテーションとコンテナーアノテーション内にネストされたアノテーションの両方を処理します。
指定された要素が
Method
SE である場合、コンパイラーによって生成されたブリッジメソッドを正しく処理します。提供された要素にアノテーションが存在しない場合、メタアノテーションが検索されます。
- パラメーター:
annotatedElement
- アノテーションを探す要素annotationType
- 検索するアノテーション型containerAnnotationType
- アノテーションを保持するコンテナーの型。コンテナーがサポートされていない場合、または Java 8 以上で実行するときに @Repeatable
SE を介して検索する必要がある場合は、null
になる可能性があります。- 戻り値:
- 見つかったアノテーションまたは空のセット (非
null
) - 導入:
- 4.2
- 関連事項:
getRepeatableAnnotations(AnnotatedElement, Class)
getRepeatableAnnotations(AnnotatedElement, Class, Class)
getDeclaredRepeatableAnnotations(AnnotatedElement, Class)
AnnotatedElementUtils.getMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method)
Repeatable
SEAnnotatedElement.getDeclaredAnnotationsByType(java.lang.Class<T>)
SE
findAnnotation
@Nullable public static <A extends AnnotationSE> A findAnnotation(AnnotatedElementSE annotatedElement, @Nullable ClassSE<A> annotationType) 提供されているAnnotatedElement
SE でannotationType
の単一のAnnotation
SE を見つけます。指定された要素にアノテーションが直接存在しない場合、メタアノテーションが検索されます。
警告 : このメソッドは、アノテーション付きの要素に対して一般的に機能します。つまり、このメソッドは、クラスまたはメソッドの特殊な検索アルゴリズムを実行しません。
findAnnotation(Class, Class)
またはfindAnnotation(Method, Class)
のより具体的なセマンティクスが必要な場合は、代わりにそれらのメソッドの 1 つを呼び出します。- パラメーター:
annotatedElement
- アノテーションを検索するAnnotatedElement
annotationType
- ローカルおよびメタアノテーションとして検索するアノテーション型- 戻り値:
- 最初に一致したアノテーション。見つからない場合は
null
- 導入:
- 4.2
findAnnotation
@Nullable public static <A extends AnnotationSE> A findAnnotation(MethodSE method, @Nullable ClassSE<A> annotationType) 提供されたMethod
SE でannotationType
の単一のAnnotation
SE を見つけ、アノテーションが特定のメソッド自体に直接存在しない場合は、そのスーパーメソッドを(つまり、スーパークラスとインターフェースから)トラバースします。コンパイラーによって生成されたブリッジ
Methods
SE を正しく処理します。メソッドにアノテーションが直接存在しない場合は、メタアノテーションが検索されます。
メソッドのアノテーションはデフォルトでは継承されないため、これを明示的に処理する必要があります。
- パラメーター:
method
- アノテーションを探すメソッドannotationType
- 検索するアノテーション型- 戻り値:
- 最初に一致したアノテーション。見つからない場合は
null
- 関連事項:
findAnnotation
@Nullable public static <A extends AnnotationSE> A findAnnotation(ClassSE<?> clazz, @Nullable ClassSE<A> annotationType) 提供されたClass
SE でannotationType
の単一のAnnotation
SE を検索し、そのインターフェース、アノテーション、スーパークラスをトラバースします(アノテーションが特定のクラス自体に直接存在しない場合)。このメソッドは、
inherited
SE として宣言されていないクラスレベルのアノテーション、およびメタアノテーションとインターフェースのアノテーションを明示的に処理します。アルゴリズムは次のように動作します。
- 指定されたクラスのアノテーションを検索し、見つかった場合はそれを返します。
- 指定されたクラスが宣言するすべてのアノテーションを再帰的に検索します。
- 指定されたクラスが宣言するすべてのインターフェースを再帰的に検索します。
- 指定されたクラスのスーパークラス階層を再帰的に検索します。
メモ: この文脈では、用語は再帰的に、現在のインターフェース、アノテーション、スーパークラスをアノテーションとして検索するクラスとしてステップ 1 に戻ることにより、検索プロセスが続行することを意味します。
- パラメーター:
clazz
- アノテーションを探すクラスannotationType
- 検索するアノテーションの型- 戻り値:
- 最初に一致したアノテーション。見つからない場合は
null
findAnnotationDeclaringClass
@DeprecatedSE @Nullable public static ClassSE<?> findAnnotationDeclaringClass(ClassSE<? extends AnnotationSE> annotationType, @Nullable ClassSE<?> clazz) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換え指定されたannotationType
のアノテーションが直接存在する指定されたclazz
(指定されたclazz
自体を含む)の継承階層の最初のClass
SE を見つけます。提供された
clazz
がインターフェースの場合、インターフェース自体のみがチェックされます。インターフェースの継承階層はトラバースされません。メタアノテーションは検索されません。
標準の
Class
SE API は、継承階層のどのクラスが実際にAnnotation
SE を宣言するかを決定するメカニズムを提供しないため、これを明示的に処理する必要があります。- パラメーター:
annotationType
- 検索するアノテーション型clazz
- アノテーションを確認するクラス (null
の場合があります)- 戻り値:
- 指定された
annotationType
または見つからない場合はnull
のアノテーションを宣言する継承階層の最初のClass
SE - 関連事項:
findAnnotationDeclaringClassForTypes
@DeprecatedSE @Nullable public static ClassSE<?> findAnnotationDeclaringClassForTypes(ListSE<ClassSE<? extends AnnotationSE>> annotationTypes, @Nullable ClassSE<?> clazz) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換え指定されたannotationTypes
の少なくとも 1 つが直接存在する指定されたclazz
(指定されたclazz
自体を含む)の継承階層の最初のClass
SE を見つけます。提供された
clazz
がインターフェースの場合、インターフェース自体のみがチェックされます。インターフェースの継承階層はトラバースされません。メタアノテーションは検索されません。
標準の
Class
SE API は、継承階層内のどのクラスが実際にいくつかの候補アノテーションSEの 1 つを宣言するかを決定するメカニズムを提供しないため、これを明示的に処理する必要があります。- パラメーター:
annotationTypes
- 検索するアノテーション型clazz
- アノテーションを確認するクラス (null
の場合があります)- 戻り値:
- 指定された
annotationTypes
または見つからない場合はnull
の少なくとも 1 つのアノテーションを宣言する継承階層の最初のClass
SE - 導入:
- 3.2.2
- 関連事項:
isAnnotationDeclaredLocally
public static boolean isAnnotationDeclaredLocally(ClassSE<? extends AnnotationSE> annotationType, ClassSE<?> clazz) 指定されたannotationType
のアノテーションが、指定されたclazz
でローカルに宣言されている(つまり、直接存在している)かどうかを判断します。提供される
Class
SE は任意の型を表すことができます。メタアノテーションは検索されません。
メモ: このメソッドは、アノテーションが継承SEされているかどうかを判別しません。
- パラメーター:
annotationType
- 検索するアノテーション型clazz
- アノテーションを確認するクラス- 戻り値:
true
(指定されたannotationType
のアノテーションが直接存在する場合)- 関連事項:
isAnnotationInherited
@DeprecatedSE public static boolean isAnnotationInherited(ClassSE<? extends AnnotationSE> annotationType, ClassSE<?> clazz) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換え指定されたannotationType
のアノテーションが、提供されたclazz
に存在し、継承されているSE(つまり、直接存在していない)かどうかを判別します。メタアノテーションは検索されません。
提供された
clazz
がインターフェースの場合、インターフェース自体のみがチェックされます。Java の標準的なメタアノテーションセマンティクスに従って、インターフェースの継承階層はトラバースされません。アノテーションの継承の詳細については、@Inherited
メタアノテーションの javadocSE を参照してください。- パラメーター:
annotationType
- 検索するアノテーション型clazz
- アノテーションを確認するクラス- 戻り値:
true
(指定されたannotationType
のアノテーションが存在し、継承されている場合)- 関連事項:
isAnnotationMetaPresent
@DeprecatedSE public static boolean isAnnotationMetaPresent(ClassSE<? extends AnnotationSE> annotationType, @Nullable ClassSE<? extends AnnotationSE> metaAnnotationType) 使用すべきではありません。5.2 以降、MergedAnnotations
API に置き換え型metaAnnotationType
のアノテーションが、提供されたannotationType
にメタ存在するかどうかを判別します。- パラメーター:
annotationType
- 検索するアノテーション型metaAnnotationType
- 検索するメタアノテーションの型- 戻り値:
true
(そのようなアノテーションがメタ表示の場合)- 導入:
- 4.2.1
isInJavaLangAnnotationPackage
提供されたAnnotation
SE がコア JDKjava.lang.annotation
パッケージで定義されているかどうかを確認します。- パラメーター:
annotation
- チェックするアノテーション- 戻り値:
- アノテーションが
java.lang.annotation
パッケージにある場合はtrue
isInJavaLangAnnotationPackage
指定された名前のAnnotation
SE がコア JDKjava.lang.annotation
パッケージで定義されているかどうかを確認します。- パラメーター:
annotationType
- チェックするアノテーション型の名前- 戻り値:
- アノテーションが
java.lang.annotation
パッケージにある場合はtrue
- 導入:
- 4.2
validateAnnotation
指定されたアノテーションの宣言された属性を確認します。特に、Google App Engine のClass
値 (初期のClass.getAnnotations() failure
ではなく) のTypeNotPresentExceptionProxy
の遅れた到着をカバーします。このメソッドが失敗しないということは、
getAnnotationAttributes(Annotation)
も (後で試行したときに) 失敗しないことを示します。- パラメーター:
annotation
- 検証するアノテーション- 例外:
IllegalStateExceptionSE
- 宣言されたClass
属性を読み取ることができなかった場合- 導入:
- 4.3.15
- 関連事項:
getAnnotationAttributes
指定されたアノテーションの属性をMap
SE として取得し、すべての属性型を保持します。classValuesAsString
およびnestedAnnotationsAsMap
パラメーターをfalse
に設定してgetAnnotationAttributes(Annotation, boolean, boolean)
を呼び出すのと同じです。メモ: このメソッドは、実際に
AnnotationAttributes
インスタンスを返します。ただし、Map
署名はバイナリ互換性のために保存されています。- パラメーター:
annotation
- 属性を取得するためのアノテーション- 戻り値:
- 属性名をキーとして、対応する属性値を値として持つアノテーション属性のマップ (非
null
) - 関連事項:
getAnnotationAttributes
public static MapSE<StringSE,ObjectSE> getAnnotationAttributes(AnnotationSE annotation, boolean classValuesAsString) 指定されたアノテーションの属性をMap
SE として取得します。nestedAnnotationsAsMap
パラメーターをfalse
に設定してgetAnnotationAttributes(Annotation, boolean, boolean)
を呼び出すのと同じです。メモ: このメソッドは、実際に
AnnotationAttributes
インスタンスを返します。ただし、Map
署名はバイナリ互換性のために保存されています。- パラメーター:
annotation
- 属性を取得するためのアノテーションclassValuesAsString
- クラス参照を文字列に変換するか(AnnotationMetadata
との互換性のため)、クラス参照として保持するか- 戻り値:
- 属性名をキーとして、対応する属性値を値として持つアノテーション属性のマップ (非
null
) - 関連事項:
getAnnotationAttributes
public static AnnotationAttributes getAnnotationAttributes(AnnotationSE annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap) 指定されたアノテーションの属性をAnnotationAttributes
マップとして取得します。このメソッドは、リフレクションベースの
StandardAnnotationMetadata
と同等の完全に再帰的なアノテーション読み取り機能を提供します。- パラメーター:
annotation
- 属性を取得するためのアノテーションclassValuesAsString
- クラス参照を文字列に変換するか(AnnotationMetadata
との互換性のため)、クラス参照として保持するかnestedAnnotationsAsMap
- ネストされたアノテーションをAnnotationAttributes
マップに変換するか(AnnotationMetadata
との互換性のため)、Annotation
インスタンスとして保持するか- 戻り値:
- 属性名をキーとして、対応する属性値を値として持つアノテーション属性(特殊なマップ) (非
null
) - 導入:
- 3.1.1
getAnnotationAttributes
public static AnnotationAttributes getAnnotationAttributes(@Nullable AnnotatedElementSE annotatedElement, AnnotationSE annotation) 指定されたアノテーションの属性をAnnotationAttributes
マップとして取得します。classValuesAsString
およびnestedAnnotationsAsMap
パラメーターをfalse
に設定してgetAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean)
を呼び出すのと同じです。- パラメーター:
annotatedElement
- 指定されたアノテーションでアノテーションが付けられた要素。不明な場合はnull
の可能性がありますannotation
- 属性を取得するためのアノテーション- 戻り値:
- 属性名をキーとして、対応する属性値を値として持つアノテーション属性(特殊なマップ) (非
null
) - 導入:
- 4.2
- 関連事項:
getAnnotationAttributes
public static AnnotationAttributes getAnnotationAttributes(@Nullable AnnotatedElementSE annotatedElement, AnnotationSE annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap) 指定されたアノテーションの属性をAnnotationAttributes
マップとして取得します。このメソッドは、リフレクションベースの
StandardAnnotationMetadata
と同等の完全に再帰的なアノテーション読み取り機能を提供します。- パラメーター:
annotatedElement
- 指定されたアノテーションでアノテーションが付けられた要素。不明な場合はnull
の可能性がありますannotation
- 属性を取得するためのアノテーションclassValuesAsString
- クラス参照を文字列に変換するか(AnnotationMetadata
との互換性のため)、クラス参照として保持するかnestedAnnotationsAsMap
- ネストされたアノテーションをAnnotationAttributes
マップに変換するか(AnnotationMetadata
との互換性のため)、Annotation
インスタンスとして保持するか- 戻り値:
- 属性名をキーとして、対応する属性値を値として持つアノテーション属性(特殊なマップ) (非
null
) - 導入:
- 4.2
registerDefaultValues
可能な場合は、指定された属性のアノテーションで宣言されたデフォルト値を登録します。- パラメーター:
attributes
- 処理するアノテーション属性- 導入:
- 4.3.2
postProcessAnnotationAttributes
public static void postProcessAnnotationAttributes(@Nullable ObjectSE annotatedElement, @Nullable AnnotationAttributes attributes, boolean classValuesAsString) 提供されたAnnotationAttributes
を後処理し、ネストされたアノテーションをAnnotation
インスタンスとして保持します。具体的には、このメソッドは、
@AliasFor
でアノテーションが付けられたアノテーション属性に属性エイリアスセマンティクスを適用し、デフォルト値のプレースホルダーを元のデフォルト値に置き換えます。- パラメーター:
annotatedElement
- 指定された属性の作成元であるアノテーションまたはアノテーション階層でアノテーションが付けられた要素。不明な場合はnull
の可能性がありますattributes
- 後処理するアノテーション属性classValuesAsString
- クラス参照を文字列に変換するか(AnnotationMetadata
との互換性のため)、クラス参照として保持するか- 導入:
- 4.3.2
- 関連事項:
getValue
アノテーションインスタンスを指定して、単一要素のアノテーションのvalue
属性の値を取得します。- パラメーター:
annotation
- 値を取得するアノテーションインスタンス- 戻り値:
- 属性値。
AnnotationConfigurationException
が原因で属性値を取得できない場合を除き、見つからない場合はnull
。この場合、そのような例外が再スローされます。 - 関連事項:
getValue
@Nullable public static ObjectSE getValue(@Nullable AnnotationSE annotation, @Nullable StringSE attributeName) アノテーションインスタンスを指定して、名前付き属性の値を取得します。- パラメーター:
annotation
- 値を取得するアノテーションインスタンスattributeName
- 取得する属性値の名前- 戻り値:
- 属性値。
AnnotationConfigurationException
が原因で属性値を取得できない場合を除き、見つからない場合はnull
。この場合、そのような例外が再スローされます。 - 関連事項:
getDefaultValue
アノテーションインスタンスを指定して、単一要素アノテーションのvalue
属性のデフォルト値を取得します。- パラメーター:
annotation
- デフォルト値を取得するアノテーションインスタンス- 戻り値:
- デフォルト値。見つからない場合は
null
- 関連事項:
getDefaultValue
@Nullable public static ObjectSE getDefaultValue(@Nullable AnnotationSE annotation, @Nullable StringSE attributeName) アノテーションインスタンスを指定して、名前付き属性のデフォルト値を取得します。- パラメーター:
annotation
- デフォルト値を取得するアノテーションインスタンスattributeName
- 取得する属性値の名前- 戻り値:
- 名前付き属性のデフォルト値。見つからない場合は
null
- 関連事項:
getDefaultValue
annotation type
SE を指定して、単一要素のアノテーションのvalue
属性のデフォルト値を取得します。- パラメーター:
annotationType
- デフォルト値を取得する必要があるアノテーション型- 戻り値:
- デフォルト値。見つからない場合は
null
- 関連事項:
getDefaultValue
@Nullable public static ObjectSE getDefaultValue(@Nullable ClassSE<? extends AnnotationSE> annotationType, @Nullable StringSE attributeName) annotation type
SE を指定して、名前付き属性のデフォルト値を取得します。- パラメーター:
annotationType
- デフォルト値を取得する必要があるアノテーション型attributeName
- 取得する属性値の名前。- 戻り値:
- 名前付き属性のデフォルト値。見つからない場合は
null
- 関連事項:
synthesizeAnnotation
public static <A extends AnnotationSE> A synthesizeAnnotation(A annotation, @Nullable AnnotatedElementSE annotatedElement) @AliasFor
でアノテーションが付けられたアノテーション属性の属性別名セマンティクスを透過的に実施する動的プロキシにラップすることにより、提供されたannotation
からアノテーションを合成します。- パラメーター:
annotation
- 合成するアノテーションannotatedElement
- 指定されたアノテーションでアノテーションが付けられた要素。不明な場合はnull
の可能性があります- 戻り値:
- 指定されたアノテーションが合成可能な場合は、合成されたアノテーション。指定されたアノテーションが
null
の場合はnull
。それ以外の場合、指定されたアノテーションは変更されません - 例外:
AnnotationConfigurationException
-@AliasFor
の無効な構成が検出された場合- 導入:
- 4.2
- 関連事項:
synthesizeAnnotation
デフォルトの属性値からアノテーションを合成します。このメソッドは単に
synthesizeAnnotation(Map, Class, AnnotatedElement)
に委譲し、ソース属性値には空のマップを、AnnotatedElement
SE にはnull
を提供します。- パラメーター:
annotationType
- 合成するアノテーションの型- 戻り値:
- 合成されたアノテーション
- 例外:
IllegalArgumentExceptionSE
- 必要な属性がない場合AnnotationConfigurationException
-@AliasFor
の無効な構成が検出された場合- 導入:
- 4.2
- 関連事項:
synthesizeAnnotation
public static <A extends AnnotationSE> A synthesizeAnnotation(MapSE<StringSE, ObjectSE> attributes, ClassSE<A> annotationType, @Nullable AnnotatedElementSE annotatedElement) 指定されたannotationType
のアノテーションを実装し、@AliasFor
でアノテーションが付けられたアノテーション属性に属性エイリアスセマンティクスを透過的に適用する動的プロキシでマップをラップすることにより、提供されたアノテーション属性のマップからアノテーションを合成します。提供されたマップには、提供された
annotationType
で定義され、エイリアスが設定されていないか、デフォルト値がないすべての属性のキーと値のペアが含まれている必要があります。ネストされたマップとマップのネストされた配列は、それぞれネストされたアノテーションまたはアノテーションのネストされた配列に再帰的に合成されます。AnnotationAttributes
はMap
SE の特殊な型であり、このメソッドのattributes
引数の理想的な候補であることに注意してください。- パラメーター:
attributes
- 合成するアノテーション属性のマップannotationType
- 合成するアノテーションの型annotatedElement
- 指定された属性に対応するアノテーションが付けられた要素。不明な場合はnull
の可能性があります- 戻り値:
- 合成されたアノテーション
- 例外:
IllegalArgumentExceptionSE
- 必要な属性が欠落しているか、属性の型が正しくない場合AnnotationConfigurationException
-@AliasFor
の無効な構成が検出された場合- 導入:
- 4.2
- 関連事項:
isSynthesizedAnnotation
提供されたAnnotation
SE が Spring によって合成された (つまり、動的プロキシでラップされた) かどうかを判断し、属性エイリアス処理などの追加機能を使用します。- パラメーター:
annotation
- チェックするアノテーション- 戻り値:
true
(提供されたアノテーションが合成アノテーションの場合)- 導入:
- 5.3.23
clearCache
public static void clearCache()内部アノテーションメタデータキャッシュをクリアします。- 導入:
- 4.3.15
MergedAnnotations
API に置き換え