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 4f0ff183b7 Utility class modernization
4f0ff183b7 is described below

commit 4f0ff183b7685e520cf3eb080c8d34dbc6fc99d8
Author: James Bognar <[email protected]>
AuthorDate: Fri Nov 7 17:29:17 2025 -0500

    Utility class modernization
---
 .../juneau/common/reflect/AnnotationProvider.java  | 30 ++++++++++++++++++++++
 .../apache/juneau/common/reflect/MethodInfo.java   | 26 -------------------
 .../rest/swagger/BasicSwaggerProviderSession.java  | 10 ++++----
 3 files changed, 35 insertions(+), 31 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 54ef0c396f..7823a477d0 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
@@ -19,11 +19,13 @@ package org.apache.juneau.common.reflect;
 import static org.apache.juneau.common.utils.AssertionUtils.*;
 import static org.apache.juneau.common.utils.ClassUtils.*;
 import static org.apache.juneau.common.utils.CollectionUtils.*;
+import static org.apache.juneau.common.utils.PredicateUtils.*;
 import static org.apache.juneau.common.utils.Utils.*;
 
 import java.lang.annotation.*;
 import java.lang.reflect.*;
 import java.util.*;
+import java.util.function.*;
 import java.util.stream.*;
 
 import org.apache.juneau.common.collections.*;
@@ -853,4 +855,32 @@ public class AnnotationProvider {
                        for (var a2 : splitRepeated(a))
                                appendTo.add(AnnotationInfo.of(ci, a2));
        }
+
+       /**
+        * Iterates through annotations on a method, its declaring class 
hierarchy, and return type hierarchy.
+        *
+        * <p>
+        * This traverses annotations in parent-first order from:
+        * <ol>
+        *      <li>Declaring class hierarchy (via this AnnotationProvider)
+        *      <li>Method hierarchy (parent-first, declared annotations only)
+        *      <li>Return type hierarchy (via this AnnotationProvider)
+        * </ol>
+        *
+        * @param <A> The annotation type.
+        * @param type The annotation type to search for.
+        * @param mi The method info to traverse.
+        * @param filter Optional filter to apply to annotations. Can be 
<jk>null</jk>.
+        * @param action The action to perform on each matching annotation.
+        */
+       public <A extends Annotation> void forEachMethodAnnotation(Class<A> 
type, MethodInfo mi, Predicate<A> filter, Consumer<A> action) {
+               mi.getDeclaringClass().forEachAnnotation(this, type, filter, 
action);
+               rstream(mi.getMatchingMethods())
+                       .flatMap(m -> m.getDeclaredAnnotationInfos().stream())
+                       .map(AnnotationInfo::inner)
+                       .filter(type::isInstance)
+                       .map(type::cast)
+                       .forEach(a -> consumeIf(filter, action, a));
+               mi.getReturnType().unwrap(Value.class, 
Optional.class).forEachAnnotation(this, type, filter, action);
+       }
 }
\ No newline at end of file
diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/MethodInfo.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/MethodInfo.java
index df85eb8552..5addb984f3 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/MethodInfo.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/MethodInfo.java
@@ -332,32 +332,6 @@ public class MethodInfo extends ExecutableInfo implements 
Comparable<MethodInfo>
                return i;
        }
 
