Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that AnnotationSupport.isAnnotated() does not find repeatable annotations #4243

Merged
merged 6 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions documentation/src/docs/asciidoc/user-guide/extensions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,12 @@ order to align with the behavior of the JUnit Platform and JUnit Jupiter.
These include methods to check whether an element is annotated or meta-annotated with a
particular annotation, to search for specific annotations, and to find annotated methods
and fields in a class or interface. Some of these methods search on implemented
interfaces and within class hierarchies to find annotations. Consult the Javadoc for
`{AnnotationSupport}` for further details.
interfaces and within class hierarchies to find annotations.

NOTE: The `isAnnotated()` methods do not find repeatable annotations. To check for repeatable annotations,
use one of the `findRepeatableAnnotations()` methods and verify that the returned list is not empty.

Consult the Javadoc for `{AnnotationSupport}` for further details.
sbrannen marked this conversation as resolved.
Show resolved Hide resolved

NOTE: See also: <<extensions-supported-utilities-search-semantics>>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public interface AnnotatedElementContext {
* <em>present</em> or <em>meta-present</em> on the {@link AnnotatedElement} for
* this context.
*
* <p><strong>Note:</strong> This method does not find repeatable annotations.
* To check for repeatable annotations, use {@link #findRepeatableAnnotations(Class)}
* and verify that the returned list is not empty.
*
* <h4>WARNING</h4>
* <p>Favor the use of this method over directly invoking
* {@link AnnotatedElement#isAnnotationPresent(Class)} due to a bug in {@code javac}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,18 @@ private AnnotationSupport() {
* <em>present</em> or <em>meta-present</em> on the supplied optional
* {@code element}.
*
* <p><strong>Note:</strong> This method does not find repeatable annotations.
* To check for repeatable annotations, use {@link #findRepeatableAnnotations(Optional, Class)}
* and verify that the returned list is not empty.
*
* @param element an {@link Optional} containing the element on which to
* search for the annotation; may be {@code null} or <em>empty</em>
* @param annotationType the annotation type to search for; never {@code null}
* @return {@code true} if the annotation is present or meta-present
* @since 1.3
* @see #isAnnotated(AnnotatedElement, Class)
* @see #findAnnotation(Optional, Class)
* @see #findRepeatableAnnotations(Optional, Class)
*/
@API(status = MAINTAINED, since = "1.3")
public static boolean isAnnotated(Optional<? extends AnnotatedElement> element,
Expand All @@ -74,12 +79,17 @@ public static boolean isAnnotated(Optional<? extends AnnotatedElement> element,
* <em>present</em> or <em>meta-present</em> on the supplied
* {@code element}.
*
* <p><strong>Note:</strong> This method does not find repeatable annotations.
* To check for repeatable annotations, use {@link #findRepeatableAnnotations(AnnotatedElement, Class)}
* and verify that the returned list is not empty.
*
* @param element the element on which to search for the annotation; may be
* {@code null}
* @param annotationType the annotation type to search for; never {@code null}
* @return {@code true} if the annotation is present or meta-present
* @see #isAnnotated(Optional, Class)
* @see #findAnnotation(AnnotatedElement, Class)
* @see #findRepeatableAnnotations(AnnotatedElement, Class)
*/
public static boolean isAnnotated(AnnotatedElement element, Class<? extends Annotation> annotationType) {
return AnnotationUtils.isAnnotated(element, annotationType);
Expand Down
Loading