/*
 * Copyright 2017-2020 original authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.micronaut.core.annotation;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import io.micronaut.core.naming.NameUtils;
import io.micronaut.core.reflect.ClassUtils;
import io.micronaut.core.reflect.ReflectionUtils;
import io.micronaut.core.type.Argument;
import io.micronaut.core.util.ArgumentUtils;
import io.micronaut.core.util.ArrayUtils;
import io.micronaut.core.util.StringUtils;
import io.micronaut.core.value.OptionalValues;

import java.lang.annotation.Annotation;
import java.lang.annotation.Repeatable;
import java.lang.reflect.Array;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

An interface implemented at compile time by Micronaut that allows the inspection of annotation metadata and stereotypes (meta-annotations)

.

This interface exposes fast and efficient means to expose annotation data at runtime without requiring reflective tricks to read the annotation metadata

Users of Micronaut should in general avoid the methods of the AnnotatedElement interface and use this interface instead to obtain maximum efficiency

Core framework types such as io.micronaut.inject.BeanDefinition and io.micronaut.inject.ExecutableMethod implement this interface

Author:Graeme Rocher
Since:1.0
/** * <p>An interface implemented at compile time by Micronaut that allows the inspection of annotation metadata and * stereotypes (meta-annotations)</p>. * <p> * <p>This interface exposes fast and efficient means to expose annotation data at runtime without requiring reflective * tricks to read the annotation metadata</p> * <p> * <p>Users of Micronaut should in general avoid the methods of the {@link java.lang.reflect.AnnotatedElement} * interface and use this interface instead to obtain maximum efficiency</p> * <p> * <p>Core framework types such as <tt>io.micronaut.inject.BeanDefinition</tt> and * <tt>io.micronaut.inject.ExecutableMethod</tt> implement this interface</p> * * @author Graeme Rocher * @since 1.0 */
public interface AnnotationMetadata extends AnnotationSource {
A constant for representing empty metadata.
/** * A constant for representing empty metadata. */
AnnotationMetadata EMPTY_METADATA = new EmptyAnnotationMetadata();
The default value() member.
/** * The default <tt>value()</tt> member. */
String VALUE_MEMBER = "value";
The suffix used when saving compiled metadata to classes.
/** * The suffix used when saving compiled metadata to classes. */
String CLASS_NAME_SUFFIX = "$$AnnotationMetadata";
Resolve all of the annotation names that feature the given stereotype.
Params:
  • stereotype – The annotation names
Returns:A set of annotation names
/** * Resolve all of the annotation names that feature the given stereotype. * * @param stereotype The annotation names * @return A set of annotation names */
default @NonNull List<String> getAnnotationNamesByStereotype(@Nullable String stereotype) { return Collections.emptyList(); }
All the annotation names this metadata declares.
Returns:All the annotation names this metadata declares
/** * All the annotation names this metadata declares. * * @return All the annotation names this metadata declares */
default @NonNull Set<String> getAnnotationNames() { return Collections.emptySet(); }
All the declared annotation names this metadata declares.
Returns:All the declared annotation names this metadata declares
/** * All the declared annotation names this metadata declares. * * @return All the declared annotation names this metadata declares */
default @NonNull Set<String> getDeclaredAnnotationNames() { return Collections.emptySet(); }
Resolve all of the annotations names for the given stereotype that are declared annotations.
Params:
  • stereotype – The stereotype
Returns:The declared annotations
/** * Resolve all of the annotations names for the given stereotype that are declared annotations. * * @param stereotype The stereotype * @return The declared annotations */
default @NonNull List<String> getDeclaredAnnotationNamesByStereotype(@Nullable String stereotype) { return Collections.emptyList(); }
Get all of the values for the given annotation and type of the underlying values.
Params:
  • annotation – The annotation name
  • valueType – valueType
Type parameters:
  • <T> – Generic type
Returns:The OptionalValues
/** * Get all of the values for the given annotation and type of the underlying values. * * @param annotation The annotation name * @param valueType valueType * @param <T> Generic type * @return The {@link OptionalValues} */
default @NonNull <T> OptionalValues<T> getValues(@NonNull String annotation, @NonNull Class<T> valueType) { return OptionalValues.empty(); }
Return the default value for the given annotation member.
Params:
  • annotation – The annotation
  • member – The member
  • requiredType – The required type
Type parameters:
  • <T> – The required generic type
Returns:An optional value
/** * Return the default value for the given annotation member. * * @param annotation The annotation * @param member The member * @param requiredType The required type * @param <T> The required generic type * @return An optional value */
default <T> Optional<T> getDefaultValue(@NonNull String annotation, @NonNull String member, @NonNull Argument<T> requiredType) { return Optional.empty(); }
Gets all the annotation values by the given repeatable type.
Params:
  • annotationType – The annotation type
Type parameters:
  • <T> – The annotation type
Returns:A list of values
/** * Gets all the annotation values by the given repeatable type. * * @param annotationType The annotation type * @param <T> The annotation type * @return A list of values */
default @NonNull <T extends Annotation> List<AnnotationValue<T>> getAnnotationValuesByType(@NonNull Class<T> annotationType) { return Collections.emptyList(); }
Gets only declared annotation values by the given repeatable type.
Params:
  • annotationType – The annotation type
Type parameters:
  • <T> – The annotation type
Returns:A list of values
/** * Gets only declared annotation values by the given repeatable type. * * @param annotationType The annotation type * @param <T> The annotation type * @return A list of values */
default @NonNull <T extends Annotation> List<AnnotationValue<T>> getDeclaredAnnotationValuesByType(@NonNull Class<T> annotationType) { return Collections.emptyList(); }
Checks whether this object has the given annotation directly declared on the object.
Params:
  • annotation – The annotation
Returns:True if the annotation is present
/** * Checks whether this object has the given annotation directly declared on the object. * * @param annotation The annotation * @return True if the annotation is present */
default boolean hasDeclaredAnnotation(@Nullable String annotation) { return false; }
Checks whether this object has the given annotation on the object itself or inherited from a parent.
Params:
  • annotation – The annotation
Returns:True if the annotation is present
/** * Checks whether this object has the given annotation on the object itself or inherited from a parent. * * @param annotation The annotation * @return True if the annotation is present */
default boolean hasAnnotation(@Nullable String annotation) { return false; }
Checks whether the given annotation simple name (name without the package) is present in the annotations.
Params:
  • annotation – The annotation
Returns:True if the annotation is present
/** * Checks whether the given annotation simple name (name without the package) is present in the annotations. * * @param annotation The annotation * @return True if the annotation is present */
default boolean hasSimpleAnnotation(@Nullable String annotation) { if (annotation == null) { return false; } return getAnnotationNames().stream().anyMatch(a -> NameUtils.getSimpleName(a).equalsIgnoreCase(annotation) ); }
Checks whether the given annotation simple name (name without the package) is present in the declared annotations.
Params:
  • annotation – The annotation
Returns:True if the annotation is present
/** * Checks whether the given annotation simple name (name without the package) is present in the declared annotations. * * @param annotation The annotation * @return True if the annotation is present */
default boolean hasSimpleDeclaredAnnotation(@Nullable String annotation) { if (annotation == null) { return false; } return getDeclaredAnnotationNames().stream().anyMatch(a -> NameUtils.getSimpleName(a).equalsIgnoreCase(annotation) ); }

Checks whether this object has the given annotation stereotype on the object itself or inherited from a parent

.

An annotation stereotype is a meta annotation potentially applied to another annotation

Params:
  • annotation – The annotation
Returns:True if the annotation is present
/** * <p>Checks whether this object has the given annotation stereotype on the object itself or inherited from a parent</p>. * <p> * <p>An annotation stereotype is a meta annotation potentially applied to another annotation</p> * * @param annotation The annotation * @return True if the annotation is present */
default boolean hasStereotype(@Nullable String annotation) { return false; }

Checks whether this object has the given annotation stereotype on the object itself and not inherited from a parent

.

An annotation stereotype is a meta annotation potentially applied to another annotation

Params:
  • annotation – The annotation
Returns:True if the annotation is present
/** * <p>Checks whether this object has the given annotation stereotype on the object itself and not inherited from a parent</p>. * <p> * <p>An annotation stereotype is a meta annotation potentially applied to another annotation</p> * * @param annotation The annotation * @return True if the annotation is present */
default boolean hasDeclaredStereotype(@Nullable String annotation) { return false; }
Return the default values for the given annotation name.
Params:
  • annotation – The annotation name
Returns:The default values
/** * Return the default values for the given annotation name. * @param annotation The annotation name * @return The default values */
default @NonNull Map<String, Object> getDefaultValues(@NonNull String annotation) { return Collections.emptyMap(); }
Return the default value for the given annotation member.
Params:
  • annotation – The annotation
  • member – The member
  • requiredType – The required type
Type parameters:
  • <T> – The required generic type
Returns:An optional value
/** * Return the default value for the given annotation member. * * @param annotation The annotation * @param member The member * @param requiredType The required type * @param <T> The required generic type * @return An optional value */
default <T> Optional<T> getDefaultValue(@NonNull String annotation, @NonNull String member, @NonNull Class<T> requiredType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); ArgumentUtils.requireNonNull("requiredType", requiredType); return getDefaultValue(annotation, member, Argument.of(requiredType)); }
Return the default value for the given annotation member.
Params:
  • annotation – The annotation
  • member – The member
  • requiredType – The required type
