package jakarta.enterprise.lang.model; import jakarta.enterprise.lang.model.declarations.DeclarationInfo; import jakarta.enterprise.lang.model.types.Type; import java.lang.annotation.Annotation; import java.util.Collection; import java.util.function.Predicate; /** * An annotation target is anything that can be annotated. * That is: * *
* Note that if more than one annotation of a {@linkplain java.lang.annotation.Repeatable repeatable} annotation type * is declared on an annotation target, only an implicitly declared container annotation is present * on the annotation target; the originally declared annotations are not. If exactly one annotation of a repeatable * annotation type is declared on an annotation target, that annotation is present. *
* Annotations are represented as {@link AnnotationInfo}, so that implementations of this interface are not required * to instantiate the annotation type. *
* Implementations of this interface are required to define the {@code equals} and {@code hashCode} methods. * Implementations of this interface are encouraged to define the {@code toString} method such that * it returns a text resembling the corresponding Java™ syntax. *
* There is no guarantee that any particular construct, represented by an implementation of this interface,
* will always be represented by the same object. That includes natural singletons such as the {@code java.lang.Object}
* class declaration, or the {@code void} pseudo-type. Instances should always be compared using {@code equals}.
*
* @since 4.0
*/
public interface AnnotationTarget {
/**
* Returns whether this annotation target is a {@linkplain DeclarationInfo declaration}.
*
* @return {@code true} if this is a declaration, {@code false} otherwise
*/
boolean isDeclaration();
/**
* Returns whether this annotation target is a {@linkplain Type type}.
*
* @return {@code true} if this is a type, {@code false} otherwise
*/
boolean isType();
/**
* Returns this annotation target as a {@linkplain DeclarationInfo declaration}.
*
* @return this declaration, never {@code null}
* @throws IllegalStateException if {@link #isDeclaration()} returns {@code false}
*/
DeclarationInfo asDeclaration();
/**
* Returns this annotation target as a {@linkplain Type type}.
*
* @return this type, never {@code null}
* @throws IllegalStateException if {@link #isType()} returns {@code false}
*/
Type asType();
/**
* Returns whether an annotation of given type is present on this annotation target.
*
* @param annotationType the annotation type, must not be {@code null}
* @return {@code true} if given annotation type is present on this annotation target, {@code false} otherwise
*/
boolean hasAnnotation(Class extends Annotation> annotationType);
/**
* Returns whether given predicate matches any annotation present on this annotation target.
*
* @param predicate annotation predicate, must not be {@code null}
* @return {@code true} if given predicate matches any annotation present on this annotation target, {@code false} otherwise.
*/
boolean hasAnnotation(Predicate
* For the purpose of this method, annotations in the {@code value} member of a container annotation,
* as defined using {@link java.lang.annotation.Repeatable @Repeatable}, are considered to be present
* on the annotation target on which the container annotation is present.
*
* @param annotationType the {@code @Repeatable} annotation type, must not be {@code null}
* @param