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

commit e34850acd3954ee0ca13527561f79b05a0a5be7e
Author: James Bognar <[email protected]>
AuthorDate: Fri Nov 7 10:25:27 2025 -0500

    Utility class modernization
---
 .../apache/juneau/common/reflect/ClassInfo.java    | 24 ---------------
 .../apache/juneau/common/reflect/MethodInfo.java   | 36 ----------------------
 .../src/main/java/org/apache/juneau/BeanMeta.java  |  6 +++-
 .../src/main/java/org/apache/juneau/ClassMeta.java |  6 ++--
 .../annotation/InvalidAnnotationException.java     |  7 ++++-
 .../juneau/common/reflect/MethodInfo_Test.java     | 10 +++---
 6 files changed, 19 insertions(+), 70 deletions(-)

diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ClassInfo.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ClassInfo.java
index 761f9e5f08..ac43bf4c04 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ClassInfo.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ClassInfo.java
@@ -478,9 +478,6 @@ public class ClassInfo extends ElementInfo implements 
Annotatable {
         * @param type The annotation to look for.
         * @return The annotation if found, or <jk>null</jk> if not.
         */
-       public <A extends Annotation> A getAnnotation(AnnotationProvider 
annotationProvider, Class<A> type) {
-               return findAnnotation(annotationProvider, type);
-       }
 
        /**
         * Returns all annotations of the specified type defined on this or 
parent classes/interfaces.
@@ -2335,27 +2332,6 @@ public class ClassInfo extends ElementInfo implements 
Annotatable {
                return c == null ? null : of(c.componentType());
        }
 
-       private <A extends Annotation> A findAnnotation(AnnotationProvider ap, 
Class<A> a) {
-               if (a == null)
-                       return null;
-               if (ap == null)
-                       throw unsupportedOp();
-               A t = ap.findDeclared(a, c).map(x -> x.inner()).filter(x -> 
true).findFirst().orElse(null);
-               if (nn(t))
-                       return t;
-               ClassInfo sci = getSuperclass();
-               if (nn(sci)) {
-                       t = sci.getAnnotation(ap, a);
-                       if (nn(t))
-                               return t;
-               }
-               for (var c2 : interfaces.get()) {
-                       t = c2.getAnnotation(ap, a);
-                       if (nn(t))
-                               return t;
-               }
-               return null;
-       }
 
        /**
         * Returns the first type parameter of this type if it's parameterized 
(e.g., T in Optional&lt;T&gt;).
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 e2090177ce..1bce42b7d2 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
@@ -385,42 +385,6 @@ public class MethodInfo extends ExecutableInfo implements 
Comparable<MethodInfo>
        }
 
 
-       /**
-        * Finds the annotation of the specified type 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.
-        *
-        * @param <A> The annotation type to look for.
-        * @param annotationProvider The annotation provider.
-        * @param type The annotation to look for.
-        * @return The first annotation found, or <jk>null</jk> if it doesn't 
exist.
-        */
-       public <A extends Annotation> A getAnnotation(AnnotationProvider 
annotationProvider, Class<A> type) {
-               // Inline Context.firstAnnotation() call
-               return matchingCache.get().stream()
-                       .map(m2 -> annotationProvider.find(type, 
m2.inner()).map(x -> x.inner()).filter(x -> true).findFirst().orElse(null))
-                       .filter(Objects::nonNull)
-                       .findFirst()
-                       .orElse(null);
-       }
-
-       /**
-        * Returns the first annotation in the specified list on this method.
-        *
-        * @param types The annotations to look for.
-        * @return The first matching annotation.
-        */
-       @SafeVarargs
-       public final Annotation getAnyAnnotation(Class<? extends 
Annotation>...types) {
-               return Arrays.stream(types)
-                       .map(t -> 
getAnnotationInfos(t).findFirst().map(AnnotationInfo::inner).orElse(null))
-                       .filter(Objects::nonNull)
-                       .findFirst()
-                       .orElse(null);
-       }
-
        /**
         * Returns the name of this method.
         *
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
index 5b6d5da3ba..69b7ef2b92 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
@@ -595,7 +595,11 @@ public class BeanMeta<T> {
                        for (var m : c2.getDeclaredMethods()) {
                                if (m.isStatic() || m.isBridge() || 
m.getParameterCount() > 2 || m.hasAnnotation(ctx.getAnnotationProvider(), 
BeanIgnore.class))
                                        continue;
-                               Transient t = 
m.getAnnotation(ctx.getAnnotationProvider(), Transient.class);
+                               Transient t = m.getMatchingMethods().stream()
+                                       .map(m2 -> 
ctx.getAnnotationProvider().find(Transient.class, m2.inner()).map(x -> 
x.inner()).filter(x -> true).findFirst().orElse(null))
+                                       .filter(Objects::nonNull)
+                                       .findFirst()
+                                       .orElse(null);
                                if (nn(t) && t.value())
                                        continue;
 
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
index a6321aabe4..a85d798456 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
@@ -1115,8 +1115,8 @@ public class ClassMeta<T> implements Type {
                Optional<A> o = (Optional<A>)annotationLastMap.get(a);
                if (o == null) {
                        if (beanContext == null)
-                               return 
info.getAnnotation(BeanContext.DEFAULT.getAnnotationProvider(), a);
-                       o = 
opt(info.getAnnotation(beanContext.getAnnotationProvider(), a));
+                               return 
BeanContext.DEFAULT.getAnnotationProvider().find(a, 
info.inner()).findFirst().map(x -> x.inner()).orElse(null);
+                       o = opt(beanContext.getAnnotationProvider().find(a, 
info.inner()).findFirst().map(x -> x.inner()).orElse(null));
                        annotationLastMap.put(a, o);
                }
                return o.orElse(null);
@@ -1935,7 +1935,7 @@ public class ClassMeta<T> implements Type {
                A[] array = (A[])annotationArrayMap.get(type);
                if (array == null && nn(beanContext)) {
                        List<A> l = list();
-                       
info.forEachAnnotation(beanContext.getAnnotationProvider(), type, x -> true, x 
-> l.add(x));
+                       beanContext.getAnnotationProvider().find(type, 
info.inner()).map(x -> x.inner()).filter(x -> true).forEach(x -> l.add(x));
                        array = (A[])Array.newInstance(type, l.size());
                        for (int i = 0; i < l.size(); i++)
                                Array.set(array, i, l.get(i));
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/InvalidAnnotationException.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/InvalidAnnotationException.java
index c9c785774a..fc6d4eb860 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/InvalidAnnotationException.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/InvalidAnnotationException.java
@@ -19,6 +19,7 @@ package org.apache.juneau.annotation;
 import static org.apache.juneau.common.utils.Utils.*;
 
 import java.lang.annotation.*;
+import java.util.*;
 
 import org.apache.juneau.*;
 import org.apache.juneau.common.reflect.*;
@@ -44,7 +45,11 @@ public class InvalidAnnotationException extends 
BasicRuntimeException {
         */
        @SafeVarargs
        public static void assertNoInvalidAnnotations(MethodInfo onMethod, 
Class<? extends Annotation>...types) throws InvalidAnnotationException {
-               Annotation a = onMethod.getAnyAnnotation(types);
+               Annotation a = Arrays.stream(types)
+                       .map(t -> 
onMethod.getAnnotationInfos(t).findFirst().map(AnnotationInfo::inner).orElse(null))
+                       .filter(Objects::nonNull)
+                       .findFirst()
+                       .orElse(null);
                if (nn(a))
                        throw new InvalidAnnotationException("@{0} annotation 
cannot be used in a @{1} bean.  Method=''{2}''", scn(a), 
scn(onMethod.getDeclaringClass()), onMethod);
        }
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/MethodInfo_Test.java
 
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/MethodInfo_Test.java
index a10c26a74d..a621fa562e 100644
--- 
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/MethodInfo_Test.java
+++ 
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/MethodInfo_Test.java
@@ -358,11 +358,11 @@ class MethodInfo_Test extends TestBase {
        }
 
        @Test void getAnnotationAny() {
-               check("@A(a1)", c_a1.getAnyAnnotation(AX.class, A.class));
-               check("@A(a2b)", c_a2.getAnyAnnotation(AX.class, A.class));
-               check("@A(a3)", c_a3.getAnyAnnotation(AX.class, A.class));
-               check("@A(a4)", c_a4.getAnyAnnotation(AX.class, A.class));
-               check(null, c_a5.getAnyAnnotation(AX.class, A.class));
+               check("@A(a1)", Stream.<Class<? extends 
Annotation>>of(AX.class, A.class).map(t -> 
c_a1.getAnnotationInfos(t).findFirst().map(AnnotationInfo::inner).orElse(null)).filter(Objects::nonNull).findFirst().orElse(null));
+               check("@A(a2b)", Stream.<Class<? extends 
Annotation>>of(AX.class, A.class).map(t -> 
c_a2.getAnnotationInfos(t).findFirst().map(AnnotationInfo::inner).orElse(null)).filter(Objects::nonNull).findFirst().orElse(null));
+               check("@A(a3)", Stream.<Class<? extends 
Annotation>>of(AX.class, A.class).map(t -> 
c_a3.getAnnotationInfos(t).findFirst().map(AnnotationInfo::inner).orElse(null)).filter(Objects::nonNull).findFirst().orElse(null));
+               check("@A(a4)", Stream.<Class<? extends 
Annotation>>of(AX.class, A.class).map(t -> 
c_a4.getAnnotationInfos(t).findFirst().map(AnnotationInfo::inner).orElse(null)).filter(Objects::nonNull).findFirst().orElse(null));
+               check(null, Stream.<Class<? extends Annotation>>of(AX.class, 
A.class).map(t -> 
c_a5.getAnnotationInfos(t).findFirst().map(AnnotationInfo::inner).orElse(null)).filter(Objects::nonNull).findFirst().orElse(null));
        }
 
        @Test void getAnnotationsMapParentFirst() {

Reply via email to