Type parameters:
  • <T> – The required generic type
Returns:An optional value
/** * Return the default value for the given annotation member. * * @param annotation The annotation * @param member The member * @param requiredType The required type * @param <T> The required generic type * @return An optional value */
default <T> Optional<T> getDefaultValue(@NonNull Class<? extends Annotation> annotation, @NonNull String member, @NonNull Argument<T> requiredType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); ArgumentUtils.requireNonNull("requiredType", requiredType); return getDefaultValue(annotation.getName(), member, requiredType); }
See Also:
  • isAnnotationPresent.isAnnotationPresent(Class)
/** * @see AnnotationSource#isAnnotationPresent(Class) */
@Override default boolean isAnnotationPresent(@NonNull Class<? extends Annotation> annotationClass) { //noinspection ConstantConditions if (annotationClass == null) { return false; } return hasAnnotation(annotationClass); }
See Also:
  • isAnnotationPresent.isAnnotationPresent(Class)
/** * @see AnnotationSource#isAnnotationPresent(Class) */
@Override default boolean isDeclaredAnnotationPresent(@NonNull Class<? extends Annotation> annotationClass) { //noinspection ConstantConditions if (annotationClass == null) { return false; } return hasDeclaredAnnotation(annotationClass); }
Return the default value for the given annotation member.
Params:
  • annotation – The annotation
  • member – The member
  • requiredType – The required type
Type parameters:
  • <T> – The required generic type
Returns:An optional value
/** * Return the default value for the given annotation member. * * @param annotation The annotation * @param member The member * @param requiredType The required type * @param <T> The required generic type * @return An optional value */
default <T> Optional<T> getDefaultValue(@NonNull Class<? extends Annotation> annotation, @NonNull String member, @NonNull Class<T> requiredType) { ArgumentUtils.requireNonNull("annotation", annotation); return getDefaultValue(annotation.getName(), member, requiredType); }
Get the value of the given annotation member.
Params:
  • annotation – The annotation class
  • member – The annotation member
  • requiredType – The required type
Type parameters:
  • <T> – The value
Returns:An Optional of the value
/** * Get the value of the given annotation member. * * @param annotation The annotation class * @param member The annotation member * @param requiredType The required type * @param <T> The value * @return An {@link Optional} of the value */
default <T> Optional<T> getValue(@NonNull Class<? extends Annotation> annotation, @NonNull String member, @NonNull Class<T> requiredType) { ArgumentUtils.requireNonNull("requiredType", requiredType); return getValue(annotation, member, Argument.of(requiredType)); }
Get the value of the given annotation member.
Params:
  • annotation – The annotation class
  • member – The annotation member
  • requiredType – The required type
Type parameters:
  • <T> – The value
Returns:An Optional of the value
/** * Get the value of the given annotation member. * * @param annotation The annotation class * @param member The annotation member * @param requiredType The required type * @param <T> The value * @return An {@link Optional} of the value */
default <T> Optional<T> getValue(@NonNull Class<? extends Annotation> annotation, @NonNull String member, @NonNull Argument<T> requiredType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); ArgumentUtils.requireNonNull("requiredType", requiredType); Repeatable repeatable = annotation.getAnnotation(Repeatable.class); if (repeatable != null) { List<? extends AnnotationValue<? extends Annotation>> values = getAnnotationValuesByType(annotation); if (!values.isEmpty()) { return values.iterator().next().get(member, requiredType); } else { return Optional.empty(); } } else { Optional<? extends AnnotationValue<? extends Annotation>> values = findAnnotation(annotation); Optional<T> value = values.flatMap(av -> av.get(member, requiredType)); if (!value.isPresent() && hasStereotype(annotation)) { return getDefaultValue(annotation, member, requiredType); } return value; } }
Find the first annotation name for the given stereotype.
Params:
  • stereotype – The stereotype
Returns:The annotation name
/** * Find the first annotation name for the given stereotype. * * @param stereotype The stereotype * @return The annotation name */
default Optional<String> getAnnotationNameByStereotype(@Nullable String stereotype) { return getAnnotationNamesByStereotype(stereotype).stream().findFirst(); }
Find the first annotation name for the given stereotype.
Params:
  • stereotype – The stereotype
Returns:The annotation name
/** * Find the first annotation name for the given stereotype. * * @param stereotype The stereotype * @return The annotation name */
default Optional<String> getDeclaredAnnotationNameByStereotype(@Nullable String stereotype) { return getDeclaredAnnotationNamesByStereotype(stereotype).stream().findFirst(); }
Find the first annotation name for the given stereotype.
Params:
  • stereotype – The stereotype
Returns:The annotation name
/** * Find the first annotation name for the given stereotype. * * @param stereotype The stereotype * @return The annotation name */
default Optional<Class<? extends Annotation>> getAnnotationTypeByStereotype(@NonNull Class<? extends Annotation> stereotype) { ArgumentUtils.requireNonNull("stereotype", stereotype); return getAnnotationTypeByStereotype(stereotype.getName()); }
Find the first declared annotation name for the given stereotype.
Params:
  • stereotype – The stereotype
Returns:The annotation name
/** * Find the first declared annotation name for the given stereotype. * * @param stereotype The stereotype * @return The annotation name */
default Optional<Class<? extends Annotation>> getDeclaredAnnotationTypeByStereotype(@NonNull Class<? extends Annotation> stereotype) { ArgumentUtils.requireNonNull("stereotype", stereotype); return getDeclaredAnnotationTypeByStereotype(stereotype.getName()); }
Find the first annotation name for the given stereotype.
Params:
  • stereotype – The stereotype
Returns:The annotation name
/** * Find the first annotation name for the given stereotype. * * @param stereotype The stereotype * @return The annotation name */
default Optional<Class<? extends Annotation>> getDeclaredAnnotationTypeByStereotype(@Nullable String stereotype) { return getDeclaredAnnotationNameByStereotype(stereotype).flatMap(this::getAnnotationType); }
Gets the type for a given annotation if it is present on the classpath. Subclasses can potentially override to provide optimized loading.
Params:
  • name – The type name
  • classLoader – The ClassLoader to load the type
Returns:The type if present
/** * Gets the type for a given annotation if it is present on the classpath. Subclasses can potentially override to provide optimized loading. * @param name The type name * @param classLoader The ClassLoader to load the type * @return The type if present */
default Optional<Class<? extends Annotation>> getAnnotationType(@NonNull String name, @NonNull ClassLoader classLoader) { ArgumentUtils.requireNonNull("name", name); final Optional<Class> aClass = ClassUtils.forName(name, classLoader); return aClass.flatMap((Function<Class, Optional<Class<? extends Annotation>>>) aClass1 -> { if (Annotation.class.isAssignableFrom(aClass1)) { //noinspection unchecked return Optional.of(aClass1); } return Optional.empty(); }); }
Gets the type for a given annotation if it is present on the classpath. Subclasses can potentially override to provide optimized loading.
Params:
  • name – The type name
Returns:The type if present
/** * Gets the type for a given annotation if it is present on the classpath. Subclasses can potentially override to provide optimized loading. * @param name The type name * @return The type if present */
default Optional<Class<? extends Annotation>> getAnnotationType(@NonNull String name) { return getAnnotationType(name, getClass().getClassLoader()); }
Find the first annotation name for the given stereotype.
Params:
  • stereotype – The stereotype
Returns:The annotation name
/** * Find the first annotation name for the given stereotype. * * @param stereotype The stereotype * @return The annotation name */
default Optional<Class<? extends Annotation>> getAnnotationTypeByStereotype(@Nullable String stereotype) { return getAnnotationNameByStereotype(stereotype).flatMap(this::getAnnotationType); }
Find the first annotation name for the given stereotype.
Params:
  • stereotype – The stereotype
Returns:The annotation name
/** * Find the first annotation name for the given stereotype. * * @param stereotype The stereotype * @return The annotation name */
default Optional<String> getAnnotationNameByStereotype(@NonNull Class<? extends Annotation> stereotype) { ArgumentUtils.requireNonNull("stereotype", stereotype); return getAnnotationNameByStereotype(stereotype.getName()); }
Get all of the values for the given annotation.
Params:
  • annotation – The annotation name
  • valueType – valueType
Type parameters:
  • <T> – Generic type
Returns:The OptionalValues
/** * Get all of the values for the given annotation. * * @param annotation The annotation name * @param valueType valueType * @param <T> Generic type * @return The {@link OptionalValues} */
default @NonNull <T> OptionalValues<T> getValues(@NonNull Class<? extends Annotation> annotation, @NonNull Class<T> valueType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("valueType", valueType); return getValues(annotation.getName(), valueType); }
Resolve all of the annotation names that feature the given stereotype.
Params:
  • stereotype – The annotation names
Returns:A set of annotation names
/** * Resolve all of the annotation names that feature the given stereotype. * * @param stereotype The annotation names * @return A set of annotation names */
default @NonNull List<String> getAnnotationNamesByStereotype(@NonNull Class<? extends Annotation> stereotype) { ArgumentUtils.requireNonNull("stereotype", stereotype); return getAnnotationNamesByStereotype(stereotype.getName()); }
Resolve all of the annotation names that feature the given stereotype.
Params:
  • stereotype – The annotation names
Returns:A set of annotation names
/** * Resolve all of the annotation names that feature the given stereotype. * * @param stereotype The annotation names * @return A set of annotation names */
default @NonNull List<Class<? extends Annotation>> getAnnotationTypesByStereotype(@NonNull Class<? extends Annotation> stereotype) { ArgumentUtils.requireNonNull("stereotype", stereotype); List<String> names = getAnnotationNamesByStereotype(stereotype.getName()); return names.stream().map(this::getAnnotationType) .filter(Optional::isPresent) .map(opt -> (Class<? extends Annotation>) opt.get()) .collect(Collectors.toList()); }
Resolve all of the annotation names that feature the given stereotype.
Params:
  • stereotype – The annotation names
  • classLoader – The classloader to load annotation type
Returns:A set of annotation names
/** * Resolve all of the annotation names that feature the given stereotype. * * @param stereotype The annotation names * @param classLoader The classloader to load annotation type * @return A set of annotation names */
default @NonNull List<Class<? extends Annotation>> getAnnotationTypesByStereotype(@NonNull Class<? extends Annotation> stereotype, @NonNull ClassLoader classLoader) { ArgumentUtils.requireNonNull("stereotype", stereotype); List<String> names = getAnnotationNamesByStereotype(stereotype.getName()); return names.stream().map(name -> getAnnotationType(name, classLoader)) .filter(Optional::isPresent) .map(opt -> (Class<? extends Annotation>) opt.get()) .collect(Collectors.toList()); }
Get all of the values for the given annotation.
Params:
  • annotationClass – The annotation name
Type parameters:
  • <T> – The annotation type
Returns:The AnnotationValue
/** * Get all of the values for the given annotation. * * @param annotationClass The annotation name * @param <T> The annotation type * @return The {@link AnnotationValue} */
@Override default <T extends Annotation> Optional<AnnotationValue<T>> findAnnotation(@NonNull Class<T> annotationClass) { ArgumentUtils.requireNonNull("annotationClass", annotationClass); Repeatable repeatable = annotationClass.getAnnotation(Repeatable.class); if (repeatable != null) { List<AnnotationValue<T>> values = getAnnotationValuesByType(annotationClass); if (!values.isEmpty()) { return Optional.of(values.iterator().next()); } else { return Optional.empty(); } } else { return this.findAnnotation(annotationClass.getName()); } }
{@inheritDoc}
/** * {@inheritDoc} */
@Override default <T extends Annotation> Optional<AnnotationValue<T>> findDeclaredAnnotation(@NonNull Class<T> annotationClass) { ArgumentUtils.requireNonNull("annotationClass", annotationClass); Repeatable repeatable = annotationClass.getAnnotation(Repeatable.class); if (repeatable != null) { List<AnnotationValue<T>> values = getDeclaredAnnotationValuesByType(annotationClass); if (!values.isEmpty()) { return Optional.of(values.iterator().next()); } else { return Optional.empty(); } } else { return this.findDeclaredAnnotation(annotationClass.getName()); } }
Get the value of the given annotation member.
Params:
  • annotation – The annotation class
  • member – The annotation member
  • requiredType – The required type
Type parameters:
  • <T> – The value
Returns:An Optional of the value
/** * Get the value of the given annotation member. * * @param annotation The annotation class * @param member The annotation member * @param requiredType The required type * @param <T> The value * @return An {@link Optional} of the value */
default <T> Optional<T> getValue(@NonNull String annotation, @NonNull String member, @NonNull Class<T> requiredType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); ArgumentUtils.requireNonNull("requiredType", requiredType); return getValue(annotation, member, Argument.of(requiredType)); }
Get the value of the given annotation member.
Params:
  • annotation – The annotation class
  • member – The annotation member
  • requiredType – The required type
Type parameters:
  • <T> – The value
Returns:An Optional of the value
/** * Get the value of the given annotation member. * * @param annotation The annotation class * @param member The annotation member * @param requiredType The required type * @param <T> The value * @return An {@link Optional} of the value */
default <T> Optional<T> getValue(@NonNull String annotation, @NonNull String member, @NonNull Argument<T> requiredType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); ArgumentUtils.requireNonNull("requiredType", requiredType); Optional<T> value = findAnnotation(annotation).flatMap(av -> av.get(member, requiredType)); if (!value.isPresent() && hasStereotype(annotation)) { return getDefaultValue(annotation, member, requiredType); } return value; }
The value as an OptionalLong for the given annotation and member.
Params:
  • annotation – The annotation
  • member – The member
Returns:THe OptionalLong value
/** * The value as an {@link OptionalLong} for the given annotation and member. * * @param annotation The annotation * @param member The member * @return THe {@link OptionalLong} value */
default OptionalLong longValue(@NonNull String annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); Optional<Long> result = getValue(annotation, member, Long.class); return result.map(OptionalLong::of).orElseGet(OptionalLong::empty); }
The value as an OptionalLong for the given annotation and member.
Params:
  • annotation – The annotation
  • member – The member
Returns:THe OptionalLong value
/** * The value as an {@link OptionalLong} for the given annotation and member. * * @param annotation The annotation * @param member The member * @return THe {@link OptionalLong} value */
default OptionalLong longValue(@NonNull Class<? extends Annotation> annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); return longValue(annotation.getName(), member); }
The value of the given enum.
Params:
  • annotation – The annotation
  • enumType – The enum type
Type parameters:
  • <E> – The enum type
Returns:An Optional enum value
/** * The value of the given enum. * * @param annotation The annotation * @param enumType The enum type * @param <E> The enum type * @return An {@link Optional} enum value */
default <E extends Enum> Optional<E> enumValue(@NonNull String annotation, Class<E> enumType) { ArgumentUtils.requireNonNull("annotation", annotation); return enumValue(annotation, VALUE_MEMBER, enumType); }
The value of the annotation as a Class.
Params:
  • annotation – The annotation
  • member – The annotation member
  • enumType – The enum type
Type parameters:
  • <E> – The enum type
Returns:An Optional class
/** * The value of the annotation as a Class. * * @param annotation The annotation * @param member The annotation member * @param enumType The enum type * @param <E> The enum type * @return An {@link Optional} class */
default <E extends Enum> Optional<E> enumValue(@NonNull String annotation, @NonNull String member, Class<E> enumType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return getValue(annotation, member, enumType); }
The value of the annotation as a Class.
Params:
  • annotation – The annotation
  • enumType – The enum type
Type parameters:
  • <E> – The enum type
Returns:An Optional class
/** * The value of the annotation as a Class. * * @param annotation The annotation * @param enumType The enum type * @param <E> The enum type * @return An {@link Optional} class */
default <E extends Enum> Optional<E> enumValue(@NonNull Class<? extends Annotation> annotation, Class<E> enumType) { ArgumentUtils.requireNonNull("annotation", annotation); return enumValue(annotation, VALUE_MEMBER, enumType); }
The value of the annotation as a Class.
Params:
  • annotation – The annotation
  • member – The annotation member
  • enumType – The enum type
Type parameters:
  • <E> – The enum type
Returns:An Optional class
/** * The value of the annotation as a Class. * * @param annotation The annotation * @param member The annotation member * @param enumType The enum type * @param <E> The enum type * @return An {@link Optional} class */
default <E extends Enum> Optional<E> enumValue(@NonNull Class<? extends Annotation> annotation, @NonNull String member, Class<E> enumType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return enumValue(annotation.getName(), member, enumType); }
The enum values for the given annotation.
Params:
  • annotation – The annotation
  • enumType – The enum type
Type parameters:
  • <E> – The enum type
Returns:An array of enum values
/** * The enum values for the given annotation. * * @param annotation The annotation * @param enumType The enum type * @param <E> The enum type * @return An array of enum values */
default <E extends Enum> E[] enumValues(@NonNull String annotation, Class<E> enumType) { ArgumentUtils.requireNonNull("annotation", annotation); return enumValues(annotation, VALUE_MEMBER, enumType); }
The enum values for the given annotation.
Params:
  • annotation – The annotation
  • member – The annotation member
  • enumType – The enum type
Type parameters:
  • <E> – The enum type
Returns:An array of enum values
/** * The enum values for the given annotation. * * @param annotation The annotation * @param member The annotation member * @param enumType The enum type * @param <E> The enum type * @return An array of enum values */
default <E extends Enum> E[] enumValues(@NonNull String annotation, @NonNull String member, Class<E> enumType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return (E[]) Array.newInstance(enumType, 0); }
The enum values for the given annotation.
Params:
  • annotation – The annotation
  • enumType – The enum type
Type parameters:
  • <E> – The enum type
Returns:An array of enum values
/** * The enum values for the given annotation. * * @param annotation The annotation * @param enumType The enum type * @param <E> The enum type * @return An array of enum values */
default <E extends Enum> E[] enumValues(@NonNull Class<? extends Annotation> annotation, Class<E> enumType) { ArgumentUtils.requireNonNull("annotation", annotation); return enumValues(annotation, VALUE_MEMBER, enumType); }
The enum values for the given annotation.
Params:
  • annotation – The annotation
  • member – The annotation member
  • enumType – The enum type
Type parameters:
  • <E> – The enum type
Returns:An array of enum values
/** * The enum values for the given annotation. * * @param annotation The annotation * @param member The annotation member * @param enumType The enum type * @param <E> The enum type * @return An array of enum values */
default <E extends Enum> E[] enumValues(@NonNull Class<? extends Annotation> annotation, @NonNull String member, Class<E> enumType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return enumValues(annotation.getName(), member, enumType); }
The value of the annotation as a Class.
Params:
  • annotation – The annotation
Type parameters:
  • <T> – The type of the class
Returns:An Optional class
/** * The value of the annotation as a Class. * * @param annotation The annotation * @return An {@link Optional} class * @param <T> The type of the class */
default @NonNull <T> Class<T>[] classValues(@NonNull String annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return classValues(annotation, VALUE_MEMBER); }
The value of the annotation as a Class.
Params:
  • annotation – The annotation
  • member – The annotation member
Type parameters:
  • <T> – The type of the class
Returns:An Optional class
/** * The value of the annotation as a Class. * * @param annotation The annotation * @param member The annotation member * @return An {@link Optional} class * @param <T> The type of the class */
default @NonNull <T> Class<T>[] classValues(@NonNull String annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return getValue(annotation, member, Class[].class).orElse(ReflectionUtils.EMPTY_CLASS_ARRAY); }
The value of the annotation as a Class.
Params:
  • annotation – The annotation
Type parameters:
  • <T> – The type of the class
Returns:An Optional class
/** * The value of the annotation as a Class. * * @param annotation The annotation * @return An {@link Optional} class * @param <T> The type of the class */
default @NonNull <T> Class<T>[] classValues(@NonNull Class<? extends Annotation> annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return classValues(annotation, VALUE_MEMBER); }
The value of the annotation as a Class.
Params:
  • annotation – The annotation
  • member – The annotation member
Type parameters:
  • <T> – The type of the class
Returns:An Optional class
/** * The value of the annotation as a Class. * * @param annotation The annotation * @param member The annotation member * @return An {@link Optional} class * @param <T> The type of the class */
default @NonNull <T> Class<T>[] classValues(@NonNull Class<? extends Annotation> annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return classValues(annotation.getName(), member); }
The value of the annotation as a Class.
Params:
  • annotation – The annotation
Returns:An Optional class
/** * The value of the annotation as a Class. * * @param annotation The annotation * @return An {@link Optional} class */
default Optional<Class> classValue(@NonNull String annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return classValue(annotation, VALUE_MEMBER); }
The value of the annotation as a Class.
Params:
  • annotation – The annotation
  • member – The annotation member
Returns:An Optional class
/** * The value of the annotation as a Class. * * @param annotation The annotation * @param member The annotation member * @return An {@link Optional} class */
default Optional<Class> classValue(@NonNull String annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return getValue(annotation, member, Class.class); }
The value of the annotation as a Class.
Params:
  • annotation – The annotation
Returns:An Optional class
/** * The value of the annotation as a Class. * * @param annotation The annotation * @return An {@link Optional} class */
default Optional<Class> classValue(@NonNull Class<? extends Annotation> annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return classValue(annotation, VALUE_MEMBER); }
The value of the annotation as a Class.
Params:
  • annotation – The annotation
  • member – The annotation member
Returns:An Optional class
/** * The value of the annotation as a Class. * * @param annotation The annotation * @param member The annotation member * @return An {@link Optional} class */
default Optional<Class> classValue(@NonNull Class<? extends Annotation> annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return classValue(annotation.getName(), member); }
The value as an OptionalInt for the given annotation and member.
Params:
  • annotation – The annotation
  • member – The member
Returns:THe OptionalInt value
/** * The value as an {@link OptionalInt} for the given annotation and member. * * @param annotation The annotation * @param member The member * @return THe {@link OptionalInt} value */
default OptionalInt intValue(@NonNull String annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); Optional<Integer> result = getValue(annotation, member, Integer.class); return result.map(OptionalInt::of).orElseGet(OptionalInt::empty); }
The value as an OptionalInt for the given annotation and member.
Params:
  • annotation – The annotation
  • member – The member
