This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new a3ed1f13da org.apache.juneau.common.reflect API improvements
a3ed1f13da is described below
commit a3ed1f13dadbf8ab7a9b549bcf0a4c5e60413412
Author: James Bognar <[email protected]>
AuthorDate: Wed Nov 19 16:59:52 2025 -0500
org.apache.juneau.common.reflect API improvements
---
.../juneau/common/reflect/AnnotationProvider.java | 442 ---------------------
1 file changed, 442 deletions(-)
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationProvider.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationProvider.java
index 928651b803..4789ba1aad 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationProvider.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationProvider.java
@@ -518,101 +518,6 @@ public class AnnotationProvider {
});
}
- /**
- * Streams annotations from a class that belong to the specified
annotation group.
- *
- * <p>
- * This method is similar to {@link #find(Class, ClassInfo,
AnnotationTraversal...)} but filters
- * annotations based on their {@link
org.apache.juneau.annotation.AnnotationGroup} membership rather
- * than their exact type.
- *
- * <p>
- * An annotation belongs to a group if it has an {@code
@AnnotationGroup} meta-annotation with the
- * specified group class. This allows you to find all annotations that
are logically related.
- *
- * <h5 class='section'>Supported Traversal Types:</h5>
- * <ul>
- * <li>{@link AnnotationTraversal#SELF SELF} - Annotations
declared directly on this class
- * <li>{@link AnnotationTraversal#PARENTS PARENTS} - Parent
classes and interfaces (child-to-parent order)
- * <li>{@link AnnotationTraversal#PACKAGE PACKAGE} - The package
annotations
- * </ul>
- *
- * <p>
- * <b>Default:</b> If no traversals are specified, defaults to: {@code
PARENTS, PACKAGE}
- * <br>Note: {@code PARENTS} includes the class itself plus all parent
classes and interfaces.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Find all bean-related annotations (that belong to the
Bean group)</jc>
- * Stream<AnnotationInfo<?>> <jv>annotations</jv> =
- * annotationProvider.findGroup(Bean.<jk>class</jk>,
<jv>classInfo</jv>);
- * </p>
- *
- * @param <A> The annotation group type.
- * @param group The annotation group class to filter by.
- * @param clazz The class to search.
- * @param traversals
- * The traversal options. If not specified, defaults to {@code
PARENTS, PACKAGE}.
- * <br>Valid values: {@link AnnotationTraversal#SELF SELF}, {@link
AnnotationTraversal#PARENTS PARENTS},
- * {@link AnnotationTraversal#PACKAGE PACKAGE}
- * @return A stream of {@link AnnotationInfo} objects belonging to the
specified group. Never <jk>null</jk>.
- */
- public <A extends Annotation> Stream<AnnotationInfo<?>>
findGroup(Class<A> group, ClassInfo clazz, AnnotationTraversal... traversals) {
- assertArgNotNull("group", group);
- assertArgNotNull("clazz", clazz);
- if (traversals.length == 0)
- traversals = a(PARENTS, PACKAGE);
-
- return Arrays.stream(traversals)
-
.sorted(Comparator.comparingInt(AnnotationTraversal::getOrder))
- .flatMap(traversal -> {
- if (traversal == SELF) {
- return concat(
-
classAnnnotations.get(clazz.inner()).stream(),
-
clazz.getDeclaredAnnotations().stream().map(a -> (AnnotationInfo<?>)a)
- )
- .filter(a -> a.isInGroup(group));
- } else if (traversal == PARENTS) {
- return
clazz.getParentsAndInterfaces().stream().flatMap(x ->
- concat(
-
classAnnnotations.get(x.inner()).stream(),
-
x.getDeclaredAnnotations().stream().map(a -> (AnnotationInfo<?>)a)
- ).filter(a ->
a.isInGroup(group))
- );
- } else if (traversal == PACKAGE) {
- return opt(clazz.getPackage()).map(x ->
x.getAnnotations().stream().map(a -> (AnnotationInfo<?>)a).filter(a ->
a.isInGroup(group))).orElse(Stream.empty());
- }
- throw illegalArg("Invalid traversal type for
class annotations: {0}", traversal);
- });
- }
-
- /**
- * Streams annotations from a class that belong to the specified
annotation group in parent-first order.
- *
- * <p>
- * This is equivalent to calling {@link #findGroup(Class, ClassInfo,
AnnotationTraversal...)}
- * and reversing the result.
- *
- * <p>
- * Use this when you need parent annotations to take precedence over
child annotations.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Get bean-group annotations in parent-first order</jc>
- * Stream<AnnotationInfo<?>> <jv>annotations</jv> =
- *
annotationProvider.findGroupTopDown(Bean.<jk>class</jk>, <jv>classInfo</jv>);
- * </p>
- *
- * @param <A> The annotation group type.
- * @param group The annotation group class to filter by.
- * @param clazz The class to search.
- * @param traversals The traversal options.
- * @return A stream of {@link AnnotationInfo} objects in parent-first
order. Never <jk>null</jk>.
- */
- public <A extends Annotation> Stream<AnnotationInfo<?>>
findGroupTopDown(Class<A> group, ClassInfo clazz, AnnotationTraversal...
traversals) {
- return rstream(findGroup(group, clazz, traversals).toList());
- }
-
/**
* Streams all annotations from a class using configurable traversal
options, without filtering by annotation type.
*
@@ -792,106 +697,6 @@ public class AnnotationProvider {
});
}
- /**
- * Streams annotations from a method that belong to the specified
annotation group.
- *
- * <p>
- * This method is similar to {@link #find(Class, MethodInfo,
AnnotationTraversal...)} but filters
- * annotations based on their {@link
org.apache.juneau.annotation.AnnotationGroup} membership rather
- * than their exact type.
- *
- * <p>
- * An annotation belongs to a group if it has an {@code
@AnnotationGroup} meta-annotation with the
- * specified group class. This allows you to find all annotations that
are logically related.
- *
- * <h5 class='section'>Supported Traversal Types:</h5>
- * <ul>
- * <li>{@link AnnotationTraversal#SELF SELF} - Annotations
declared directly on this method
- * <li>{@link AnnotationTraversal#MATCHING_METHODS
MATCHING_METHODS} - Matching methods in parent classes (child-to-parent)
- * <li>{@link AnnotationTraversal#DECLARING_CLASS DECLARING_CLASS}
- The declaring class hierarchy
- * <li>{@link AnnotationTraversal#RETURN_TYPE RETURN_TYPE} - The
return type hierarchy (includes class parents and package)
- * <li>{@link AnnotationTraversal#PACKAGE PACKAGE} - The declaring
class's package annotations
- * </ul>
- *
- * <p>
- * <b>Default:</b> If no traversals are specified, defaults to: {@code
SELF, MATCHING_METHODS, RETURN_TYPE, PACKAGE}
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Find all REST operation annotations (that belong to the
RestOp group)</jc>
- * Stream<AnnotationInfo<?>> <jv>annotations</jv> =
- * annotationProvider.findGroup(RestOp.<jk>class</jk>,
<jv>methodInfo</jv>);
- * </p>
- *
- * @param <A> The annotation group type.
- * @param group The annotation group class to filter by.
- * @param method The method to search.
- * @param traversals
- * The traversal options. If not specified, defaults to {@code
SELF, MATCHING_METHODS, RETURN_TYPE, PACKAGE}.
- * <br>Valid values: {@link AnnotationTraversal#SELF SELF}, {@link
AnnotationTraversal#MATCHING_METHODS MATCHING_METHODS},
- * {@link AnnotationTraversal#DECLARING_CLASS DECLARING_CLASS},
{@link AnnotationTraversal#RETURN_TYPE RETURN_TYPE},
- * {@link AnnotationTraversal#PACKAGE PACKAGE}
- * @return A stream of {@link AnnotationInfo} objects belonging to the
specified group. Never <jk>null</jk>.
- */
- public <A extends Annotation> Stream<AnnotationInfo<?>>
findGroup(Class<A> group, MethodInfo method, AnnotationTraversal... traversals)
{
- assertArgNotNull("group", group);
- assertArgNotNull("method", method);
- if (traversals.length == 0)
- traversals = a(SELF, MATCHING_METHODS, RETURN_TYPE,
PACKAGE);
-
- return Arrays.stream(traversals)
-
.sorted(Comparator.comparingInt(AnnotationTraversal::getOrder))
- .flatMap(traversal -> {
- if (traversal == SELF) {
- return concat(
-
methodAnnotations.get(method.inner()).stream(),
-
method.getDeclaredAnnotations().stream().map(a -> (AnnotationInfo<?>)a)
- ).filter(a -> a.isInGroup(group));
- } else if (traversal == MATCHING_METHODS) {
- return
method.getMatchingMethods().stream().skip(1).flatMap(m ->
- concat(
-
methodAnnotations.get(m.inner()).stream(),
-
m.getDeclaredAnnotations().stream().map(a -> (AnnotationInfo<?>)a)
- ).filter(a ->
a.isInGroup(group))
- );
- } else if (traversal == DECLARING_CLASS) {
- return findGroup(group,
method.getDeclaringClass(), PARENTS);
- } else if (traversal == RETURN_TYPE) {
- return findGroup(group,
method.getReturnType().unwrap(Value.class, Optional.class), PARENTS);
- } else if (traversal == PACKAGE) {
- return
opt(method.getDeclaringClass().getPackage()).map(x ->
x.getAnnotations().stream().map(a -> (AnnotationInfo<?>)a).filter(a ->
a.isInGroup(group))).orElse(Stream.empty());
- }
- throw illegalArg("Invalid traversal type for
method annotations: {0}", traversal);
- });
- }
-
- /**
- * Streams annotations from a method that belong to the specified
annotation group in parent-first order.
- *
- * <p>
- * This is equivalent to calling {@link #findGroup(Class, MethodInfo,
AnnotationTraversal...)}
- * and reversing the result.
- *
- * <p>
- * Use this when you need parent annotations to take precedence over
child annotations.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Get REST operation annotations in parent-first order</jc>
- * Stream<AnnotationInfo<?>> <jv>annotations</jv> =
- *
annotationProvider.findGroupTopDown(RestOp.<jk>class</jk>, <jv>methodInfo</jv>);
- * </p>
- *
- * @param <A> The annotation group type.
- * @param group The annotation group class to filter by.
- * @param method The method to search.
- * @param traversals The traversal options.
- * @return A stream of {@link AnnotationInfo} objects in parent-first
order. Never <jk>null</jk>.
- */
- public <A extends Annotation> Stream<AnnotationInfo<?>>
findGroupTopDown(Class<A> group, MethodInfo method, AnnotationTraversal...
traversals) {
- return rstream(findGroup(group, method, traversals).toList());
- }
-
/**
* Streams all annotations from a method using configurable traversal
options, without filtering by annotation type.
*
@@ -1077,91 +882,6 @@ public class AnnotationProvider {
});
}
- /**
- * Streams annotations from a parameter that belong to the specified
annotation group.
- *
- * <p>
- * This method is similar to {@link #find(Class, ParameterInfo,
AnnotationTraversal...)} but filters
- * annotations based on their {@link
org.apache.juneau.annotation.AnnotationGroup} membership rather
- * than their exact type.
- *
- * <p>
- * An annotation belongs to a group if it has an {@code
@AnnotationGroup} meta-annotation with the
- * specified group class. This allows you to find all annotations that
are logically related.
- *
- * <h5 class='section'>Supported Traversal Types:</h5>
- * <ul>
- * <li>{@link AnnotationTraversal#SELF SELF} - Annotations
declared directly on this parameter
- * <li>{@link AnnotationTraversal#MATCHING_PARAMETERS
MATCHING_PARAMETERS} - Matching parameters in parent methods/constructors
(child-to-parent)
- * <li>{@link AnnotationTraversal#PARAMETER_TYPE PARAMETER_TYPE} -
The parameter's type hierarchy (includes class parents and package)
- * </ul>
- *
- * <p>
- * <b>Default:</b> If no traversals are specified, defaults to: {@code
SELF, MATCHING_PARAMETERS, PARAMETER_TYPE}
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Find all REST parameter annotations (that belong to a
group)</jc>
- * Stream<AnnotationInfo<?>> <jv>annotations</jv> =
- * annotationProvider.findGroup(Query.<jk>class</jk>,
<jv>parameterInfo</jv>);
- * </p>
- *
- * @param <A> The annotation group type.
- * @param group The annotation group class to filter by.
- * @param parameter The parameter to search.
- * @param traversals
- * The traversal options. If not specified, defaults to {@code
SELF, MATCHING_PARAMETERS, PARAMETER_TYPE}.
- * <br>Valid values: {@link AnnotationTraversal#SELF SELF}, {@link
AnnotationTraversal#MATCHING_PARAMETERS MATCHING_PARAMETERS},
- * {@link AnnotationTraversal#PARAMETER_TYPE PARAMETER_TYPE}
- * @return A stream of {@link AnnotationInfo} objects belonging to the
specified group. Never <jk>null</jk>.
- */
- public <A extends Annotation> Stream<AnnotationInfo<?>>
findGroup(Class<A> group, ParameterInfo parameter, AnnotationTraversal...
traversals) {
- assertArgNotNull("group", group);
- assertArgNotNull("parameter", parameter);
- if (traversals.length == 0)
- traversals = a(SELF, MATCHING_PARAMETERS,
PARAMETER_TYPE);
-
- return Arrays.stream(traversals)
-
.sorted(Comparator.comparingInt(AnnotationTraversal::getOrder))
- .flatMap(traversal -> {
- if (traversal == SELF) {
- return
parameter.getAnnotations().stream().map(a -> (AnnotationInfo<?>)a).filter(a ->
a.isInGroup(group));
- } else if (traversal == MATCHING_PARAMETERS) {
- return
parameter.getMatchingParameters().stream().skip(1).flatMap(x ->
x.getAnnotations().stream().map(a -> (AnnotationInfo<?>)a).filter(a ->
a.isInGroup(group)));
- } else if (traversal == PARAMETER_TYPE) {
- return findGroup(group,
parameter.getParameterType().unwrap(Value.class, Optional.class), PARENTS,
PACKAGE);
- }
- throw illegalArg("Invalid traversal type for
parameter annotations: {0}", traversal);
- });
- }
-
- /**
- * Streams annotations from a parameter that belong to the specified
annotation group in parent-first order.
- *
- * <p>
- * This is equivalent to calling {@link #findGroup(Class,
ParameterInfo, AnnotationTraversal...)}
- * and reversing the result.
- *
- * <p>
- * Use this when you need parent annotations to take precedence over
child annotations.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Get parameter annotations in parent-first order</jc>
- * Stream<AnnotationInfo<?>> <jv>annotations</jv> =
- *
annotationProvider.findGroupTopDown(Query.<jk>class</jk>,
<jv>parameterInfo</jv>);
- * </p>
- *
- * @param <A> The annotation group type.
- * @param group The annotation group class to filter by.
- * @param parameter The parameter to search.
- * @param traversals The traversal options.
- * @return A stream of {@link AnnotationInfo} objects in parent-first
order. Never <jk>null</jk>.
- */
- public <A extends Annotation> Stream<AnnotationInfo<?>>
findGroupTopDown(Class<A> group, ParameterInfo parameter,
AnnotationTraversal... traversals) {
- return rstream(findGroup(group, parameter,
traversals).toList());
- }
-
/**
* Streams annotations from a parameter using configurable traversal
options in parent-to-child order.
*
@@ -1350,87 +1070,6 @@ public class AnnotationProvider {
});
}
- /**
- * Streams annotations from a field that belong to the specified
annotation group.
- *
- * <p>
- * This method is similar to {@link #find(Class, FieldInfo,
AnnotationTraversal...)} but filters
- * annotations based on their {@link
org.apache.juneau.annotation.AnnotationGroup} membership rather
- * than their exact type.
- *
- * <p>
- * An annotation belongs to a group if it has an {@code
@AnnotationGroup} meta-annotation with the
- * specified group class. This allows you to find all annotations that
are logically related.
- *
- * <h5 class='section'>Supported Traversal Types:</h5>
- * <ul>
- * <li>{@link AnnotationTraversal#SELF SELF} - Annotations
declared directly on this field
- * </ul>
- *
- * <p>
- * <b>Default:</b> If no traversals are specified, defaults to: {@code
SELF}
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Find all bean property annotations (that belong to the
Beanp group)</jc>
- * Stream<AnnotationInfo<?>> <jv>annotations</jv> =
- * annotationProvider.findGroup(Beanp.<jk>class</jk>,
<jv>fieldInfo</jv>);
- * </p>
- *
- * @param <A> The annotation group type.
- * @param group The annotation group class to filter by.
- * @param field The field to search.
- * @param traversals
- * The traversal options. If not specified, defaults to {@code
SELF}.
- * <br>Valid values: {@link AnnotationTraversal#SELF SELF}
- * @return A stream of {@link AnnotationInfo} objects belonging to the
specified group. Never <jk>null</jk>.
- */
- public <A extends Annotation> Stream<AnnotationInfo<?>>
findGroup(Class<A> group, FieldInfo field, AnnotationTraversal... traversals) {
- assertArgNotNull("group", group);
- assertArgNotNull("field", field);
- if (traversals.length == 0)
- traversals = a(SELF);
-
- return Arrays.stream(traversals)
-
.sorted(Comparator.comparingInt(AnnotationTraversal::getOrder))
- .flatMap(traversal -> {
- if (traversal == SELF) {
- return concat(
-
fieldAnnotations.get(field.inner()).stream(),
-
field.getAnnotations().stream().map(a -> (AnnotationInfo<?>)a)
- ).filter(a -> a.isInGroup(group));
- }
- throw illegalArg("Invalid traversal type for
field annotations: {0}", traversal);
- });
- }
-
- /**
- * Streams annotations from a field that belong to the specified
annotation group in parent-first order.
- *
- * <p>
- * This is equivalent to calling {@link #findGroup(Class, FieldInfo,
AnnotationTraversal...)}
- * and reversing the result.
- *
- * <p>
- * Use this when you need parent annotations to take precedence over
child annotations.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Get bean property annotations in parent-first order</jc>
- * Stream<AnnotationInfo<?>> <jv>annotations</jv> =
- *
annotationProvider.findGroupTopDown(Beanp.<jk>class</jk>, <jv>fieldInfo</jv>);
- * </p>
- *
- * @param <A> The annotation group type.
- * @param group The annotation group class to filter by.
- * @param field The field to search.
- * @param traversals The traversal options.
- * @return A stream of {@link AnnotationInfo} objects in parent-first
order. Never <jk>null</jk>.
- */
- public <A extends Annotation> Stream<AnnotationInfo<?>>
findGroupTopDown(Class<A> group, FieldInfo field, AnnotationTraversal...
traversals) {
- return rstream(findGroup(group, field, traversals).toList());
- }
-
/**
* Streams all annotations from a field using configurable traversal
options, without filtering by annotation type.
*
@@ -1573,87 +1212,6 @@ public class AnnotationProvider {
});
}
- /**
- * Streams annotations from a constructor that belong to the specified
annotation group.
- *
- * <p>
- * This method is similar to {@link #find(Class, ConstructorInfo,
AnnotationTraversal...)} but filters
- * annotations based on their {@link
org.apache.juneau.annotation.AnnotationGroup} membership rather
- * than their exact type.
- *
- * <p>
- * An annotation belongs to a group if it has an {@code
@AnnotationGroup} meta-annotation with the
- * specified group class. This allows you to find all annotations that
are logically related.
- *
- * <h5 class='section'>Supported Traversal Types:</h5>
- * <ul>
- * <li>{@link AnnotationTraversal#SELF SELF} - Annotations
declared directly on this constructor
- * </ul>
- *
- * <p>
- * <b>Default:</b> If no traversals are specified, defaults to: {@code
SELF}
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Find all bean-related annotations on constructor</jc>
- * Stream<AnnotationInfo<?>> <jv>annotations</jv> =
- * annotationProvider.findGroup(Bean.<jk>class</jk>,
<jv>constructorInfo</jv>);
- * </p>
- *
- * @param <A> The annotation group type.
- * @param group The annotation group class to filter by.
- * @param constructor The constructor to search.
- * @param traversals
- * The traversal options. If not specified, defaults to {@code
SELF}.
- * <br>Valid values: {@link AnnotationTraversal#SELF SELF}
- * @return A stream of {@link AnnotationInfo} objects belonging to the
specified group. Never <jk>null</jk>.
- */
- public <A extends Annotation> Stream<AnnotationInfo<?>>
findGroup(Class<A> group, ConstructorInfo constructor, AnnotationTraversal...
traversals) {
- assertArgNotNull("group", group);
- assertArgNotNull("constructor", constructor);
- if (traversals.length == 0)
- traversals = a(SELF);
-
- return Arrays.stream(traversals)
-
.sorted(Comparator.comparingInt(AnnotationTraversal::getOrder))
- .flatMap(traversal -> {
- if (traversal == SELF) {
- return concat(
-
constructorAnnotations.get(constructor.inner()).stream(),
-
constructor.getDeclaredAnnotations().stream().map(a -> (AnnotationInfo<?>)a)
- ).filter(a -> a.isInGroup(group));
- }
- throw illegalArg("Invalid traversal type for
constructor annotations: {0}", traversal);
- });
- }
-
- /**
- * Streams annotations from a constructor that belong to the specified
annotation group in parent-first order.
- *
- * <p>
- * This is equivalent to calling {@link #findGroup(Class,
ConstructorInfo, AnnotationTraversal...)}
- * and reversing the result.
- *
- * <p>
- * Use this when you need parent annotations to take precedence over
child annotations.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Get bean-related annotations in parent-first order</jc>
- * Stream<AnnotationInfo<?>> <jv>annotations</jv> =
- *
annotationProvider.findGroupTopDown(Bean.<jk>class</jk>,
<jv>constructorInfo</jv>);
- * </p>
- *
- * @param <A> The annotation group type.
- * @param group The annotation group class to filter by.
- * @param constructor The constructor to search.
- * @param traversals The traversal options.
- * @return A stream of {@link AnnotationInfo} objects in parent-first
order. Never <jk>null</jk>.
- */
- public <A extends Annotation> Stream<AnnotationInfo<?>>
findGroupTopDown(Class<A> group, ConstructorInfo constructor,
AnnotationTraversal... traversals) {
- return rstream(findGroup(group, constructor,
traversals).toList());
- }
-
/**
* Streams all annotations from a constructor using configurable
traversal options, without filtering by annotation type.
*