public abstract class AnnotationUtils extends ObjectSE
このクラスのほとんどの機能は、JDK のイントロスペクション機能自体では提供されないことに注意してください。
ランタイムが保持するアプリケーションアノテーション(トランザクション制御、認可、サービス公開など)の一般的なルールとして、JDK のプレーンアノテーションルックアップメソッドではなく、常にこのクラスのルックアップメソッド(findAnnotation(Method, Class)
または getAnnotation(Method, Class)
など)を使用します。指定されたクラスレベルのみの取得ルックアップ(getAnnotation(Method, Class)
)と指定されたメソッドの継承階層全体の検索ルックアップ(findAnnotation(Method, Class)
)のどちらかを明示的に選択することもできます。
AnnotatedElement
SE(Java 8 内)のクラスレベルの javadoc で定義されているのと同じ意味を持っています。 アノテーションが要素上に存在するいくつかの他のアノテーションのメタアノテーションとして宣言されている場合、アノテーションは、要素上でメタ存在します。A
は、他のアノテーションに直接存在またはメタ存在する場合アノテーション A
は別のアノテーションにメタ存在しています。
このクラスのほとんどの find*()
メソッドおよび一部の get*()
メソッドは、メタアノテーションとして使用されるアノテーションを検索するためのサポートを提供します。詳細については、このクラスの各メソッドの javadoc を参照してください。構成されたアノテーションで属性オーバーライドを使用したメタアノテーションをきめ細かくサポートするには、代わりに AnnotatedElementUtils
のより具象メソッドを使用することを検討してください。
アノテーション、アノテーションの配列、AnnotationAttributes
を返すこのクラスのすべての public メソッドは、@AliasFor
を介して構成された属性エイリアスを透過的にサポートします。詳細については、さまざまな synthesizeAnnotation*(..)
メソッドを参照してください。
このクラスのメソッドで使用される検索アルゴリズムは、指定された型の最初のアノテーションが見つかると、アノテーションの検索を停止します。結果として、指定された型の追加のアノテーションは通知なく無視されます。
AliasFor
, AnnotationAttributes
, AnnotatedElementUtils
, BridgeMethodResolver
, AnnotatedElement.getAnnotations()
SE, AnnotatedElement.getAnnotation(Class)
SE, AnnotatedElement.getDeclaredAnnotations()
SEコンストラクターと説明 |
---|
AnnotationUtils() |
修飾子と型 | メソッドと説明 |
---|---|
static void | clearCache() 内部アノテーションメタデータキャッシュをクリアします。 |
static <A extends AnnotationSE> | findAnnotation(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType) |
static <A extends AnnotationSE> | findAnnotation(ClassSE<?> clazz, ClassSE<A> annotationType) 提供された Class SE で annotationType の単一の Annotation SE を検索し、そのインターフェース、アノテーション、スーパークラスをトラバースします(アノテーションが特定のクラス自体に直接存在しない場合)。 |
static <A extends AnnotationSE> | findAnnotation(MethodSE method, ClassSE<A> annotationType) |
static ClassSE<?> | findAnnotationDeclaringClass(ClassSE<? extends AnnotationSE> annotationType, ClassSE<?> clazz) |
static ClassSE<?> | findAnnotationDeclaringClassForTypes(ListSE<ClassSE<? extends AnnotationSE>> annotationTypes, ClassSE<?> clazz) |
static <A extends AnnotationSE> | getAnnotation(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType) 指定された AnnotatedElement SE から annotationType の単一の Annotation SE を取得します。ここで、アノテーションは AnnotatedElement に存在するかメタ存在します。 |
static <A extends AnnotationSE> | getAnnotation(AnnotationSE annotation, ClassSE<A> annotationType) 提供されたアノテーションから annotationType の単一の Annotation SE を取得します: 指定されたアノテーション自体またはその直接メタアノテーションのいずれか。 |
static <A extends AnnotationSE> | getAnnotation(MethodSE method, ClassSE<A> annotationType) |
static AnnotationAttributes | getAnnotationAttributes(AnnotatedElementSE annotatedElement, AnnotationSE annotation) 指定されたアノテーションの属性を AnnotationAttributes マップとして取得します。 |
static AnnotationAttributes | getAnnotationAttributes(AnnotatedElementSE annotatedElement, AnnotationSE annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap) 指定されたアノテーションの属性を AnnotationAttributes マップとして取得します。 |
static MapSE<StringSE, ObjectSE> | getAnnotationAttributes(AnnotationSE annotation) 指定されたアノテーションの属性を Map SE として取得し、すべての属性型を保持します。 |
static MapSE<StringSE, ObjectSE> | getAnnotationAttributes(AnnotationSE annotation, boolean classValuesAsString) 指定されたアノテーションの属性を Map SE として取得します。 |
static AnnotationAttributes | getAnnotationAttributes(AnnotationSE annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap) 指定されたアノテーションの属性を AnnotationAttributes マップとして取得します。 |
static AnnotationSE[] | getAnnotations(AnnotatedElementSE annotatedElement) 提供された AnnotatedElement SE に存在するすべての Annotations SE を取得します。 |
static AnnotationSE[] | getAnnotations(MethodSE method) 提供された Method SE に存在するすべての Annotations SE を取得します。 |
static <A extends AnnotationSE> | getDeclaredRepeatableAnnotations(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType) 提供された AnnotatedElement SE から annotationType の宣言された繰り返し可能な アノテーションSEを取得します。このようなアノテーションは、要素に直接存在するか、間接的に存在するか、メタ存在です。 |
static <A extends AnnotationSE> | getDeclaredRepeatableAnnotations(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType, ClassSE<? extends AnnotationSE> containerAnnotationType) 提供された AnnotatedElement SE から annotationType の宣言された繰り返し可能な アノテーションSEを取得します。このようなアノテーションは、要素に直接存在するか、間接的に存在するか、メタ存在です。 |
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> | getRepeatableAnnotations(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType) 提供された AnnotatedElement SE から annotationType の繰り返し可能なアノテーションSEを取得します。このようなアノテーションは、要素に存在するか、間接的に存在するか、メタに存在します。 |
static <A extends AnnotationSE> | getRepeatableAnnotations(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType, ClassSE<? extends AnnotationSE> containerAnnotationType) 提供された AnnotatedElement SE から annotationType の繰り返し可能なアノテーションSEを取得します。このようなアノテーションは、要素に存在するか、間接的に存在するか、メタに存在します。 |
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) |
static boolean | isAnnotationMetaPresent(ClassSE<? extends AnnotationSE> annotationType, ClassSE<? extends AnnotationSE> metaAnnotationType) 型 metaAnnotationType のアノテーションが、提供された annotationType にメタ存在するかどうかを判別します。 |
static boolean | isInJavaLangAnnotationPackage(AnnotationSE annotation) 提供された Annotation SE がコア JDK java.lang.annotation パッケージで定義されているかどうかを確認します。 |
static boolean | isInJavaLangAnnotationPackage(StringSE annotationType) 指定された名前の Annotation SE がコア JDK java.lang.annotation パッケージで定義されているかどうかを確認します。 |
static void | postProcessAnnotationAttributes(ObjectSE annotatedElement, AnnotationAttributes attributes, boolean classValuesAsString) 提供された AnnotationAttributes を後処理し、ネストされたアノテーションを Annotation インスタンスとして保持します。 |
static void | registerDefaultValues(AnnotationAttributes attributes) 可能な場合は、指定された属性のアノテーションで宣言されたデフォルト値を登録します。 |
static <A extends AnnotationSE> | synthesizeAnnotation(A annotation, AnnotatedElementSE annotatedElement) @AliasFor でアノテーションが付けられたアノテーション属性の属性別名セマンティクスを透過的に実施する動的プロキシにラップすることにより、提供された annotation からアノテーションを合成します。 |
static <A extends AnnotationSE> | synthesizeAnnotation(ClassSE<A> annotationType) デフォルトの属性値からアノテーションを合成します。 |
static <A extends AnnotationSE> | synthesizeAnnotation(MapSE<StringSE, ObjectSE> attributes, ClassSE<A> annotationType, AnnotatedElementSE annotatedElement) 指定された annotationType のアノテーションを実装し、@AliasFor でアノテーションが付けられたアノテーション属性に属性エイリアスセマンティクスを透過的に適用する動的プロキシでマップをラップすることにより、提供されたアノテーション属性のマップからアノテーションを合成します。 |
static void | validateAnnotation(AnnotationSE annotation) 指定されたアノテーションの宣言された属性を確認します。特に、Google App Engine の (初期の Class.getAnnotations() failure ではなく) Class 値に対する TypeNotPresentExceptionProxy の遅れた到着をカバーします。 |
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
@Nullable public static <A extends AnnotationSE> A getAnnotation(AnnotationSE annotation, ClassSE<A> annotationType)
annotationType
の単一の Annotation
SE を取得します: 指定されたアノテーション自体またはその直接メタアノテーションのいずれか。 このメソッドは、単一レベルのメタアノテーションのみをサポートすることに注意してください。任意のレベルのメタアノテーションをサポートするには、代わりに find*()
メソッドの 1 つを使用してください。
annotation
- チェックするアノテーション annotationType
- ローカルおよびメタアノテーションとして検索するアノテーション型 null
@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
@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
BridgeMethodResolver.findBridgedMethod(Method)
, getAnnotation(AnnotatedElement, Class)
@Nullable public static AnnotationSE[] getAnnotations(AnnotatedElementSE annotatedElement)
annotatedElement
- アノテーションを取得するメソッド、コンストラクター、フィールド null
(たとえばアノテーション属性のネストされたクラス値が実行時に解決されなかったため)AnnotatedElement.getAnnotations()
SE@Nullable public static AnnotationSE[] getAnnotations(MethodSE method)
Method
SE に存在するすべての Annotations
SE を取得します。 コンパイラーによって生成されたブリッジ Methods
SE を正しく処理します。
メタアノテーションは検索されません。
method
- アノテーションを取得するメソッド null
(たとえばアノテーション属性のネストされたクラス値が実行時に解決されなかったため)BridgeMethodResolver.findBridgedMethod(Method)
, AnnotatedElement.getAnnotations()
SEpublic static <A extends AnnotationSE> SetSE<A> getRepeatableAnnotations(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType)
AnnotatedElement
SE から annotationType
の繰り返し可能なアノテーションSEを取得します。このようなアノテーションは、要素に存在するか、間接的に存在するか、メタに存在します。 このメソッドは、Java 8 の AnnotatedElement.getAnnotationsByType(Class)
SE の機能を模倣し、@Repeatable
SE(Java 8 以降で実行されている場合)を介して宣言されたコンテナーアノテーションの自動検出をサポートし、メタアノテーションを追加サポートします。
単一のアノテーションとコンテナーアノテーション内にネストされたアノテーションの両方を処理します。
指定された要素が Method
SE である場合、コンパイラーによって生成されたブリッジメソッドを正しく処理します。
提供された要素にアノテーションが存在しない場合、メタアノテーションが検索されます。
annotatedElement
- アノテーションを探す要素 annotationType
- 検索するアノテーション型 null
)getRepeatableAnnotations(AnnotatedElement, Class, Class)
, getDeclaredRepeatableAnnotations(AnnotatedElement, Class, Class)
, AnnotatedElementUtils.getMergedRepeatableAnnotations(AnnotatedElement, Class)
, BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method)
, Repeatable
SE, AnnotatedElement.getAnnotationsByType(java.lang.Class<T>)
SEpublic static <A extends AnnotationSE> SetSE<A> getRepeatableAnnotations(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType, @Nullable ClassSE<? extends AnnotationSE> containerAnnotationType)
AnnotatedElement
SE から annotationType
の繰り返し可能なアノテーションSEを取得します。このようなアノテーションは、要素に存在するか、間接的に存在するか、メタに存在します。 このメソッドは、メタアノテーションの追加サポートにより、Java 8 の AnnotatedElement.getAnnotationsByType(Class)
SE の機能を模倣します。
単一のアノテーションとコンテナーアノテーション内にネストされたアノテーションの両方を処理します。
指定された要素が Method
SE である場合、コンパイラーによって生成されたブリッジメソッドを正しく処理します。
提供された要素にアノテーションが存在しない場合、メタアノテーションが検索されます。
annotatedElement
- アノテーションを探す要素 annotationType
- 検索するアノテーション型 containerAnnotationType
- アノテーションを保持するコンテナーの型。コンテナーがサポートされていない場合、または Java 8 以上で実行するときに @Repeatable
SE を介して検索する必要がある場合は、null
になる可能性があります。null
)getRepeatableAnnotations(AnnotatedElement, Class)
, getDeclaredRepeatableAnnotations(AnnotatedElement, Class)
, getDeclaredRepeatableAnnotations(AnnotatedElement, Class, Class)
, AnnotatedElementUtils.getMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
, BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method)
, Repeatable
SE, AnnotatedElement.getAnnotationsByType(java.lang.Class<T>)
SEpublic static <A extends AnnotationSE> SetSE<A> getDeclaredRepeatableAnnotations(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType)
AnnotatedElement
SE から annotationType
の宣言された繰り返し可能な アノテーションSEを取得します。このようなアノテーションは、要素に直接存在するか、間接的に存在するか、メタ存在です。 このメソッドは、Java 8 の AnnotatedElement.getDeclaredAnnotationsByType(Class)
SE の機能を模倣し、@Repeatable
SE(Java 8 以降で実行されている場合)を介して宣言されたコンテナーアノテーションの自動検出をサポートし、メタアノテーションを追加サポートします。
単一のアノテーションとコンテナーアノテーション内にネストされたアノテーションの両方を処理します。
指定された要素が Method
SE である場合、コンパイラーによって生成されたブリッジメソッドを正しく処理します。
提供された要素にアノテーションが存在しない場合、メタアノテーションが検索されます。
annotatedElement
- アノテーションを探す要素 annotationType
- 検索するアノテーション型 null
)getRepeatableAnnotations(AnnotatedElement, Class)
, getRepeatableAnnotations(AnnotatedElement, Class, Class)
, getDeclaredRepeatableAnnotations(AnnotatedElement, Class, Class)
, AnnotatedElementUtils.getMergedRepeatableAnnotations(AnnotatedElement, Class)
, BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method)
, Repeatable
SE, AnnotatedElement.getDeclaredAnnotationsByType(java.lang.Class<T>)
SEpublic static <A extends AnnotationSE> SetSE<A> getDeclaredRepeatableAnnotations(AnnotatedElementSE annotatedElement, ClassSE<A> annotationType, @Nullable ClassSE<? extends AnnotationSE> containerAnnotationType)
AnnotatedElement
SE から annotationType
の宣言された繰り返し可能な アノテーションSEを取得します。このようなアノテーションは、要素に直接存在するか、間接的に存在するか、メタ存在です。 このメソッドは、メタアノテーションの追加サポートにより、Java 8 の AnnotatedElement.getDeclaredAnnotationsByType(Class)
SE の機能を模倣します。
単一のアノテーションとコンテナーアノテーション内にネストされたアノテーションの両方を処理します。
指定された要素が Method
SE である場合、コンパイラーによって生成されたブリッジメソッドを正しく処理します。
提供された要素にアノテーションが存在しない場合、メタアノテーションが検索されます。
annotatedElement
- アノテーションを探す要素 annotationType
- 検索するアノテーション型 containerAnnotationType
- アノテーションを保持するコンテナーの型。コンテナーがサポートされていない場合、または Java 8 以上で実行するときに @Repeatable
SE を介して検索する必要がある場合は、null
になる可能性があります。null
)getRepeatableAnnotations(AnnotatedElement, Class)
, getRepeatableAnnotations(AnnotatedElement, Class, Class)
, getDeclaredRepeatableAnnotations(AnnotatedElement, Class)
, AnnotatedElementUtils.getMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
, BridgeMethodResolver.findBridgedMethod(java.lang.reflect.Method)
, Repeatable
SE, AnnotatedElement.getDeclaredAnnotationsByType(java.lang.Class<T>)
SE@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
@Nullable public static <A extends AnnotationSE> A findAnnotation(MethodSE method, @Nullable ClassSE<A> annotationType)
Method
SE で annotationType
の単一の Annotation
SE を見つけ、アノテーションが特定のメソッド自体に直接存在しない場合は、そのスーパーメソッドを(つまり、スーパークラスとインターフェースから)トラバースします。 コンパイラーによって生成されたブリッジ Methods
SE を正しく処理します。
メソッドにアノテーションが直接存在しない場合は、メタアノテーションが検索されます。
メソッドのアノテーションはデフォルトでは継承されないため、これを明示的に処理する必要があります。
method
- アノテーションを探すメソッド annotationType
- 検索するアノテーション型 null
getAnnotation(Method, Class)
@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
@Nullable public static ClassSE<?> findAnnotationDeclaringClass(ClassSE<? extends AnnotationSE> annotationType, @Nullable ClassSE<?> clazz)
annotationType
のアノテーションが直接存在する指定された clazz
(指定された clazz
自体を含む)の継承階層の最初の Class
SE を見つけます。 提供された clazz
がインターフェースの場合、インターフェース自体のみがチェックされます。インターフェースの継承階層はトラバースされません。
メタアノテーションは検索されません。
標準の Class
SE API は、継承階層のどのクラスが実際に Annotation
SE を宣言するかを決定するメカニズムを提供しないため、これを明示的に処理する必要があります。
annotationType
- 検索するアノテーション型 clazz
- アノテーションを確認するクラス (null
の場合があります)annotationType
または見つからない場合は null
のアノテーションを宣言する継承階層の最初の Class
SEClass.isAnnotationPresent(Class)
SE, Class.getDeclaredAnnotations()
SE, findAnnotationDeclaringClassForTypes(List, Class)
, isAnnotationDeclaredLocally(Class, Class)
@Nullable public static ClassSE<?> findAnnotationDeclaringClassForTypes(ListSE<ClassSE<? extends AnnotationSE>> annotationTypes, @Nullable ClassSE<?> clazz)
annotationTypes
の少なくとも 1 つが直接存在する指定された clazz
(指定された clazz
自体を含む)の継承階層の最初の Class
SE を見つけます。 提供された clazz
がインターフェースの場合、インターフェース自体のみがチェックされます。インターフェースの継承階層はトラバースされません。
メタアノテーションは検索されません。
標準の Class
SE API は、継承階層内のどのクラスが実際にいくつかの候補アノテーションSEの 1 つを宣言するかを決定するメカニズムを提供しないため、これを明示的に処理する必要があります。
annotationTypes
- 検索するアノテーション型 clazz
- アノテーションを確認するクラス (null
の場合があります)annotationTypes
または見つからない場合は null
の少なくとも 1 つのアノテーションを宣言する継承階層の最初の Class
SEClass.isAnnotationPresent(Class)
SE, Class.getDeclaredAnnotations()
SE, findAnnotationDeclaringClass(Class, Class)
, isAnnotationDeclaredLocally(Class, Class)
public static boolean isAnnotationDeclaredLocally(ClassSE<? extends AnnotationSE> annotationType, ClassSE<?> clazz)
annotationType
のアノテーションが、指定された clazz
でローカルに宣言されている(つまり、直接存在している)かどうかを判断します。 提供される Class
SE は任意の型を表すことができます。
メタアノテーションは検索されません。
メモ: このメソッドは、アノテーションが継承SEされているかどうかを判別しません。継承されたアノテーションをより明確にするために、代わりに isAnnotationInherited(Class, Class)
の使用を検討してください。
annotationType
- 検索するアノテーション型 clazz
- アノテーションを確認するクラス true
(指定された annotationType
のアノテーションが直接存在する場合)Class.getDeclaredAnnotations()
SE, Class.getDeclaredAnnotation(Class)
SE, isAnnotationInherited(Class, Class)
public static boolean isAnnotationInherited(ClassSE<? extends AnnotationSE> annotationType, ClassSE<?> clazz)
annotationType
のアノテーションが、提供された clazz
に存在し、継承されているSE(つまり、直接存在していない)かどうかを判別します。メタアノテーションは検索されません。
提供された clazz
がインターフェースの場合、インターフェース自体のみがチェックされます。Java の標準的なメタアノテーションセマンティクスに従って、インターフェースの継承階層はトラバースされません。アノテーションの継承の詳細については、@Inherited
メタアノテーションの javadocSE を参照してください。
annotationType
- 検索するアノテーション型 clazz
- アノテーションを確認するクラス true
(指定された annotationType
のアノテーションが存在し、継承されている場合)Class.isAnnotationPresent(Class)
SE, isAnnotationDeclaredLocally(Class, Class)
public static boolean isAnnotationMetaPresent(ClassSE<? extends AnnotationSE> annotationType, @Nullable ClassSE<? extends AnnotationSE> metaAnnotationType)
metaAnnotationType
のアノテーションが、提供された annotationType
にメタ存在するかどうかを判別します。annotationType
- 検索するアノテーション型 metaAnnotationType
- 検索するメタアノテーションの型 true
(そのようなアノテーションがメタ表示の場合)public static boolean isInJavaLangAnnotationPackage(@Nullable AnnotationSE annotation)
Annotation
SE がコア JDK java.lang.annotation
パッケージで定義されているかどうかを確認します。annotation
- チェックするアノテーション java.lang.annotation
パッケージにある場合は true
public static boolean isInJavaLangAnnotationPackage(@Nullable StringSE annotationType)
Annotation
SE がコア JDK java.lang.annotation
パッケージで定義されているかどうかを確認します。annotationType
- チェックするアノテーション型の名前 java.lang.annotation
パッケージにある場合は true
public static void validateAnnotation(AnnotationSE annotation)
Class.getAnnotations() failure
ではなく) Class
値に対する TypeNotPresentExceptionProxy
の遅れた到着をカバーします。 このメソッドが失敗しないことは、getAnnotationAttributes(Annotation)
も失敗しないことを示しています(後で試行した場合)。
annotation
- 検証するアノテーション IllegalStateExceptionSE
- 宣言された Class
属性を読み取ることができなかった場合 Class.getAnnotations()
SE, getAnnotationAttributes(Annotation)
public static MapSE<StringSE,ObjectSE> getAnnotationAttributes(AnnotationSE annotation)
Map
SE として取得し、すべての属性型を保持します。classValuesAsString
および nestedAnnotationsAsMap
パラメーターを false
に設定して getAnnotationAttributes(Annotation, boolean, boolean)
を呼び出すのと同じです。
メモ: このメソッドは、実際に AnnotationAttributes
インスタンスを返します。ただし、Map
署名はバイナリ互換性のために保存されています。
annotation
- 属性を取得するためのアノテーション null
)getAnnotationAttributes(AnnotatedElement, Annotation)
, getAnnotationAttributes(Annotation, boolean, boolean)
, getAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean)
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(Annotation, boolean, boolean)
public static AnnotationAttributes getAnnotationAttributes(AnnotationSE annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
AnnotationAttributes
マップとして取得します。 このメソッドは、リフレクションベースの StandardAnnotationMetadata
と同等の完全に再帰的なアノテーション読み取り機能を提供します。
annotation
- 属性を取得するためのアノテーション classValuesAsString
- クラス参照を文字列に変換するか(AnnotationMetadata
との互換性のため)、クラス参照として保持するか nestedAnnotationsAsMap
- ネストされたアノテーションを AnnotationAttributes
マップに変換するか(AnnotationMetadata
との互換性のため)、Annotation
インスタンスとして保持するか null
)public static AnnotationAttributes getAnnotationAttributes(@Nullable AnnotatedElementSE annotatedElement, AnnotationSE annotation)
AnnotationAttributes
マップとして取得します。classValuesAsString
および nestedAnnotationsAsMap
パラメーターを false
に設定して getAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean)
を呼び出すのと同じです。
annotatedElement
- 指定されたアノテーションでアノテーションが付けられた要素。不明な場合は null
の可能性があります annotation
- 属性を取得するためのアノテーション null
)getAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean)
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
)public static void registerDefaultValues(AnnotationAttributes attributes)
attributes
- 処理するアノテーション属性 public static void postProcessAnnotationAttributes(@Nullable ObjectSE annotatedElement, AnnotationAttributes attributes, boolean classValuesAsString)
AnnotationAttributes
を後処理し、ネストされたアノテーションを Annotation
インスタンスとして保持します。 具体的には、このメソッドは、@AliasFor
でアノテーションが付けられたアノテーション属性に属性エイリアスセマンティクスを適用し、デフォルト値のプレースホルダーを元のデフォルト値に置き換えます。
annotatedElement
- 指定された属性の作成元であるアノテーションまたはアノテーション階層でアノテーションが付けられた要素。不明な場合は null
の可能性があります attributes
- 後処理するアノテーション属性 classValuesAsString
- クラス参照を文字列に変換するか(AnnotationMetadata
との互換性のため)、クラス参照として保持するか postProcessAnnotationAttributes(Object, AnnotationAttributes, boolean, boolean)
, getDefaultValue(Class, String)
@Nullable public static ObjectSE getValue(AnnotationSE annotation)
value
属性の値を取得します。annotation
- 値を取得するアノテーションインスタンス AnnotationConfigurationException
が原因で属性値を取得できない場合を除き、見つからない場合は null
。この場合、そのような例外が再スローされます。getValue(Annotation, String)
@Nullable public static ObjectSE getValue(@Nullable AnnotationSE annotation, @Nullable StringSE attributeName)
annotation
- 値を取得するアノテーションインスタンス attributeName
- 取得する属性値の名前 AnnotationConfigurationException
が原因で属性値を取得できない場合を除き、見つからない場合は null
。この場合、そのような例外が再スローされます。getValue(Annotation)
, rethrowAnnotationConfigurationException(Throwable)
@Nullable public static ObjectSE getDefaultValue(AnnotationSE annotation)
value
属性のデフォルト値を取得します。annotation
- デフォルト値を取得するアノテーションインスタンス null
getDefaultValue(Annotation, String)
@Nullable public static ObjectSE getDefaultValue(@Nullable AnnotationSE annotation, @Nullable StringSE attributeName)
annotation
- デフォルト値を取得するアノテーションインスタンス attributeName
- 取得する属性値の名前 null
getDefaultValue(Class, String)
@Nullable public static ObjectSE getDefaultValue(ClassSE<? extends AnnotationSE> annotationType)
annotation type
SE を指定して、単一要素のアノテーションの value
属性のデフォルト値を取得します。annotationType
- デフォルト値を取得する必要があるアノテーション型 null
getDefaultValue(Class, String)
@Nullable public static ObjectSE getDefaultValue(@Nullable ClassSE<? extends AnnotationSE> annotationType, @Nullable StringSE attributeName)
annotation type
SE を指定して、名前付き属性のデフォルト値を取得します。annotationType
- デフォルト値を取得する必要があるアノテーション型 attributeName
- 取得する属性値の名前。null
getDefaultValue(Annotation, String)
public static <A extends AnnotationSE> A synthesizeAnnotation(A annotation, @Nullable AnnotatedElementSE annotatedElement)
@AliasFor
でアノテーションが付けられたアノテーション属性の属性別名セマンティクスを透過的に実施する動的プロキシにラップすることにより、提供された annotation
からアノテーションを合成します。annotation
- 合成するアノテーション annotatedElement
- 指定されたアノテーションでアノテーションが付けられた要素。不明な場合は null
の可能性があります null
の場合は null
。それ以外の場合、指定されたアノテーションは変更されません AnnotationConfigurationException
- @AliasFor
の無効な構成が検出された場合 synthesizeAnnotation(Map, Class, AnnotatedElement)
, synthesizeAnnotation(Class)
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
の無効な構成が検出された場合 synthesizeAnnotation(Annotation, AnnotatedElement)
, synthesizeAnnotation(Class)
, getAnnotationAttributes(AnnotatedElement, Annotation)
, getAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean)
public static <A extends AnnotationSE> A synthesizeAnnotation(ClassSE<A> annotationType)
このメソッドは単に synthesizeAnnotation(Map, Class, AnnotatedElement)
に委譲し、ソース属性値には空のマップを、AnnotatedElement
SE には null
を提供します。
annotationType
- 合成するアノテーションの型 IllegalArgumentExceptionSE
- 必要な属性がない場合 AnnotationConfigurationException
- @AliasFor
の無効な構成が検出された場合 synthesizeAnnotation(Map, Class, AnnotatedElement)
, synthesizeAnnotation(Annotation, AnnotatedElement)
public static void clearCache()