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 921a15a487 org.apache.juneau.common.reflect API improvements
921a15a487 is described below

commit 921a15a4878ac0d755d7dde977996d81ad38f8d7
Author: James Bognar <[email protected]>
AuthorDate: Wed Nov 19 10:05:55 2025 -0500

    org.apache.juneau.common.reflect API improvements
---
 .../juneau/common/reflect/AnnotationProvider.java  |  6 ++
 .../apache/juneau/common/reflect/MethodInfo.java   | 83 ----------------------
 2 files changed, 6 insertions(+), 83 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 7a6d3e5f23..234398ddf8 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
@@ -1005,6 +1005,8 @@ public class AnnotationProvider {
        public <A extends Annotation> Stream<AnnotationInfo<A>> 
findAnnotations(Class<A> type, MethodInfo method, AnnotationTraversal... 
traversals) {
                assertArgNotNull("type", type);
                assertArgNotNull("method", method);
+               if (traversals.length == 0)
+                       traversals = new AnnotationTraversal[]{SELF, 
MATCHING_METHODS, RETURN_TYPE, PACKAGE};
 
                return Arrays.stream(traversals)
                        
.sorted(Comparator.comparingInt(AnnotationTraversal::getOrder))
@@ -1015,6 +1017,10 @@ public class AnnotationProvider {
                                        return 
method.getMatchingMethods().stream().skip(1).flatMap(x -> find(type, 
x.inner()));
                                } else if (traversal == RETURN_TYPE) {
                                        return findAnnotations(type, 
method.getReturnType().unwrap(Value.class, Optional.class), PARENTS);
+                               } else if (traversal == PACKAGE) {
+                                       var c = method.getDeclaringClass();
+                                       A packageAnn = 
c.getPackageAnnotation(type);
+                                       return nn(packageAnn) ? 
Stream.of(AnnotationInfo.of(c, packageAnn)) : Stream.empty();
                                }
                                throw illegalArg("Invalid traversal type for 
method annotations: {0}", traversal);
                        });
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 a228923e89..5bd6ff5a62 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
@@ -199,62 +199,6 @@ public class MethodInfo extends ExecutableInfo implements 
Comparable<MethodInfo>
                        .map(a -> (AnnotationInfo<A>)a);
        }
 
-       /**
-        * Performs an action on all matching annotations on this method.
-        *
-        * <p>
-        * Processes annotations on:
-        * <ul>
-        *      <li>Package of the declaring class
-        *      <li>Interfaces (and their methods) in parent-to-child order
-        *      <li>Parent classes (and their methods) in parent-to-child order
-        * </ul>
-        *
-        * @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.
-        * @return This object.
-        */
-       public MethodInfo forEachAnnotation(Predicate<AnnotationInfo<?>> 
filter, Consumer<AnnotationInfo<?>> action) {
-               var c = getDeclaringClass();
-               forEachDeclaredAnnotation(c.getPackage(), filter, action);
-               var interfaces = c.getInterfaces();
-               for (int i = interfaces.size() - 1; i >= 0; i--) {
-                       forEachDeclaredAnnotation(interfaces.get(i), filter, 
action);
-                       forEachDeclaredMethodAnnotation(this, 
interfaces.get(i), filter, action);
-               }
-               var parents = c.getParents();
-               for (int i = parents.size() - 1; i >= 0; i--) {
-                       forEachDeclaredAnnotation(parents.get(i), filter, 
action);
-                       forEachDeclaredMethodAnnotation(this, parents.get(i), 
filter, action);
-               }
-               return this;
-       }
-
-       /**
-        * Performs an action on all matching annotations on methods only.
-        *
-        * <p>
-        * Processes annotations on:
-        * <ul>
-        *      <li>Matching methods in interfaces in parent-to-child order
-        *      <li>Matching methods in parent classes in parent-to-child order
-        * </ul>
-        *
-        * @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.
-        * @return This object.
-        */
-       public MethodInfo 
forEachAnnotationMethodOnly(Predicate<AnnotationInfo<?>> filter, 
Consumer<AnnotationInfo<?>> action) {
-               var c = getDeclaringClass();
-               var interfaces = c.getInterfaces();
-               for (int i = interfaces.size() - 1; i >= 0; i--)
-                       forEachDeclaredMethodAnnotation(this, 
interfaces.get(i), filter, action);
-               var parents = c.getParents();
-               for (int i = parents.size() - 1; i >= 0; i--)
-                       forEachDeclaredMethodAnnotation(this, parents.get(i), 
filter, action);
-               return this;
-       }
-
        /**
         * Returns all annotations on the declaring class, this method and 
parent overridden methods, return type, and package in child-to-parent order.
         *
@@ -785,33 +729,6 @@ public class MethodInfo extends ExecutableInfo implements 
Comparable<MethodInfo>
                return null;
        }
 
-       
//-----------------------------------------------------------------------------------------------------------------
-       // Helper methods for forEachAnnotation
-       
//-----------------------------------------------------------------------------------------------------------------
-
-       private static void forEachDeclaredAnnotation(ClassInfo ci, 
Predicate<AnnotationInfo<?>> filter, Consumer<AnnotationInfo<?>> action) {
-               if (nn(ci))
-                       for (var ai : ci.getDeclaredAnnotations())
-                               if (filter == null || filter.test(ai))
-                                       action.accept(ai);
-       }
-
-       private static void forEachDeclaredAnnotation(PackageInfo pi, 
Predicate<AnnotationInfo<?>> filter, Consumer<AnnotationInfo<?>> action) {
-               if (nn(pi))
-                       for (var ai : pi.getAnnotations())
-                               if (filter == null || filter.test(ai))
-                                       action.accept(ai);
-       }
-
-       private static void forEachDeclaredMethodAnnotation(MethodInfo 
methodInfo, ClassInfo ci, Predicate<AnnotationInfo<?>> filter, 
Consumer<AnnotationInfo<?>> action) {
-               MethodInfo mi = methodInfo.findMatchingOnClass(ci);
-               if (nn(mi))
-                       mi.getDeclaredAnnotations().forEach(ai -> {
-                               if (filter == null || filter.test(ai))
-                                       action.accept(ai);
-                       });
-       }
-
        
//-----------------------------------------------------------------------------------------------------------------
        // Annotatable interface methods
        
//-----------------------------------------------------------------------------------------------------------------

Reply via email to