| 1 | /* |
| 2 | * Copyright 2015-2024 the original author or authors. |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v2.0 which |
| 6 | * accompanies this distribution and is available at |
| 7 | * |
| 8 | * https://www.eclipse.org/legal/epl-v20.html |
| 9 | */ |
| 10 | |
| 11 | package org.junit.jupiter.api; |
| 12 | |
| 13 | import static org.apiguardian.api.API.Status.STABLE; |
| 14 | |
| 15 | import java.lang.annotation.Annotation; |
| 16 | import java.lang.reflect.Method; |
| 17 | import java.util.List; |
| 18 | import java.util.Optional; |
| 19 | |
| 20 | import org.apiguardian.api.API; |
| 21 | |
| 22 | /** |
| 23 | * {@code MethodDescriptor} encapsulates functionality for a given {@link Method}. |
| 24 | * |
| 25 | * @since 5.4 |
| 26 | * @see MethodOrdererContext |
| 27 | */ |
| 28 | @API(status = STABLE, since = "5.7") |
| 29 | public interface MethodDescriptor { |
| 30 | |
| 31 | /** |
| 32 | * Get the method for this descriptor. |
| 33 | * |
| 34 | * @return the method; never {@code null} |
| 35 | */ |
| 36 | Method getMethod(); |
| 37 | |
| 38 | /** |
| 39 | * Get the display name for this descriptor's {@link #getMethod() method}. |
| 40 | * |
| 41 | * @return the display name for this descriptor's method; never {@code null} |
| 42 | * or blank |
| 43 | * @since 5.7 |
| 44 | */ |
| 45 | @API(status = STABLE, since = "5.10") |
| 46 | String getDisplayName(); |
| 47 | |
| 48 | /** |
| 49 | * Determine if an annotation of {@code annotationType} is either |
| 50 | * <em>present</em> or <em>meta-present</em> on the {@link Method} for |
| 51 | * this descriptor. |
| 52 | * |
| 53 | * @param annotationType the annotation type to search for; never {@code null} |
| 54 | * @return {@code true} if the annotation is present or meta-present |
| 55 | * @see #findAnnotation(Class) |
| 56 | * @see #findRepeatableAnnotations(Class) |
| 57 | */ |
| 58 | boolean isAnnotated(Class<? extends Annotation> annotationType); |
| 59 | |
| 60 | /** |
| 61 | * Find the first annotation of {@code annotationType} that is either |
| 62 | * <em>present</em> or <em>meta-present</em> on the {@link Method} for |
| 63 | * this descriptor. |
| 64 | * |
| 65 | * @param <A> the annotation type |
| 66 | * @param annotationType the annotation type to search for; never {@code null} |
| 67 | * @return an {@code Optional} containing the annotation; never {@code null} but |
| 68 | * potentially empty |
| 69 | * @see #isAnnotated(Class) |
| 70 | * @see #findRepeatableAnnotations(Class) |
| 71 | */ |
| 72 | <A extends Annotation> Optional<A> findAnnotation(Class<A> annotationType); |
| 73 | |
| 74 | /** |
| 75 | * Find all <em>repeatable</em> {@linkplain Annotation annotations} of |
| 76 | * {@code annotationType} that are either <em>present</em> or |
| 77 | * <em>meta-present</em> on the {@link Method} for this descriptor. |
| 78 | * |
| 79 | * @param <A> the annotation type |
| 80 | * @param annotationType the repeatable annotation type to search for; never |
| 81 | * {@code null} |
| 82 | * @return the list of all such annotations found; neither {@code null} nor |
| 83 | * mutable, but potentially empty |
| 84 | * @see #isAnnotated(Class) |
| 85 | * @see #findAnnotation(Class) |
| 86 | * @see java.lang.annotation.Repeatable |
| 87 | */ |
| 88 | <A extends Annotation> List<A> findRepeatableAnnotations(Class<A> annotationType); |
| 89 | |
| 90 | } |