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

commit ef0ff7e017fc40296de7617791ab6162c9ca9536
Author: James Bognar <[email protected]>
AuthorDate: Thu Nov 6 18:59:19 2025 -0500

    Utility class modernization
---
 .../apache/juneau/common/reflect/AnnotationProvider.java | 10 ++++++++++
 .../java/org/apache/juneau/common/reflect/ClassInfo.java |  6 ++++--
 .../apache/juneau/common/reflect/ConstructorInfo.java    |  3 ++-
 .../java/org/apache/juneau/common/reflect/FieldInfo.java |  3 ++-
 .../org/apache/juneau/common/reflect/MethodInfo.java     |  6 ++++--
 .../src/main/java/org/apache/juneau/BeanMeta.java        | 11 +++++++----
 .../main/java/org/apache/juneau/BeanPropertyMeta.java    | 16 +++++++++-------
 .../src/main/java/org/apache/juneau/ClassMeta.java       | 11 +++++++----
 .../src/main/java/org/apache/juneau/Context.java         | 12 ++++++------
 .../main/java/org/apache/juneau/swap/BuilderSwap.java    |  2 +-
 .../src/main/java/org/apache/juneau/xml/XmlBeanMeta.java |  2 +-
 11 files changed, 53 insertions(+), 29 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 2d820a0cda..e92397555b 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