Returns:THe OptionalInt value
/** * The value as an {@link OptionalInt} for the given annotation and member. * * @param annotation The annotation * @param member The member * @return THe {@link OptionalInt} value */
default OptionalInt intValue(@NonNull Class<? extends Annotation> annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); return intValue(annotation.getName(), member); }
The value as an OptionalInt for the given annotation and member.
Params:
  • annotation – The annotation
Returns:THe OptionalInt value
/** * The value as an {@link OptionalInt} for the given annotation and member. * * @param annotation The annotation * @return THe {@link OptionalInt} value */
default OptionalInt intValue(@NonNull Class<? extends Annotation> annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return intValue(annotation, VALUE_MEMBER); }
The value as an optional string for the given annotation and member.
Params:
  • annotation – The annotation
  • member – The member
Returns:The string value if it is present
/** * The value as an optional string for the given annotation and member. * * @param annotation The annotation * @param member The member * @return The string value if it is present */
default Optional<String> stringValue(@NonNull String annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return getValue(annotation, member, String.class); }
The value as an optional string for the given annotation and member.
Params:
  • annotation – The annotation
  • member – The member
Returns:The string value if it is present
/** * The value as an optional string for the given annotation and member. * * @param annotation The annotation * @param member The member * @return The string value if it is present */
default Optional<String> stringValue(@NonNull Class<? extends Annotation> annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); return stringValue(annotation.getName(), member); }
The value as an optional string for the given annotation and member.
Params:
  • annotation – The annotation
