public interface MergedAnnotations extends IterableSE<MergedAnnotation<AnnotationSE>>
Class
SE や Method
SE などのソースから取得した、マージされたアノテーションのコレクションへのアクセスを提供します。マージされた各アノテーションは、さまざまなソース値から属性値を「マージ」できるビューを表します。通常は次のとおりです。
@AliasFor
宣言 @AliasFor
宣言 例: @PostMapping
アノテーションは次のように定義されます:
@Retention(RetentionPolicy.RUNTIME) @RequestMapping(method = RequestMethod.POST) public @interface PostMapping { @AliasFor(attribute = "path") String[] value() default {}; @AliasFor(attribute = "value") String[] path() default {}; }
メソッドに @PostMapping("/home")
でアノテーションが付けられている場合、そのメソッドには @PostMapping
とメタアノテーション @RequestMapping
の両方のマージされたアノテーションが含まれます。@RequestMapping
アノテーションのマージされたビューには、次の属性が含まれます。
名前 | 値 | ソース |
---|---|---|
value | "/home" | @PostMapping で宣言 |
path | "/home" | 明示的な @AliasFor |
メソッド | RequestMethod.POST | メタアノテーションで宣言 |
MergedAnnotations
は、任意の Java AnnotatedElement
SE から取得できます。また、リフレクションを使用しないソース(バイトコードを直接解析するソースなど)にも使用できます。
さまざまな検索戦略を使用して、集約するアノテーションを含む関連するソース要素を見つけることができます。例: MergedAnnotations.SearchStrategy.TYPE_HIERARCHY
は、スーパークラスと実装されたインターフェースの両方を検索します。
MergedAnnotations
インスタンスから、単一のアノテーションを取得するか、すべてのアノテーションをストリーミングするか、特定の型に一致するアノテーションのみをストリーミングすることができます。アノテーションが存在するかどうかをすばやく確認することもできます。
ここにいくつかの典型的な例があります:
// is an annotation present or meta-present? mergedAnnotations.isPresent(ExampleAnnotation.class); // get the merged "value" attribute of ExampleAnnotation (either directly or // meta-present) mergedAnnotations.get(ExampleAnnotation.class).getString("value"); // get all meta-annotations but no directly present annotations mergedAnnotations.stream().filter(MergedAnnotation::isMetaPresent); // get all ExampleAnnotation declarations (including any meta-annotations) and // print the merged "value" attributes mergedAnnotations.stream(ExampleAnnotation.class) .map(mergedAnnotation -> mergedAnnotation.getString("value")) .forEach(System.out::println);
注: MergedAnnotations
API とその基礎となるモデルは、Spring の共通コンポーネントモデルの構成可能なアノテーション用に設計されており、属性のエイリアスとメタアノテーションの関連に重点が置かれています。この API でプレーン Java アノテーションを取得するためのサポートはありません。簡単なアノテーション検索のために、標準の Java リフレクションまたは Spring の AnnotationUtils
を使用してください。
MergedAnnotation
, MergedAnnotationCollectors
, MergedAnnotationPredicates
, MergedAnnotationSelectors
修飾子と型 | インターフェースと説明 |
---|---|
static class | MergedAnnotations.SearchStrategy from(AnnotatedElement, SearchStrategy) でサポートされている検索戦略。 |
修飾子と型 | メソッドと説明 |
---|---|
static MergedAnnotations | from(AnnotatedElementSE element) 指定された要素からのすべてのアノテーションとメタアノテーションを含む新しい MergedAnnotations インスタンスを作成します。 |
static MergedAnnotations | from(AnnotatedElementSE element, MergedAnnotations.SearchStrategy searchStrategy) 指定された要素からのすべてのアノテーションとメタアノテーション、および MergedAnnotations.SearchStrategy に応じて、関連する継承された要素を含む新しい MergedAnnotations インスタンスを作成します。 |
static MergedAnnotations | from(AnnotatedElementSE element, MergedAnnotations.SearchStrategy searchStrategy, RepeatableContainers repeatableContainers) 指定された要素からのすべてのアノテーションとメタアノテーション、および MergedAnnotations.SearchStrategy に応じて、関連する継承された要素を含む新しい MergedAnnotations インスタンスを作成します。 |
static MergedAnnotations | from(AnnotatedElementSE element, MergedAnnotations.SearchStrategy searchStrategy, RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter) 指定された要素からのすべてのアノテーションとメタアノテーション、および MergedAnnotations.SearchStrategy に応じて、関連する継承された要素を含む新しい MergedAnnotations インスタンスを作成します。 |
static MergedAnnotations | from(AnnotationSE... annotations) 指定されたアノテーションから新しい MergedAnnotations インスタンスを作成します。 |
static MergedAnnotations | from(ObjectSE source, AnnotationSE... annotations) 指定されたアノテーションから新しい MergedAnnotations インスタンスを作成します。 |
static MergedAnnotations | from(ObjectSE source, AnnotationSE[] annotations, RepeatableContainers repeatableContainers) 指定されたアノテーションから新しい MergedAnnotations インスタンスを作成します。 |
static MergedAnnotations | from(ObjectSE source, AnnotationSE[] annotations, RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter) 指定されたアノテーションから新しい MergedAnnotations インスタンスを作成します。 |
<A extends AnnotationSE> | get(ClassSE<A> annotationType) 指定された型の最も近い一致するアノテーションまたはメタアノテーションを取得します。存在しない場合は MergedAnnotation.missing() を取得します。 |
<A extends AnnotationSE> | get(ClassSE<A> annotationType, PredicateSE<? super MergedAnnotation<A>> predicate) 指定された型の最も近い一致するアノテーションまたはメタアノテーションを取得します。存在しない場合は MergedAnnotation.missing() を取得します。 |
<A extends AnnotationSE> | get(ClassSE<A> annotationType, PredicateSE<? super MergedAnnotation<A>> predicate, MergedAnnotationSelector<A> selector) 指定した型の一致するアノテーションまたはメタアノテーションを取得します。存在しない場合は MergedAnnotation.missing() を取得します。 |
<A extends AnnotationSE> | get(StringSE annotationType) 指定された型の最も近い一致するアノテーションまたはメタアノテーションを取得します。存在しない場合は MergedAnnotation.missing() を取得します。 |
<A extends AnnotationSE> | get(StringSE annotationType, PredicateSE<? super MergedAnnotation<A>> predicate) 指定された型の最も近い一致するアノテーションまたはメタアノテーションを取得します。存在しない場合は MergedAnnotation.missing() を取得します。 |
<A extends AnnotationSE> | get(StringSE annotationType, PredicateSE<? super MergedAnnotation<A>> predicate, MergedAnnotationSelector<A> selector) 指定した型の一致するアノテーションまたはメタアノテーションを取得します。存在しない場合は MergedAnnotation.missing() を取得します。 |
<A extends AnnotationSE> | isDirectlyPresent(ClassSE<A> annotationType) 指定されたアノテーションが直接存在するかどうかを確認します。 |
boolean | isDirectlyPresent(StringSE annotationType) 指定されたアノテーションが直接存在するかどうかを確認します。 |
<A extends AnnotationSE> | isPresent(ClassSE<A> annotationType) 指定されたアノテーションが直接存在するかメタ存在するかを判別します。 |
boolean | isPresent(StringSE annotationType) 指定されたアノテーションが直接存在するかメタ存在するかを判別します。 |
static MergedAnnotations | of(CollectionSE<MergedAnnotation<?>> annotations) 直接存在するアノテーションの指定されたコレクションから新しい MergedAnnotations インスタンスを作成します。 |
StreamSE<MergedAnnotation<AnnotationSE>> | stream() このコレクションに含まれるすべてのアノテーションとメタアノテーションをストリーミングします。 |
<A extends AnnotationSE> | stream(ClassSE<A> annotationType) 指定した型に一致するすべてのアノテーションとメタアノテーションをストリーミングします。 |
<A extends AnnotationSE> | stream(StringSE annotationType) 指定した型に一致するすべてのアノテーションとメタアノテーションをストリーミングします。 |
forEachSE, iteratorSE, spliteratorSE
<A extends AnnotationSE> boolean isPresent(ClassSE<A> annotationType)
get(annotationType).isPresent()
を呼び出すのと同じです。
annotationType
- チェックするアノテーション型 true
boolean isPresent(StringSE annotationType)
get(annotationType).isPresent()
を呼び出すのと同じです。
annotationType
- チェックするアノテーション型の完全修飾クラス名 true
<A extends AnnotationSE> boolean isDirectlyPresent(ClassSE<A> annotationType)
get(annotationType).isDirectlyPresent()
を呼び出すのと同じです。
annotationType
- チェックするアノテーション型 true
boolean isDirectlyPresent(StringSE annotationType)
get(annotationType).isDirectlyPresent()
を呼び出すのと同じです。
annotationType
- チェックするアノテーション型の完全修飾クラス名 true
<A extends AnnotationSE> MergedAnnotation<A> get(ClassSE<A> annotationType)
MergedAnnotation.missing()
を取得します。annotationType
- 取得するアノテーション型 MergedAnnotation
インスタンス <A extends AnnotationSE> MergedAnnotation<A> get(ClassSE<A> annotationType, @Nullable PredicateSE<? super MergedAnnotation<A>> predicate)
MergedAnnotation.missing()
を取得します。annotationType
- 取得するアノテーション型 predicate
- 一致する必要がある述語、または型の一致のみが必要な場合は null
MergedAnnotation
インスタンス MergedAnnotationPredicates
<A extends AnnotationSE> MergedAnnotation<A> get(ClassSE<A> annotationType, @Nullable PredicateSE<? super MergedAnnotation<A>> predicate, @Nullable MergedAnnotationSelector<A> selector)
MergedAnnotation.missing()
を取得します。annotationType
- 取得するアノテーション型 predicate
- 一致する必要がある述語、または型の一致のみが必要な場合は null
selector
- 集約内で最も適切なアノテーションを選択するために使用されるセレクタ、または最も近いものを選択するために null
MergedAnnotation
インスタンス MergedAnnotationPredicates
, MergedAnnotationSelectors
<A extends AnnotationSE> MergedAnnotation<A> get(StringSE annotationType)
MergedAnnotation.missing()
を取得します。annotationType
- 取得するアノテーション型の完全修飾クラス名 MergedAnnotation
インスタンス <A extends AnnotationSE> MergedAnnotation<A> get(StringSE annotationType, @Nullable PredicateSE<? super MergedAnnotation<A>> predicate)
MergedAnnotation.missing()
を取得します。annotationType
- 取得するアノテーション型の完全修飾クラス名 predicate
- 一致する必要がある述語、または型の一致のみが必要な場合は null
MergedAnnotation
インスタンス MergedAnnotationPredicates
<A extends AnnotationSE> MergedAnnotation<A> get(StringSE annotationType, @Nullable PredicateSE<? super MergedAnnotation<A>> predicate, @Nullable MergedAnnotationSelector<A> selector)
MergedAnnotation.missing()
を取得します。annotationType
- 取得するアノテーション型の完全修飾クラス名 predicate
- 一致する必要がある述語、または型の一致のみが必要な場合は null
selector
- 集約内で最も適切なアノテーションを選択するために使用されるセレクタ、または最も近いものを選択するために null
MergedAnnotation
インスタンス MergedAnnotationPredicates
, MergedAnnotationSelectors
<A extends AnnotationSE> StreamSE<MergedAnnotation<A>> stream(ClassSE<A> annotationType)
stream()
と同じ順序規則に従います。annotationType
- 一致するアノテーション型 <A extends AnnotationSE> StreamSE<MergedAnnotation<A>> stream(StringSE annotationType)
stream()
と同じ順序規則に従います。annotationType
- 一致するアノテーション型の完全修飾クラス名 StreamSE<MergedAnnotation<AnnotationSE>> stream()
static MergedAnnotations from(AnnotatedElementSE element)
MergedAnnotations
インスタンスを作成します。結果のインスタンスには、継承されたアノテーションは含まれません。これらも含める場合は、適切な MergedAnnotations.SearchStrategy
とともに from(AnnotatedElement, SearchStrategy)
を使用する必要があります。element
- ソース要素 MergedAnnotations
インスタンス static MergedAnnotations from(AnnotatedElementSE element, MergedAnnotations.SearchStrategy searchStrategy)
MergedAnnotations.SearchStrategy
に応じて、関連する継承された要素を含む新しい MergedAnnotations
インスタンスを作成します。element
- ソース要素 searchStrategy
- 使用する検索戦略 MergedAnnotations
インスタンス static MergedAnnotations from(AnnotatedElementSE element, MergedAnnotations.SearchStrategy searchStrategy, RepeatableContainers repeatableContainers)
MergedAnnotations.SearchStrategy
に応じて、関連する継承された要素を含む新しい MergedAnnotations
インスタンスを作成します。element
- ソース要素 searchStrategy
- 使用する検索戦略 repeatableContainers
- 要素アノテーションまたはメタアノテーションで使用できる繰り返し可能なコンテナー MergedAnnotations
インスタンス static MergedAnnotations from(AnnotatedElementSE element, MergedAnnotations.SearchStrategy searchStrategy, RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter)
MergedAnnotations.SearchStrategy
に応じて、関連する継承された要素を含む新しい MergedAnnotations
インスタンスを作成します。element
- ソース要素 searchStrategy
- 使用する検索戦略 repeatableContainers
- 要素アノテーションまたはメタアノテーションで使用できる繰り返し可能なコンテナー annotationFilter
- 考慮されるアノテーションを制限するために使用されるアノテーションフィルター MergedAnnotations
インスタンス static MergedAnnotations from(AnnotationSE... annotations)
MergedAnnotations
インスタンスを作成します。annotations
- 含めるアノテーション MergedAnnotations
インスタンス from(Object, Annotation...)
static MergedAnnotations from(ObjectSE source, AnnotationSE... annotations)
MergedAnnotations
インスタンスを作成します。source
- アノテーションのソース。このソースは、情報とロギングのためにのみ使用されます。指定されたアノテーションを実際に含む必要はなく、検索されません。annotations
- 含めるアノテーション MergedAnnotations
インスタンス from(Annotation...)
, from(AnnotatedElement)
static MergedAnnotations from(ObjectSE source, AnnotationSE[] annotations, RepeatableContainers repeatableContainers)
MergedAnnotations
インスタンスを作成します。source
- アノテーションのソース。このソースは、情報とロギングのためにのみ使用されます。指定されたアノテーションを実際に含む必要はなく、検索されません。annotations
- 含めるアノテーション repeatableContainers
- メタアノテーションで使用できる繰り返し可能なコンテナー MergedAnnotations
インスタンス static MergedAnnotations from(ObjectSE source, AnnotationSE[] annotations, RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter)
MergedAnnotations
インスタンスを作成します。source
- アノテーションのソース。このソースは、情報とロギングのためにのみ使用されます。指定されたアノテーションを実際に含む必要はなく、検索されません。annotations
- 含めるアノテーション repeatableContainers
- メタアノテーションで使用できる繰り返し可能なコンテナー annotationFilter
- 考慮されるアノテーションを制限するために使用されるアノテーションフィルター MergedAnnotations
インスタンス static MergedAnnotations of(CollectionSE<MergedAnnotation<?>> annotations)
MergedAnnotations
インスタンスを作成します。このメソッドを使用すると、リフレクションを使用して必ずしもロードされないアノテーションから MergedAnnotations
インスタンスを作成できます。提供されるアノテーションはすべて directly present
であり、aggregate index
が 0
である必要があります。 結果の MergedAnnotations
インスタンスには、指定されたアノテーションと、リフレクションを使用して読み取ることができるメタアノテーションの両方が含まれます。
annotations
- 含めるアノテーション MergedAnnotations
インスタンス MergedAnnotation.of(ClassLoader, Object, Class, java.util.Map)