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

commit 90ee69dfb8ff4d089ee5f4b660a7a97aa655a0c7
Author: James Bognar <[email protected]>
AuthorDate: Fri Nov 7 12:13:20 2025 -0500

    Utility class modernization
---
 .../juneau/common/reflect/AnnotationInfo.java      |  2 +-
 .../apache/juneau/common/reflect/ClassInfo.java    | 58 +++++++++++++++++++---
 .../src/main/java/org/apache/juneau/ClassMeta.java |  8 +--
 .../java/org/apache/juneau/swap/AutoListSwap.java  |  6 +--
 .../java/org/apache/juneau/swap/AutoMapSwap.java   |  6 +--
 .../org/apache/juneau/swap/AutoNumberSwap.java     |  6 +--
 .../org/apache/juneau/swap/AutoObjectSwap.java     |  6 +--
 .../java/org/apache/juneau/rest/RestContext.java   |  8 +--
 .../rest/swagger/BasicSwaggerProviderSession.java  | 18 +++----
 .../juneau/common/reflect/ClassInfo_Test.java      |  6 +--
 10 files changed, 85 insertions(+), 39 deletions(-)

diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationInfo.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationInfo.java
index c84e043360..650ce6ed96 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationInfo.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationInfo.java
@@ -414,7 +414,7 @@ public class AnnotationInfo<T extends Annotation> {
        
//-----------------------------------------------------------------------------------------------------------------
 
        private static int findRank(Object a) {
-               return ClassInfo.of(a).getMethods().stream()
+               return ClassInfo.of(a).getAllMethods().stream()
                        .filter(m -> m.hasName("rank") && m.getParameterCount() 
== 0 && m.hasReturnType(int.class))
                        .findFirst()
                        .map(m -> safe(() -> (int)m.invoke(a)))
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 deaaff446c..447e82bfd5 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
@@ -623,8 +623,24 @@ public class ClassInfo extends ElementInfo implements 
Annotatable {
        /**
         * Returns all methods declared on this class.
         *
+        * <p>
+        * This method returns methods of <b>all visibility levels</b> (public, 
protected, package-private, and private)
+        * declared directly on this class only (does not include inherited 
methods).
+        *
+        * <h5 class='section'>Comparison with Similar Methods:</h5>
+        * <ul class='spaced-list'>
+        *      <li>{@link #getDeclaredMethods()} - Returns all declared 
methods on this class only (all visibility levels) ← This method
+        *      <li>{@link #getAllMethods()} - Returns all declared methods on 
this class and parents (all visibility levels)
+        *      <li>{@link #getPublicMethods()} - Returns public methods only 
on this class and parents
+        * </ul>
+        *
+        * <h5 class='section'>Notes:</h5>
+        * <ul class='spaced-list'>
+        *      <li>Unlike Java's {@link Class#getDeclaredMethods()}, results 
are filtered to exclude synthetic methods like <c>$jacocoInit</c>.
+        * </ul>
+        *
         * @return
-        *      All methods declared on this class.
+        *      All methods declared on this class (all visibility levels).
         *      <br>Results are ordered alphabetically.
         *      <br>List is unmodifiable.
         */
@@ -785,12 +801,28 @@ public class ClassInfo extends ElementInfo implements 
Annotatable {
        /**
         * Returns all declared methods on this class and all parent classes.
         *
+        * <p>
+        * This method returns methods of <b>all visibility levels</b> (public, 
protected, package-private, and private).
+        *
+        * <h5 class='section'>Comparison with Similar Methods:</h5>
+        * <ul class='spaced-list'>
+        *      <li>{@link #getDeclaredMethods()} - Returns all declared 
methods on this class only (all visibility levels)
+        *      <li>{@link #getAllMethods()} - Returns all declared methods on 
this class and parents (all visibility levels) ← This method
+        *      <li>{@link #getPublicMethods()} - Returns public methods only 
on this class and parents
+        * </ul>
+        *
+        * <h5 class='section'>Notes:</h5>
+        * <ul class='spaced-list'>
+        *      <li>Unlike Java's {@link Class#getMethods()}, this returns 
methods of all visibility levels, not just public ones.
+        *      <li>Methods from {@link Object} class are excluded from the 
results.
+        * </ul>
+        *
         * @return
-        *      All declared methods on this class and all parent classes.
+        *      All declared methods on this class and all parent classes (all 
visibility levels).
         *      <br>Results are ordered child-to-parent, and then 
alphabetically per class.
         *      <br>List is unmodifiable.
         */
-       public List<MethodInfo> getMethods() { return allMethods.get(); }
+       public List<MethodInfo> getAllMethods() { return allMethods.get(); }
 
        /**
         * Returns the name of the underlying class.
@@ -1091,14 +1123,28 @@ public class ClassInfo extends ElementInfo implements 
Annotatable {
        }
 
        /**
-        * Returns all public methods on this class.
+        * Returns all public methods on this class and parent classes.
         *
         * <p>
-        * Methods defined on the {@link Object} class are excluded from the 
results.
+        * This method returns <b>public methods only</b>, from this class and 
all parent classes and interfaces.
+        *
+        * <h5 class='section'>Comparison with Similar Methods:</h5>
+        * <ul class='spaced-list'>
+        *      <li>{@link #getDeclaredMethods()} - Returns all declared 
methods on this class only (all visibility levels)
+        *      <li>{@link #getAllMethods()} - Returns all declared methods on 
this class and parents (all visibility levels)
+        *      <li>{@link #getPublicMethods()} - Returns public methods only 
on this class and parents ← This method
+        * </ul>
+        *
+        * <h5 class='section'>Notes:</h5>
+        * <ul class='spaced-list'>
+        *      <li>This method behaves similarly to Java's {@link 
Class#getMethods()}, returning only public methods.
+        *      <li>Methods defined on the {@link Object} class are excluded 
from the results.
+        * </ul>
         *
         * @return
-        *      All public methods on this class.
+        *      All public methods on this class and parent classes.
         *      <br>Results are ordered alphabetically.
+        *      <br>List is unmodifiable.
         */
        public List<MethodInfo> getPublicMethods() { return 
publicMethods.get(); }
 
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 201c8e3331..4b001e3e83 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
@@ -224,10 +224,10 @@ public class ClassMeta<T> implements Type {
                                exampleField = x.accessible().inner();
                        });
 
-                       // Find @NameProperty and @ParentProperty methods if 
present.
-                       List<MethodInfo> methods = ci.getMethods();
-                       for (int i = methods.size() - 1; i >= 0; i--) {
-                               MethodInfo m = methods.get(i);
+               // Find @NameProperty and @ParentProperty methods if present.
+               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.isStatic() || ! 
m.hasNumParameters(1))
                                                throw new 
ClassMetaRuntimeException(c, "@ParentProperty used on invalid method ''{0}''.  
Must not be static and have one argument.", m);
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 5542d3e43e..e999dd0f8f 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
@@ -103,9 +103,9 @@ public class AutoListSwap<T> extends ObjectSwap<T,List<?>> {
                if (shouldIgnore(bc, ci))
                        return null;
 
-               // Find swap() method if present.
-               for (var m : ci.getMethods()) {
-                       if (isSwapMethod(bc, m)) {
+       // Find swap() method if present.
+       for (var m : ci.getAllMethods()) {
+               if (isSwapMethod(bc, m)) {
 
                                var rt = m.getReturnType();
 
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 84903260a9..00b4390678 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
@@ -103,9 +103,9 @@ public class AutoMapSwap<T> extends ObjectSwap<T,Map<?,?>> {
                if (shouldIgnore(bc, ci))
                        return null;
 
-               // Find swap() method if present.
-               for (var m : ci.getMethods()) {
-                       if (isSwapMethod(bc, m)) {
+       // Find swap() method if present.
+       for (var m : ci.getAllMethods()) {
+               if (isSwapMethod(bc, m)) {
 
                                var rt = m.getReturnType();
 
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 ea4eba6af8..86d7cde769 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
@@ -126,10 +126,10 @@ public class AutoNumberSwap<T> extends 
ObjectSwap<T,Number> {
                if (shouldIgnore(bc, ci))
                        return null;
 
-               // Find swap() method if present.
-               for (var m : ci.getMethods()) {
+       // Find swap() method if present.
+       for (var m : ci.getAllMethods()) {
 
-                       if (isSwapMethod(bc, m)) {
+               if (isSwapMethod(bc, m)) {
 
                                ClassInfo rt = m.getReturnType();
 
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 ccb8001196..e5c9ee0859 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
@@ -105,9 +105,9 @@ public class AutoObjectSwap<T> extends ObjectSwap<T,Object> 
{
                if (shouldIgnore(bc, ci))
                        return null;
 
-               // Find swap() method if present.
-               for (var m : ci.getMethods()) {
-                       if (isSwapMethod(bc, m)) {
+       // Find swap() method if present.
+       for (var m : ci.getAllMethods()) {
+               if (isSwapMethod(bc, m)) {
 
                                ClassInfo rt = m.getReturnType();
 
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index 65c58d7b08..b47e0efbf7 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -1770,11 +1770,11 @@ public class RestContext extends Context {
                                        
RestInjectAnnotation.name(x.getAnnotationInfos(RestInject.class).findFirst().map(AnnotationInfo::inner).orElse(null))
                                )
                        ));
-                       // @formatter:on
+               // @formatter:on
 
-                       rci.getMethods().stream().filter(x -> 
x.hasAnnotation(RestInject.class)).forEach(x -> {
-                               var rt = x.getReturnType().<Object>inner();
-                               var name = 
RestInjectAnnotation.name(x.getAnnotationInfos(RestInject.class).findFirst().map(AnnotationInfo::inner).orElse(null));
+               rci.getAllMethods().stream().filter(x -> 
x.hasAnnotation(RestInject.class)).forEach(x -> {
+                       var rt = x.getReturnType().<Object>inner();
+                       var name = 
RestInjectAnnotation.name(x.getAnnotationInfos(RestInject.class).findFirst().map(AnnotationInfo::inner).orElse(null));
                                if (! (DELAYED_INJECTION.contains(rt) || 
DELAYED_INJECTION_NAMES.contains(name))) {
                                        // @formatter:off
                                        beanStore
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 065977e041..303fd0e0ee 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
@@ -447,11 +447,11 @@ public class BasicSwaggerProviderSession {
                                                        
rstream(eci.getAnnotationInfos()).map(x -> 
x.cast(Schema.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
 -> merge(schema, x));
                                                        
pushupSchemaFields(RESPONSE, om, schema);
                                                        om.appendIf(nem, 
"schema", schema);
-                                               }
                                        }
-                                       List<MethodInfo> methods = 
eci.getMethods();
-                                       for (int i = methods.size() - 1; i >= 
0; i--) {
-                                               MethodInfo ecmi = 
methods.get(i);
+                               }
+                               List<MethodInfo> methods = eci.getAllMethods();
+                               for (int i = methods.size() - 1; i >= 0; i--) {
+                                       MethodInfo ecmi = methods.get(i);
                                                Header a = 
ecmi.getAnnotationInfos(Header.class).findFirst().map(AnnotationInfo::inner).orElse(null);
                                                if (a == null)
                                                        a = 
ecmi.getReturnType().unwrap(Value.class, 
Optional.class).getAnnotationInfos(Header.class).findFirst().map(AnnotationInfo::inner).orElse(null);
@@ -484,11 +484,11 @@ public class BasicSwaggerProviderSession {
                                                om.appendIf(nem, "schema", 
schema);
                                                addBodyExamples(sm, om, true, 
m.getGenericReturnType(), locale);
                                        }
-                               }
-                               if 
(mi.getReturnType().hasAnnotation(Response.class)) {
-                                       List<MethodInfo> methods = 
mi.getReturnType().getMethods();
-                                       for (int i = methods.size() - 1; i >= 
0; i--) {
-                                               MethodInfo ecmi = 
methods.get(i);
+                       }
+                       if (mi.getReturnType().hasAnnotation(Response.class)) {
+                               List<MethodInfo> methods = 
mi.getReturnType().getAllMethods();
+                               for (int i = methods.size() - 1; i >= 0; i--) {
+                                       MethodInfo ecmi = methods.get(i);
                                                if 
(ecmi.hasAnnotation(Header.class)) {
                                                        Header a = 
ecmi.getAnnotationInfos(Header.class).findFirst().map(AnnotationInfo::inner).orElse(null);
                                                        String ha = a.name();
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
 
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
index a3fd7dedb3..550d30203b 100644
--- 
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
+++ 
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
@@ -322,12 +322,12 @@ public class ClassInfo_Test extends TestBase {
        }
 
        @Test void getAllMethods() {
-               
check("CC3.c3a(),CC3.c3b(),CC3.i2b(),CC2.c2a(),CC2.c2b(),CC2.i1b(),CC2.i2a(),CC2.i2b(),CC1.c1a(),CC1.c1b(),CC1.i1a(),CI1.i1a(),CI1.i1b(),CI2.i2a(),CI2.i2b()",
 cc3.getMethods());
+               
check("CC3.c3a(),CC3.c3b(),CC3.i2b(),CC2.c2a(),CC2.c2b(),CC2.i1b(),CC2.i2a(),CC2.i2b(),CC1.c1a(),CC1.c1b(),CC1.i1a(),CI1.i1a(),CI1.i1b(),CI2.i2a(),CI2.i2b()",
 cc3.getAllMethods());
        }
 
        @Test void getAllMethods_twice() {
-               
check("CC3.c3a(),CC3.c3b(),CC3.i2b(),CC2.c2a(),CC2.c2b(),CC2.i1b(),CC2.i2a(),CC2.i2b(),CC1.c1a(),CC1.c1b(),CC1.i1a(),CI1.i1a(),CI1.i1b(),CI2.i2a(),CI2.i2b()",
 cc3.getMethods());
-               
check("CC3.c3a(),CC3.c3b(),CC3.i2b(),CC2.c2a(),CC2.c2b(),CC2.i1b(),CC2.i2a(),CC2.i2b(),CC1.c1a(),CC1.c1b(),CC1.i1a(),CI1.i1a(),CI1.i1b(),CI2.i2a(),CI2.i2b()",
 cc3.getMethods());
+               
check("CC3.c3a(),CC3.c3b(),CC3.i2b(),CC2.c2a(),CC2.c2b(),CC2.i1b(),CC2.i2a(),CC2.i2b(),CC1.c1a(),CC1.c1b(),CC1.i1a(),CI1.i1a(),CI1.i1b(),CI2.i2a(),CI2.i2b()",
 cc3.getAllMethods());
+               
check("CC3.c3a(),CC3.c3b(),CC3.i2b(),CC2.c2a(),CC2.c2b(),CC2.i1b(),CC2.i2a(),CC2.i2b(),CC1.c1a(),CC1.c1b(),CC1.i1a(),CI1.i1a(),CI1.i1b(),CI2.i2a(),CI2.i2b()",
 cc3.getAllMethods());
        }
 
        @Test void getDeclaredMethods() {

Reply via email to