Returns:The string value if it is present
/** * The value as an optional string for the given annotation and member. * * @param annotation The annotation * @return The string value if it is present */
default @NonNull Optional<String> stringValue(@NonNull Class<? extends Annotation> annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return stringValue(annotation, VALUE_MEMBER); }
The value as an optional string for the given annotation and member.
Params:
  • annotation – The annotation
Returns:The string value if it is present
/** * The value as an optional string for the given annotation and member. * * @param annotation The annotation * @return The string value if it is present */
default @NonNull Optional<String> stringValue(@NonNull String annotation) { return stringValue(annotation, VALUE_MEMBER); }
The value as an optional boolean for the given annotation and member.
Params:
  • annotation – The annotation
  • member – The member
Returns:The string value if it is present
/** * The value as an optional boolean for the given annotation and member. * * @param annotation The annotation * @param member The member * @return The string value if it is present */
default Optional<Boolean> booleanValue(@NonNull String annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return getValue(annotation, member, Boolean.class); }
The value as an optional boolean for the given annotation and member.
Params:
  • annotation – The annotation
  • member – The member
Returns:The string value if it is present
/** * The value as an optional boolean for the given annotation and member. * * @param annotation The annotation * @param member The member * @return The string value if it is present */
default Optional<Boolean> booleanValue(@NonNull Class<? extends Annotation> annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); return booleanValue(annotation.getName(), member); }
The value as an optional boolean for the given annotation and member.
Params:
  • annotation – The annotation