-       /**
-        * Performs an action on all matching annotations defined on this 
method.
-        *
-        * <p>
-        * Searches all methods with the same signature on the parent classes 
or interfaces
-        * and the return type on the method.
-        * <br>Results are parent-to-child ordered.
-        *
-        * @param <A> The annotation type to look for.
-        * @param annotationProvider The annotation provider.
-        * @param type The annotation type.
-        * @param filter A predicate to apply to the entries to determine if 
action should be performed.  Can be <jk>null</jk>.
-        * @param action An action to perform on the entry.
-        */
-       public <A extends Annotation> void forEachAnnotation(AnnotationProvider 
annotationProvider, Class<A> type, Predicate<A> filter, Consumer<A> action) {
-               declaringClass.forEachAnnotation(annotationProvider, type, 
filter, action);
-               rstream(getMatchingMethods())
-                       .flatMap(m -> m.getDeclaredAnnotationInfos().stream())
-                       .map(AnnotationInfo::inner)
-                       .filter(type::isInstance)
-                       .map(type::cast)
-                       .forEach(a -> consumeIf(filter, action, a));
-               getReturnType().unwrap(Value.class, 
Optional.class).forEachAnnotation(annotationProvider, type, filter, action);
-       }
-
-
        /**
         * Returns the name of this method.
         *
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
index 303fd0e0ee..e83d07bf62 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
@@ -459,7 +459,7 @@ public class BasicSwaggerProviderSession {
                                                        String ha = a.name();
                                                        for (var code : codes) {
                                                                JsonMap header 
= responses.getMap(String.valueOf(code), true).getMap("headers", 
true).getMap(ha, true);
-                                                               
ecmi.forEachAnnotation(context.getAnnotationProvider(), Schema.class, x -> 
true, x -> merge(header, x));
+                                                               
context.getAnnotationProvider().forEachMethodAnnotation(Schema.class, ecmi, x 
-> true, x -> merge(header, x));
                                                                
rstream(ecmi.getReturnType().unwrap(Value.class, 
Optional.class).getAnnotationInfos()).map(x -> 
x.cast(Schema.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
 -> merge(header, x));
                                                                
pushupSchemaFields(RESPONSE_HEADER, header, getSchema(header.getMap("schema"), 
ecmi.getReturnType().unwrap(Value.class, Optional.class).innerType(), bs));
                                                        }
@@ -470,16 +470,16 @@ public class BasicSwaggerProviderSession {
 
                        if (mi.hasAnnotation(Response.class) || 
mi.getReturnType().unwrap(Value.class, 
Optional.class).hasAnnotation(Response.class)) {
                                List<Response> la = list();
-                               
mi.forEachAnnotation(context.getAnnotationProvider(), Response.class, x -> 
true, x -> la.add(x));
+                               
context.getAnnotationProvider().forEachMethodAnnotation(Response.class, mi, x 
-> true, x -> la.add(x));
                                List<StatusCode> la2 = list();
-                               
mi.forEachAnnotation(context.getAnnotationProvider(), StatusCode.class, x -> 
true, x -> la2.add(x));
+                               
context.getAnnotationProvider().forEachMethodAnnotation(StatusCode.class, mi, x 
-> true, x -> la2.add(x));
                                Set<Integer> codes = getCodes(la2, 200);
                                for (var a : la) {
                                        for (var code : codes) {
                                                JsonMap om = 
responses.getMap(String.valueOf(code), true);
                                                merge(om, a);
                                                JsonMap schema = 
getSchema(om.getMap("schema"), m.getGenericReturnType(), bs);
-                                               
mi.forEachAnnotation(context.getAnnotationProvider(), Schema.class, x -> true, 
x -> merge(schema, x));
+                                               
context.getAnnotationProvider().forEachMethodAnnotation(Schema.class, mi, x -> 
true, x -> merge(schema, x));
                                                pushupSchemaFields(RESPONSE, 
om, schema);
                                                om.appendIf(nem, "schema", 
schema);
                                                addBodyExamples(sm, om, true, 
m.getGenericReturnType(), locale);
@@ -495,7 +495,7 @@ public class BasicSwaggerProviderSession {
                                                        if (! isMulti(a)) {
                                                                for (var code : 
codes) {
                                                                        JsonMap 
header = responses.getMap(String.valueOf(code), true).getMap("headers", 
true).getMap(ha, true);
-                                                                       
ecmi.forEachAnnotation(context.getAnnotationProvider(), Schema.class, x -> 
true, x -> merge(header, x));
+                                                                       
context.getAnnotationProvider().forEachMethodAnnotation(Schema.class, ecmi, x 
-> true, x -> merge(header, x));
                                                                        
rstream(ecmi.getReturnType().unwrap(Value.class, 
Optional.class).getAnnotationInfos()).map(x -> 
x.cast(Schema.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
 -> merge(header, x));
                                                                        
merge(header, a.schema());
                                                                        
pushupSchemaFields(RESPONSE_HEADER, header, getSchema(header, 
ecmi.getReturnType().innerType(), bs));

Reply via email to