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

commit 08fb19d2ce60f6416cc03374c7aec6a11f22b749
Author: James Bognar <[email protected]>
AuthorDate: Tue Nov 18 13:02:34 2025 -0500

    org.apache.juneau.common.reflect API improvements
---
 .../java/org/apache/juneau/common/reflect/ClassInfo.java | 15 ---------------
 .../org/apache/juneau/common/reflect/MethodInfo.java     | 16 ----------------
 .../src/main/java/org/apache/juneau/BeanMeta.java        |  6 +++---
 .../src/main/java/org/apache/juneau/ClassMeta.java       |  8 ++++----
 .../main/java/org/apache/juneau/swap/AutoListSwap.java   |  6 +++---
 .../main/java/org/apache/juneau/swap/AutoMapSwap.java    |  6 +++---
 .../main/java/org/apache/juneau/swap/AutoNumberSwap.java |  6 +++---
 .../main/java/org/apache/juneau/swap/AutoObjectSwap.java |  6 +++---
 8 files changed, 19 insertions(+), 50 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 1c1dc58705..b7de067fab 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
@@ -1644,21 +1644,6 @@ public class ClassInfo extends ElementInfo implements 
Annotatable {
                return of(pmap1.get(inner));
        }
 
-       /**
-        * Returns <jk>true</jk> if this class has the specified annotation.
-        *
-        * @param <A> The annotation type to look for.
-        * @param annotationProvider The annotation provider.
-        * @param type The annotation to look for.
-        * @return The <jk>true</jk> if annotation if found.
-        */
-       public <A extends Annotation> boolean hasAnnotation(AnnotationProvider 
annotationProvider, Class<A> type) {
-               if (annotationProvider == null)
-                       throw unsupportedOp();
-               // Inline Context.firstAnnotation() call
-               return nn(annotationProvider.find(type, inner).map(x -> 
x.inner()).filter(x -> true).findFirst().orElse(null));
-       }
-
        /**
         * Returns <jk>true</jk> if this class has the specified annotation.
         *
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 ee7d44bd27..20aac2d9e3 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
@@ -464,22 +464,6 @@ public class MethodInfo extends ExecutableInfo implements 
Comparable<MethodInfo>
                return true;
        }
 
-       /**
-        * Returns <jk>true</jk> if the specified annotation is present on this 
method.
-        *
-        * @param <A> The annotation type to look for.
-        * @param annotationProvider The annotation provider.
-        * @param type The annotation to look for.
-        * @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 : getMatchingMethods())
-                       if (nn(annotationProvider.find(type, m2.inner()).map(x 
-> x.inner()).filter(x -> true).findFirst().orElse(null)))
-                               return true;
-               return false;
-       }
-
        /**
         * Returns <jk>true</jk> if the specified annotation is present on this 
method or any matching methods in parent classes/interfaces.
         *
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 cb7bf99151..c56d38babc 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
@@ -230,8 +230,8 @@ public class BeanMeta<T> {
 
                                Map<String,BeanPropertyMeta.Builder> 
normalProps = map();
 
-                               boolean hasBean = 
ci.hasAnnotation(ctx.getAnnotationProvider(), Bean.class);
-                               boolean hasBeanIgnore = 
ci.hasAnnotation(ctx.getAnnotationProvider(), BeanIgnore.class);
+                               boolean hasBean = 
ctx.getAnnotationProvider().find(Bean.class, 
ci.inner()).findFirst().isPresent();
+                               boolean hasBeanIgnore = 
ctx.getAnnotationProvider().find(BeanIgnore.class, 
ci.inner()).findFirst().isPresent();
 
                                /// See if this class matches one the patterns 
in the exclude-class list.
                                if (ctx.isNotABean(c))
@@ -593,7 +593,7 @@ public class BeanMeta<T> {
 
                forEachClass(ClassInfo.of(c), stopClass, c2 -> {
                        for (var m : c2.getDeclaredMethods()) {
-                               if (m.isStatic() || m.isBridge() || 
m.getParameterCount() > 2 || m.hasAnnotation(ctx.getAnnotationProvider(), 
BeanIgnore.class))
+                               if (m.isStatic() || m.isBridge() || 
m.getParameterCount() > 2 || m.getMatchingMethods().stream().anyMatch(m2 -> 
ctx.getAnnotationProvider().find(BeanIgnore.class, 
m2.inner()).findFirst().isPresent()))
                                        continue;
                                Transient t = m.getMatchingMethods().stream()
                                        .map(m2 -> 
ctx.getAnnotationProvider().find(Transient.class, m2.inner()).map(x -> 
x.inner()).filter(x -> true).findFirst().orElse(null))
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 f095966a28..2b177719f6 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
@@ -163,7 +163,7 @@ public class ClassMeta<T> implements Type {
                                        cc = DATE;
                                else if (c.isArray())
                                        cc = ARRAY;
-                               else if (ci.isChildOfAny(URL.class, URI.class) 
|| ci.hasAnnotation(bc.getAnnotationProvider(), Uri.class))
+                               else if (ci.isChildOfAny(URL.class, URI.class) 
|| bc.getAnnotationProvider().find(Uri.class, 
ci.inner()).findFirst().isPresent())
                                        cc = URI;
                                else if (ci.isChildOf(Reader.class))
                                        cc = READER;
@@ -226,13 +226,13 @@ public class ClassMeta<T> implements Type {
                List<MethodInfo> methods = ci.getAllMethods();
                for (int i = methods.size() - 1; i >= 0; i--) {
                        MethodInfo m = methods.get(i);
-                               if (m.hasAnnotation(bc.getAnnotationProvider(), 
ParentProperty.class)) {
+                               if (m.getMatchingMethods().stream().anyMatch(m2 
-> bc.getAnnotationProvider().find(ParentProperty.class, 
m2.inner()).findFirst().isPresent())) {
                                        if (m.isStatic() || ! 
m.hasNumParameters(1))
                                                throw new 
ClassMetaRuntimeException(c, "@ParentProperty used on invalid method ''{0}''.  
Must not be static and have one argument.", m);
                                        m.setAccessible();
                                        parentPropertyMethod = new 
Setter.MethodSetter(m.inner());
                                }
-                               if (m.hasAnnotation(bc.getAnnotationProvider(), 
NameProperty.class)) {
+                               if (m.getMatchingMethods().stream().anyMatch(m2 
-> bc.getAnnotationProvider().find(NameProperty.class, 
m2.inner()).findFirst().isPresent())) {
                                        if (m.isStatic() || ! 
m.hasNumParameters(1))
                                                throw new 
ClassMetaRuntimeException(c, "@NameProperty used on invalid method ''{0}''.  
Must not be static and have one argument.", m);
                                        m.setAccessible();
@@ -240,7 +240,7 @@ public class ClassMeta<T> implements Type {
                                }
                        }
 
-                       ci.getDeclaredMethods().stream().filter(m -> 
m.hasAnnotation(bc.getAnnotationProvider(), Example.class)).forEach(m -> {
+                       ci.getDeclaredMethods().stream().filter(m -> 
m.getMatchingMethods().stream().anyMatch(m2 -> 
bc.getAnnotationProvider().find(Example.class, 
m2.inner()).findFirst().isPresent())).forEach(m -> {
                                if (! (m.isStatic() && 
m.hasParameterTypesLenient(BeanSession.class) && 
ci.isParentOf(m.getReturnType().inner())))
                                        throw new ClassMetaRuntimeException(c, 
"@Example used on invalid method ''{0}''.  Must be static and return an 
instance of the declaring class.", m.toString());
                                m.setAccessible();
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoListSwap.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoListSwap.java
index 928792cfa5..5f05e97359 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoListSwap.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoListSwap.java
@@ -133,7 +133,7 @@ public class AutoListSwap<T> extends ObjectSwap<T,List<?>> {
                        && mi.hasAnyName(SWAP_METHOD_NAMES)
                        && mi.hasReturnTypeParent(List.class)
                        && mi.hasParameterTypesLenient(BeanSession.class)
-                       && ! mi.hasAnnotation(bc.getAnnotationProvider(), 
BeanIgnore.class);
+                       && ! mi.getMatchingMethods().stream().anyMatch(m2 -> 
bc.getAnnotationProvider().find(BeanIgnore.class, 
m2.inner()).findFirst().isPresent());
                // @formatter:on
        }
 
@@ -156,12 +156,12 @@ public class AutoListSwap<T> extends 
ObjectSwap<T,List<?>> {
                        && mi.hasAnyName(UNSWAP_METHOD_NAMES)
                        && mi.hasParameterTypesLenient(BeanSession.class, 
rt.inner())
                        && mi.hasReturnTypeParent(ci)
-                       && ! mi.hasAnnotation(bc.getAnnotationProvider(), 
BeanIgnore.class);
+                       && ! mi.getMatchingMethods().stream().anyMatch(m2 -> 
bc.getAnnotationProvider().find(BeanIgnore.class, 
m2.inner()).findFirst().isPresent());
                // @formatter:on
        }
 
        private static boolean shouldIgnore(BeanContext bc, ClassInfo ci) {
-               return ci.hasAnnotation(bc.getAnnotationProvider(), 
BeanIgnore.class) || ci.isNonStaticMemberClass();
+               return bc.getAnnotationProvider().find(BeanIgnore.class, 
ci.inner()).findFirst().isPresent() || ci.isNonStaticMemberClass();
        }
 
        
//------------------------------------------------------------------------------------------------------------------
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoMapSwap.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoMapSwap.java
index 871a648dde..6c500dfd5b 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoMapSwap.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoMapSwap.java
@@ -133,7 +133,7 @@ public class AutoMapSwap<T> extends ObjectSwap<T,Map<?,?>> {
                        && mi.hasAnyName(SWAP_METHOD_NAMES)
                        && mi.hasReturnTypeParent(Map.class)
                        && mi.hasParameterTypesLenient(BeanSession.class)
-                       && ! mi.hasAnnotation(bc.getAnnotationProvider(), 
BeanIgnore.class);
+                       && ! mi.getMatchingMethods().stream().anyMatch(m2 -> 
bc.getAnnotationProvider().find(BeanIgnore.class, 
m2.inner()).findFirst().isPresent());
                // @formatter:on
        }
 
@@ -156,12 +156,12 @@ public class AutoMapSwap<T> extends 
ObjectSwap<T,Map<?,?>> {
                        && mi.hasAnyName(UNSWAP_METHOD_NAMES)
                        && mi.hasParameterTypesLenient(BeanSession.class, 
rt.inner())
                        && mi.hasReturnTypeParent(ci)
-                       && !mi.hasAnnotation(bc.getAnnotationProvider(), 
BeanIgnore.class);
+                       && ! mi.getMatchingMethods().stream().anyMatch(m2 -> 
bc.getAnnotationProvider().find(BeanIgnore.class, 
m2.inner()).findFirst().isPresent());
                // @formatter:on
        }
 
        private static boolean shouldIgnore(BeanContext bc, ClassInfo ci) {
-               return ci.hasAnnotation(bc.getAnnotationProvider(), 
BeanIgnore.class) || ci.isNonStaticMemberClass();
+               return bc.getAnnotationProvider().find(BeanIgnore.class, 
ci.inner()).findFirst().isPresent() || ci.isNonStaticMemberClass();
        }
 
        
//------------------------------------------------------------------------------------------------------------------
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoNumberSwap.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoNumberSwap.java
index 45bfdb0345..991b298787 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoNumberSwap.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoNumberSwap.java
@@ -158,7 +158,7 @@ public class AutoNumberSwap<T> extends ObjectSwap<T,Number> 
{
                        && (rt.isChildOf(Number.class) || (rt.isPrimitive() && 
rt.isAny(int.class, short.class, long.class, float.class, double.class, 
byte.class)))
                        && mi.hasAnyName(SWAP_METHOD_NAMES)
                        && mi.hasParameterTypesLenient(BeanSession.class)
-                       && ! mi.hasAnnotation(bc.getAnnotationProvider(), 
BeanIgnore.class);
+                       && ! mi.getMatchingMethods().stream().anyMatch(m2 -> 
bc.getAnnotationProvider().find(BeanIgnore.class, 
m2.inner()).findFirst().isPresent());
                // @formatter:on
        }
 
@@ -181,14 +181,14 @@ public class AutoNumberSwap<T> extends 
ObjectSwap<T,Number> {
                        && mi.hasAnyName(UNSWAP_METHOD_NAMES)
                        && mi.hasParameterTypesLenient(BeanSession.class, 
rt.inner())
                        && mi.hasReturnTypeParent(ci)
-                       && ! mi.hasAnnotation(bc.getAnnotationProvider(), 
BeanIgnore.class);
+                       && ! mi.getMatchingMethods().stream().anyMatch(m2 -> 
bc.getAnnotationProvider().find(BeanIgnore.class, 
m2.inner()).findFirst().isPresent());
                // @formatter:on
        }
 
        private static boolean shouldIgnore(BeanContext bc, ClassInfo ci) {
                // @formatter:off
                return
-                       ci.hasAnnotation(bc.getAnnotationProvider(), 
BeanIgnore.class)
+                       bc.getAnnotationProvider().find(BeanIgnore.class, 
ci.inner()).findFirst().isPresent()
                        || ci.isNonStaticMemberClass()
                        || ci.isPrimitive()
                        || ci.isChildOf(Number.class);
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoObjectSwap.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoObjectSwap.java
index 53af77d0e2..96d8216b53 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoObjectSwap.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoObjectSwap.java
@@ -134,7 +134,7 @@ public class AutoObjectSwap<T> extends ObjectSwap<T,Object> 
{
                        && mi.isVisible(bc.getBeanMethodVisibility())
                        && mi.hasAnyName(SWAP_METHOD_NAMES)
                        && mi.hasParameterTypesLenient(BeanSession.class)
-                       && ! mi.hasAnnotation(bc.getAnnotationProvider(), 
BeanIgnore.class);
+                       && ! mi.getMatchingMethods().stream().anyMatch(m2 -> 
bc.getAnnotationProvider().find(BeanIgnore.class, 
m2.inner()).findFirst().isPresent());
                // @formatter:on
        }
 
@@ -157,12 +157,12 @@ public class AutoObjectSwap<T> extends 
ObjectSwap<T,Object> {
                        && mi.hasAnyName(UNSWAP_METHOD_NAMES)
                        && mi.hasParameterTypesLenient(BeanSession.class, 
rt.inner())
                        && mi.hasReturnTypeParent(ci)
-                       && ! mi.hasAnnotation(bc.getAnnotationProvider(), 
BeanIgnore.class);
+                       && ! mi.getMatchingMethods().stream().anyMatch(m2 -> 
bc.getAnnotationProvider().find(BeanIgnore.class, 
m2.inner()).findFirst().isPresent());
                // @formatter:on
        }
 
        private static boolean shouldIgnore(BeanContext bc, ClassInfo ci) {
-               return ci.hasAnnotation(bc.getAnnotationProvider(), 
BeanIgnore.class) || ci.isNonStaticMemberClass();
+               return bc.getAnnotationProvider().find(BeanIgnore.class, 
ci.inner()).findFirst().isPresent() || ci.isNonStaticMemberClass();
        }
 
        
//------------------------------------------------------------------------------------------------------------------

Reply via email to