Returns:The string value if it is present
/** * The value as an optional boolean for the given annotation and member. * * @param annotation The annotation * @return The string value if it is present */
default @NonNull Optional<Boolean> booleanValue(@NonNull Class<? extends Annotation> annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return booleanValue(annotation, VALUE_MEMBER); }
The value as an optional boolean for the given annotation and member.
Params:
  • annotation – The annotation
Returns:The string value if it is present
/** * The value as an optional boolean for the given annotation and member. * * @param annotation The annotation * @return The string value if it is present */
default @NonNull Optional<Boolean> booleanValue(@NonNull String annotation) { return booleanValue(annotation, VALUE_MEMBER); }
The values as string array for the given annotation and member.
Params:
  • annotation – The annotation
  • member – The member
Returns:The string values if it is present
/** * The values as string array for the given annotation and member. * * @param annotation The annotation * @param member The member * @return The string values if it is present */
default @NonNull String[] stringValues(@NonNull Class<? extends Annotation> annotation, @NonNull String member) { return StringUtils.EMPTY_STRING_ARRAY; }
The values as string array for the given annotation and member.
Params:
  • annotation – The annotation
Returns:The string values if it is present
/** * The values as string array for the given annotation and member. * * @param annotation The annotation * @return The string values if it is present */
default @NonNull String[] stringValues(@NonNull Class<? extends Annotation> annotation) { return stringValues(annotation, VALUE_MEMBER); }
The value as an OptionalDouble for the given annotation and member.
Params:
  • annotation – The annotation
  • member – The member