@@ -40,6 +40,16 @@ public interface AnnotationProvider {
         */
        boolean DISABLE_ANNOTATION_CACHING = 
Boolean.getBoolean("juneau.disableAnnotationCaching");
 
+       /**
+        * Returns the underlying AnnotationProvider2 instance.
+        * 
+        * <p>
+        * This allows direct access to AnnotationProvider2 methods which 
support runtime annotations.
+        *
+        * @return The underlying AnnotationProvider2 instance.
+        */
+       AnnotationProvider2 getAnnotationProvider();
+
        /**
         * Finds the first matching annotation on the specified class.
         *
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 6ae22f3715..7d0bdad6dc 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
@@ -1664,7 +1664,8 @@ public class ClassInfo extends ElementInfo implements 
Annotatable {
        public <A extends Annotation> boolean hasAnnotation(AnnotationProvider 
annotationProvider, Class<A> type) {
                if (annotationProvider == null)
                        throw unsupportedOp();
-               return nn(annotationProvider.firstAnnotation(type, c, x -> 
true));
+               // Inline Context.firstAnnotation() call
+               return nn(annotationProvider.getAnnotationProvider().find(type, 
c).map(x -> x.inner()).filter(x -> true).findFirst().orElse(null));
        }
 
        /**
@@ -2339,7 +2340,8 @@ public class ClassInfo extends ElementInfo implements 
Annotatable {
                        return null;
                if (ap == null)
                        throw unsupportedOp();
-               A t = ap.firstDeclaredAnnotation(a, c, x -> true);
+               // Inline Context.firstDeclaredAnnotation() call
+               A t = ap.getAnnotationProvider().findDeclared(a, c).map(x -> 
x.inner()).filter(x -> true).findFirst().orElse(null);
                if (nn(t))
                        return t;
                ClassInfo sci = getSuperclass();
diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ConstructorInfo.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ConstructorInfo.java
index 5b3596ec6e..a9a04fb6ce 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ConstructorInfo.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ConstructorInfo.java
@@ -149,7 +149,8 @@ public class ConstructorInfo extends ExecutableInfo 
implements Comparable<Constr
         * @return <jk>true</jk> if the specified annotation is present on this 
constructor.
         */
        public <A extends Annotation> boolean hasAnnotation(AnnotationProvider 
annotationProvider, Class<A> type) {
-               return nn(annotationProvider.firstAnnotation(type, c, x -> 
true));
+               // Inline Context.firstAnnotation() call
+               return nn(annotationProvider.getAnnotationProvider().find(type, 
c).map(x -> x.inner()).filter(x -> true).findFirst().orElse(null));
        }
 
        /**
diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/FieldInfo.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/FieldInfo.java
index 7eabf313fd..e3c4489d4a 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/FieldInfo.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/FieldInfo.java
@@ -223,7 +223,8 @@ public class FieldInfo extends AccessibleInfo implements 
Comparable<FieldInfo>,
         * @return <jk>true</jk> if the specified annotation is present.
         */
        public <A extends Annotation> boolean hasAnnotation(AnnotationProvider 
annotationProvider, Class<A> type) {
-               return nn(annotationProvider.firstAnnotation(type, f, x -> 
true));
+               // Inline Context.firstAnnotation() call
+               return nn(annotationProvider.getAnnotationProvider().find(type, 
f).map(x -> x.inner()).filter(x -> true).findFirst().orElse(null));
        }
 
        /**
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 e32b32fbbf..a827b9e688 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
@@ -475,8 +475,9 @@ public class MethodInfo extends ExecutableInfo implements 
Comparable<MethodInfo>
         * @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.firstAnnotation(type, 
m2.inner(), x -> true))
+                       .map(m2 -> 
annotationProvider.getAnnotationProvider().find(type, m2.inner()).map(x -> 
x.inner()).filter(x -> true).findFirst().orElse(null))
                        .filter(Objects::nonNull)
                        .findFirst()
                        .orElse(null);
@@ -588,8 +589,9 @@ public class MethodInfo extends ExecutableInfo implements 
Comparable<MethodInfo>
         * @return <jk>true</jk> if the specified annotation is present on this 
method.
         */
        public <A extends Annotation> boolean hasAnnotation(AnnotationProvider 
annotationProvider, Class<A> type) {
+               // Inline Context.firstAnnotation() call
                for (var m2 : matchingCache.get())
-                       if (nn(annotationProvider.firstAnnotation(type, 
m2.inner(), x -> true)))
+                       if 
(nn(annotationProvider.getAnnotationProvider().find(type, m2.inner()).map(x -> 
x.inner()).filter(x -> true).findFirst().orElse(null)))
                                return true;
                return false;
        }
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 0678497c22..07ce20942d 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
@@ -182,8 +182,9 @@ public class BeanMeta<T> {
                private String findPropertyName(Field f) {
                        List<Beanp> lp = list();
                        List<Name> ln = list();
-                       ctx.forEachAnnotation(Beanp.class, f, x -> true, x -> 
lp.add(x));
-                       ctx.forEachAnnotation(Name.class, f, x -> true, x -> 
ln.add(x));
+                       // Inline Context.forEachAnnotation() calls
+                       ctx.getAnnotationProvider().find(Beanp.class, f).map(x 
-> x.inner()).filter(x -> true).forEach(x -> lp.add(x));
+                       ctx.getAnnotationProvider().find(Name.class, f).map(x 
-> x.inner()).filter(x -> true).forEach(x -> ln.add(x));
                        String name = bpName(lp, ln);
                        if (isNotEmpty(name))
                                return name;
@@ -252,7 +253,8 @@ public class BeanMeta<T> {
                                                throw new 
BeanRuntimeException(c, "Multiple instances of '@Beanc' found.");
                                        constructor = x;
                                        constructorArgs = new String[0];
-                                       ctx.forEachAnnotation(Beanc.class, 
x.inner(), y -> ! y.properties().isEmpty(), z -> constructorArgs = 
splita(z.properties()));
+                                       // Inline Context.forEachAnnotation() 
call
+                               ctx.getAnnotationProvider().find(Beanc.class, 
x.inner()).map(x2 -> x2.inner()).filter(y -> ! 
y.properties().isEmpty()).forEach(z -> constructorArgs = 
splita(z.properties()));
                                        if (! 
x.hasNumParameters(constructorArgs.length)) {
                                                if (constructorArgs.length != 0)
                                                throw new 
BeanRuntimeException(c, "Number of properties defined in '@Beanc' annotation 
does not match number of parameters in constructor.");
@@ -275,7 +277,8 @@ public class BeanMeta<T> {
                                                        throw new 
BeanRuntimeException(c, "Multiple instances of '@Beanc' found.");
                                                constructor = x;
                                                constructorArgs = new String[0];
-                                               
ctx.forEachAnnotation(Beanc.class, x.inner(), y -> ! y.properties().isEmpty(), 
z -> constructorArgs = splita(z.properties()));
+                                               // Inline 
Context.forEachAnnotation() call
+                               ctx.getAnnotationProvider().find(Beanc.class, 
x.inner()).map(x2 -> x2.inner()).filter(y -> ! 
y.properties().isEmpty()).forEach(z -> constructorArgs = 
splita(z.properties()));
                                                if (! 
x.hasNumParameters(constructorArgs.length)) {
                                                        if 
(constructorArgs.length != 0)
                                                        throw new 
BeanRuntimeException(c, "Number of properties defined in '@Beanc' annotation 
does not match number of parameters in constructor.");
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
index d6874cbf8d..625fbcc743 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
@@ -220,7 +220,8 @@ public class BeanPropertyMeta implements 
Comparable<BeanPropertyMeta> {
 
                        if (nn(innerField)) {
                                List<Beanp> lp = list();
-                               bc.forEachAnnotation(Beanp.class, innerField, x 
-> true, x -> lp.add(x));
+                               // Inline Context.forEachAnnotation() call
+                               bc.getAnnotationProvider().find(Beanp.class, 
innerField).map(x -> x.inner()).filter(x -> true).forEach(x -> lp.add(x));
                                if (nn(field) || isNotEmpty(lp)) {
                                        // Only use field type if it's a bean 
property or has @Beanp annotation.
                                        // Otherwise, we want to infer the type 
from the getter or setter.
@@ -238,8 +239,9 @@ public class BeanPropertyMeta implements 
Comparable<BeanPropertyMeta> {
                                        if (! x.wo().isEmpty())
                                                writeOnly = 
Boolean.valueOf(x.wo());
                                });
-                               bc.forEachAnnotation(Swap.class, innerField, x 
-> true, x -> swap = getPropertySwap(x));
-                               isUri |= nn(bc.firstAnnotation(Uri.class, 
innerField, x -> true));
+                               // Inline Context.forEachAnnotation() call
+                               bc.getAnnotationProvider().find(Swap.class, 
innerField).map(x -> x.inner()).filter(x -> true).forEach(x -> swap = 
getPropertySwap(x));
+                               isUri |= 
nn(bc.getAnnotationProvider().find(Uri.class, innerField).map(x -> 
x.inner()).filter(x -> true).findFirst().orElse(null));
                        }
 
                        if (nn(getter)) {
@@ -635,9 +637,9 @@ public class BeanPropertyMeta implements 
Comparable<BeanPropertyMeta> {
        public <A extends Annotation> BeanPropertyMeta 
forEachAnnotation(Class<A> a, Predicate<A> filter, Consumer<A> action) {
                BeanContext bc = beanContext;
                if (nn(a)) {
-                       if (nn(field)) bc.forEachAnnotation(a, field, filter, 
action);
-                       if (nn(getter)) bc.forEachAnnotation(a, getter, filter, 
action);
-                       if (nn(setter)) bc.forEachAnnotation(a, setter, filter, 
action);
+                       if (nn(field)) bc.getAnnotationProvider().find(a, 
field).map(x -> x.inner()).filter(filter).forEach(action);
+                       if (nn(getter)) bc.getAnnotationProvider().find(a, 
getter).map(x -> x.inner()).filter(filter).forEach(action);
+                       if (nn(setter)) bc.getAnnotationProvider().find(a, 
setter).map(x -> x.inner()).filter(filter).forEach(action);
                }
                return this;
        }
@@ -679,7 +681,7 @@ public class BeanPropertyMeta implements 
Comparable<BeanPropertyMeta> {
                        return l;
                getBeanMeta().getClassMeta().getInfo().forEachAnnotation(bc, a, 
x -> true, x -> l.add(x));
                if (nn(field)) {
-                       bc.forEachAnnotation(a, field, x -> true, x -> 
l.add(x));
+                       bc.getAnnotationProvider().find(a, field).map(x -> 
x.inner()).filter(x -> true).forEach(x -> l.add(x));
                        ClassInfo.of(field.getType()).forEachAnnotation(bc, a, 
x -> true, x -> l.add(x));
                }
                if (nn(getter)) {
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 152869c968..77993e7e06 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
@@ -362,7 +362,8 @@ public class ClassMeta<T> implements Type {
                                invocationHandler = new 
BeanProxyInvocationHandler<T>(beanMeta);
 
                        if (nn(bc)) {
-                               bc.forEachAnnotation(Bean.class, c, x -> true, 
x -> {
+                               // Inline Context.forEachAnnotation() call
+                               bc.getAnnotationProvider().find(Bean.class, 
c).map(x -> x.inner()).filter(x -> true).forEach(x -> {
                                        if (x.dictionary().length != 0)
                                                beanRegistry = new 
BeanRegistry(bc, null, x.dictionary());
                                        // This could be a non-bean POJO with a 
type name.
@@ -372,7 +373,8 @@ public class ClassMeta<T> implements Type {
                        }
 
                        if (example == null && nn(bc)) {
-                               bc.forEachAnnotation(Example.class, c, x -> ! 
x.value().isEmpty(), x -> example = x.value());
+                               // Inline Context.forEachAnnotation() call
+                               bc.getAnnotationProvider().find(Example.class, 
c).map(x -> x.inner()).filter(x -> ! x.value().isEmpty()).forEach(x -> example 
= x.value());
                        }
 
                        if (example == null) {
@@ -494,8 +496,9 @@ public class ClassMeta<T> implements Type {
 
                private void findSwaps(List<ObjectSwap> l, BeanContext bc) {
 
-                       if (nn(bc))
-                               bc.forEachAnnotation(Swap.class, innerClass, x 
-> true, x -> l.add(createSwap(x)));
+               if (nn(bc))
+                       // Inline Context.forEachAnnotation() call
+                       bc.getAnnotationProvider().find(Swap.class, 
innerClass).map(x -> x.inner()).filter(x -> true).forEach(x -> 
l.add(createSwap(x)));
 
                        ObjectSwap defaultSwap = DefaultSwaps.find(ci);
                        if (defaultSwap == null)
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
index ae0d1f7cf1..e35c872bc1 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
@@ -814,32 +814,32 @@ public abstract class Context implements 
AnnotationProvider {
 
        @Override /* Overridden from MetaProvider */
        public <A extends Annotation> A firstAnnotation(Class<A> type, Class<?> 
onClass, Predicate<A> filter) {
-               return getAnnotationProvider().find(type, onClass).map(x -> 
x.inner()).filter(x -> filter.test(x)).findFirst().orElse(null);
+               throw unsupportedOp();
        }
 
        @Override /* Overridden from MetaProvider */
        public <A extends Annotation> A firstAnnotation(Class<A> type, 
Constructor<?> onConstructor, Predicate<A> filter) {
-               return getAnnotationProvider().find(type, onConstructor).map(x 
-> x.inner()).filter(x -> filter.test(x)).findFirst().orElse(null);
+               throw unsupportedOp();
        }
 
        @Override /* Overridden from MetaProvider */
        public <A extends Annotation> A firstAnnotation(Class<A> type, Field 
onField, Predicate<A> filter) {
-               return getAnnotationProvider().find(type, onField).map(x -> 
x.inner()).filter(x -> filter.test(x)).findFirst().orElse(null);
+               throw unsupportedOp();
        }
 
        @Override /* Overridden from MetaProvider */
        public <A extends Annotation> A firstAnnotation(Class<A> type, Method 
onMethod, Predicate<A> filter) {
-               return getAnnotationProvider().find(type, onMethod).map(x -> 
x.inner()).filter(x -> filter.test(x)).findFirst().orElse(null);
+               throw unsupportedOp();
        }
 
        @Override /* Overridden from MetaProvider */
        public <A extends Annotation> A firstDeclaredAnnotation(Class<A> type, 
Class<?> onClass, Predicate<A> filter) {
-               return getAnnotationProvider().findDeclared(type, 
onClass).map(x -> x.inner()).filter(x -> 
filter.test(x)).findFirst().orElse(null);
+               throw unsupportedOp();
        }
 
        @Override /* Overridden from MetaProvider */
        public <A extends Annotation> void forEachAnnotation(Class<A> type, 
Class<?> onClass, Predicate<A> filter, Consumer<A> action) {
-               getAnnotationProvider().find(type, onClass).map(x -> 
x.inner()).filter(x -> filter.test(x)).forEach(x -> action.accept(x));
+               throw unsupportedOp();
        }
 
        @Override /* Overridden from MetaProvider */
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/BuilderSwap.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/BuilderSwap.java
index cc103eed10..895b04150d 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/BuilderSwap.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/BuilderSwap.java
@@ -97,7 +97,7 @@ public class BuilderSwap<T,B> {
                ConstructorInfo objectConstructor = null;
                ConstructorInfo builderConstructor;
 
-               
bc.forEachAnnotation(org.apache.juneau.annotation.Builder.class, objectClass, x 
-> isNotVoid(x.value()), x -> builderClass.set(x.value()));
+               
bc.getAnnotationProvider().find(org.apache.juneau.annotation.Builder.class, 
objectClass).map(x -> x.inner()).filter(x -> isNotVoid(x.value())).forEach(x -> 
builderClass.set(x.value()));
 
                var pci = ClassInfo.of(objectClass);
 
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanMeta.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanMeta.java
index 45bdbd15f4..27345722a1 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanMeta.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanMeta.java
@@ -46,7 +46,7 @@ public class XmlBeanMeta extends ExtendedBeanMeta {
                        Class<?> c = beanMeta.getClassMeta().getInnerClass();
                        Value<XmlFormat> defaultFormat = Value.empty();
 
-                       mp.forEachAnnotation(Xml.class, c, x -> true, x -> {
+                       mp.getAnnotationProvider().find(Xml.class, c).map(x -> 
x.inner()).filter(x -> true).forEach(x -> {
                                XmlFormat xf = x.format();
                                if (xf == ATTRS)
                                        defaultFormat.set(XmlFormat.ATTR);

Reply via email to