Returns:THe OptionalDouble value
/** * The value as an {@link OptionalDouble} for the given annotation and member. * * @param annotation The annotation * @param member The member * @return THe {@link OptionalDouble} value */
default @NonNull OptionalDouble doubleValue(@NonNull String annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); Optional<Double> result = getValue(annotation, member, Double.class); return result.map(OptionalDouble::of).orElseGet(OptionalDouble::empty); }
The value as an OptionalDouble for the given annotation and member.
Params:
  • annotation – The annotation
  • member – The member
Returns:THe OptionalDouble value
/** * The value as an {@link OptionalDouble} for the given annotation and member. * * @param annotation The annotation * @param member The member * @return THe {@link OptionalDouble} value */
default @NonNull OptionalDouble doubleValue(@NonNull Class<? extends Annotation> annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); return doubleValue(annotation.getName(), member); }
The value as an OptionalDouble for the given annotation and member.
Params:
  • annotation – The annotation
Returns:THe OptionalDouble value
/** * The value as an {@link OptionalDouble} for the given annotation and member. * * @param annotation The annotation * @return THe {@link OptionalDouble} value */
default @NonNull OptionalDouble doubleValue(@NonNull Class<? extends Annotation> annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return doubleValue(annotation, VALUE_MEMBER); }
Get the value of default "value" the given annotation.
Params:
  • annotation – The annotation class
  • requiredType – The required type
Type parameters:
  • <T> – The value
Returns:An Optional of the value
/** * Get the value of default "value" the given annotation. * * @param annotation The annotation class * @param requiredType The required type * @param <T> The value * @return An {@link Optional} of the value */
default @NonNull <T> Optional<T> getValue(@NonNull String annotation, @NonNull Class<T> requiredType) { return getValue(annotation, VALUE_MEMBER, requiredType); }
Get the value of the given annotation member.
Params:
  • annotation – The annotation class
  • member – The annotation member
Returns:An Optional of the value
/** * Get the value of the given annotation member. * * @param annotation The annotation class * @param member The annotation member * @return An {@link Optional} of the value */
default @NonNull Optional<Object> getValue(@NonNull String annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return getValue(annotation, member, Object.class); }
Get the value of the given annotation member.
Params:
  • annotation – The annotation class
  • member – The annotation member
Returns:An Optional of the value
/** * Get the value of the given annotation member. * * @param annotation The annotation class * @param member The annotation member * @return An {@link Optional} of the value */
default @NonNull Optional<Object> getValue(@NonNull Class<? extends Annotation> annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return getValue(annotation, member, Object.class); }
Returns whether the value of the given member is true.
Params:
  • annotation – The annotation class
  • member – The annotation member
Returns:True if the value is true
/** * Returns whether the value of the given member is <em>true</em>. * * @param annotation The annotation class * @param member The annotation member * @return True if the value is true */
default boolean isTrue(@NonNull String annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return getValue(annotation, member, Boolean.class).orElse(false); }
Returns whether the value of the given member is true.
Params:
  • annotation – The annotation class
  • member – The annotation member
Returns:True if the value is true
/** * Returns whether the value of the given member is <em>true</em>. * * @param annotation The annotation class * @param member The annotation member * @return True if the value is true */
default boolean isTrue(@NonNull Class<? extends Annotation> annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return getValue(annotation.getName(), member, Boolean.class).orElse(false); }
Returns whether the value of the given member is present.
Params:
  • annotation – The annotation class
  • member – The annotation member
Returns:True if the value is true
/** * Returns whether the value of the given member is present. * * @param annotation The annotation class * @param member The annotation member * @return True if the value is true */
default boolean isPresent(@NonNull String annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return findAnnotation(annotation).map(av -> av.contains(member)).orElse(false); }
Returns whether the value of the given member is present.
Params:
  • annotation – The annotation class
  • member – The annotation member
Returns:True if the value is true
/** * Returns whether the value of the given member is present. * * @param annotation The annotation class * @param member The annotation member * @return True if the value is true */
default boolean isPresent(@NonNull Class<? extends Annotation> annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return isPresent(annotation.getName(), member); }
Returns whether the value of the given member is true.
Params:
  • annotation – The annotation class
  • member – The annotation member
Returns:True if the value is true
/** * Returns whether the value of the given member is <em>true</em>. * * @param annotation The annotation class * @param member The annotation member * @return True if the value is true */
default boolean isFalse(@NonNull Class<? extends Annotation> annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return !isTrue(annotation, member); }
Returns whether the value of the given member is true.
Params:
  • annotation – The annotation class
  • member – The annotation member
Returns:True if the value is true
/** * Returns whether the value of the given member is <em>true</em>. * * @param annotation The annotation class * @param member The annotation member * @return True if the value is true */
default boolean isFalse(@NonNull String annotation, @NonNull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return !isTrue(annotation, member); }
Get the value of default "value" the given annotation.
Params:
  • annotation – The annotation class
Returns:An Optional of the value
/** * Get the value of default "value" the given annotation. * * @param annotation The annotation class * @return An {@link Optional} of the value */
default @NonNull Optional<Object> getValue(@NonNull String annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return getValue(annotation, Object.class); }
Get the value of default "value" the given annotation.
Params:
  • annotation – The annotation class
Returns:An Optional of the value
/** * Get the value of default "value" the given annotation. * * @param annotation The annotation class * @return An {@link Optional} of the value */
default @NonNull Optional<Object> getValue(@NonNull Class<? extends Annotation> annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return getValue(annotation, AnnotationMetadata.VALUE_MEMBER, Object.class); }
Get the value of default "value" the given annotation.
Params:
  • annotation – The annotation class
  • requiredType – requiredType
Type parameters:
  • <T> – Generic type
Returns:An Optional of the value
/** * Get the value of default "value" the given annotation. * * @param annotation The annotation class * @param requiredType requiredType * @param <T> Generic type * @return An {@link Optional} of the value */
default @NonNull <T> Optional<T> getValue(@NonNull Class<? extends Annotation> annotation, @NonNull Class<T> requiredType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("requiredType", requiredType); return getValue(annotation, AnnotationMetadata.VALUE_MEMBER, requiredType); }
Get the value of default "value" the given annotation.
Params:
  • annotation – The annotation class
  • requiredType – requiredType
Type parameters:
  • <T> – Generic type
Returns:An Optional of the value
/** * Get the value of default "value" the given annotation. * * @param annotation The annotation class * @param requiredType requiredType * @param <T> Generic type * @return An {@link Optional} of the value */
default @NonNull <T> Optional<T> getValue(@NonNull Class<? extends Annotation> annotation, @NonNull Argument<T> requiredType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("requiredType", requiredType); return getValue(annotation, AnnotationMetadata.VALUE_MEMBER, requiredType); }
Get the value of default "value" the given annotation.
Params:
  • annotation – The annotation class
  • requiredType – requiredType
Type parameters:
  • <T> – Generic type
Returns:An Optional of the value
/** * Get the value of default "value" the given annotation. * * @param annotation The annotation class * @param requiredType requiredType * @param <T> Generic type * @return An {@link Optional} of the value */
default @NonNull <T> Optional<T> getValue(@NonNull String annotation, @NonNull Argument<T> requiredType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("requiredType", requiredType); return getValue(annotation, AnnotationMetadata.VALUE_MEMBER, requiredType); }
Checks whether this object has the given annotation on the object itself or inherited from a parent.
Params:
  • annotation – The annotation
Returns:True if the annotation is present
/** * Checks whether this object has the given annotation on the object itself or inherited from a parent. * * @param annotation The annotation * @return True if the annotation is present */
default boolean hasAnnotation(@Nullable Class<? extends Annotation> annotation) { if (annotation != null) { Repeatable repeatable = annotation.getAnnotation(Repeatable.class); if (repeatable != null) { return hasAnnotation(repeatable.value().getName()); } else { return hasAnnotation(annotation.getName()); } } return false; }

Checks whether this object has the given annotation stereotype on the object itself or inherited from a parent

.

An annotation stereotype is a meta annotation potentially applied to another annotation

Params:
  • annotation – The annotation
Returns:True if the annotation is present
/** * <p>Checks whether this object has the given annotation stereotype on the object itself or inherited from a parent</p>. * <p> * <p>An annotation stereotype is a meta annotation potentially applied to another annotation</p> * * @param annotation The annotation * @return True if the annotation is present */
default boolean hasStereotype(@Nullable Class<? extends Annotation> annotation) { if (annotation != null) { Repeatable repeatable = annotation.getAnnotation(Repeatable.class); if (repeatable != null) { return hasStereotype(repeatable.value().getName()); } else { return hasStereotype(annotation.getName()); } } return false; }
Check whether any of the given stereotypes is present.
Params:
  • annotations – The annotations
Returns:True if any of the given stereotypes are present
/** * Check whether any of the given stereotypes is present. * * @param annotations The annotations * @return True if any of the given stereotypes are present */
@SuppressWarnings("unchecked") default boolean hasStereotype(@Nullable Class<? extends Annotation>... annotations) { if (ArrayUtils.isEmpty(annotations)) { return false; } for (Class<? extends Annotation> annotation : annotations) { if (hasStereotype(annotation)) { return true; } } return false; }
Check whether any of the given stereotypes is present.
Params:
  • annotations – The annotations
Returns:True if any of the given stereotypes are present
/** * Check whether any of the given stereotypes is present. * * @param annotations The annotations * @return True if any of the given stereotypes are present */
default boolean hasStereotype(@Nullable String[] annotations) { if (ArrayUtils.isEmpty(annotations)) { return false; } for (String annotation : annotations) { if (hasStereotype(annotation)) { return true; } } return false; }
Checks whether this object has the given annotation directly declared on the object.
Params:
  • annotation – The annotation
Returns:True if the annotation is present
/** * Checks whether this object has the given annotation directly declared on the object. * * @param annotation The annotation * @return True if the annotation is present */
default boolean hasDeclaredAnnotation(@Nullable Class<? extends Annotation> annotation) { if (annotation != null) { Repeatable repeatable = annotation.getAnnotation(Repeatable.class); if (repeatable != null) { return hasDeclaredAnnotation(repeatable.value().getName()); } else { return hasDeclaredAnnotation(annotation.getName()); } } return false; }
Checks whether this object has the given stereotype directly declared on the object.
Params:
  • stereotype – The annotation
Returns:True if the annotation is present
/** * Checks whether this object has the given stereotype directly declared on the object. * * @param stereotype The annotation * @return True if the annotation is present */
default boolean hasDeclaredStereotype(@Nullable Class<? extends Annotation> stereotype) { if (stereotype != null) { Repeatable repeatable = stereotype.getAnnotation(Repeatable.class); if (repeatable != null) { return hasDeclaredStereotype(repeatable.value().getName()); } else { return hasDeclaredStereotype(stereotype.getName()); } } return false; }
Checks whether this object has any of the given stereotype directly declared on the object.
Params:
  • annotations – The annotations
Returns:True if any of the given stereotypes are present
/** * Checks whether this object has any of the given stereotype directly declared on the object. * * @param annotations The annotations * @return True if any of the given stereotypes are present */
@SuppressWarnings("unchecked") default boolean hasDeclaredStereotype(@Nullable Class<? extends Annotation>... annotations) { if (ArrayUtils.isEmpty(annotations)) { return false; } for (Class<? extends Annotation> annotation : annotations) { if (hasDeclaredStereotype(annotation)) { return true; } } return false; }
Is the annotation metadata empty.
Returns:True if it is
/** * Is the annotation metadata empty. * * @return True if it is */
default boolean isEmpty() { return this == AnnotationMetadata.EMPTY_METADATA; } }