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

commit 08a1ece7dec4827bbdcead35983c7c5d8ffa2f56
Author: James Bognar <[email protected]>
AuthorDate: Mon Nov 17 11:04:33 2025 -0500

    org.apache.juneau.common.reflect API improvements
---
 .../juneau/common/reflect/AnnotationInfo.java      | 25 ++--------------------
 .../rest/client/remote/RemoteOperationMeta.java    |  8 +++----
 .../rest/client/remote/RemoteOperationReturn.java  |  2 +-
 .../juneau/rest/debug/BasicDebugEnablement.java    | 23 +++++++-------------
 .../juneau/rest/matcher/ClientVersionMatcher.java  |  2 +-
 .../rest/swagger/BasicSwaggerProviderSession.java  |  6 +++---
 6 files changed, 19 insertions(+), 47 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 a9f802da18..4a80de0efe 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
@@ -19,7 +19,6 @@ package org.apache.juneau.common.reflect;
 import static org.apache.juneau.common.utils.AssertionUtils.*;
 import static org.apache.juneau.common.utils.ClassUtils.*;
 import static org.apache.juneau.common.utils.CollectionUtils.*;
-import static org.apache.juneau.common.utils.PredicateUtils.*;
 import static org.apache.juneau.common.utils.ThrowableUtils.*;
 import static org.apache.juneau.common.utils.Utils.*;
 
@@ -82,24 +81,6 @@ public class AnnotationInfo<T extends Annotation> {
                return rank;
        }
 
-       /**
-        * Performs an action on all matching values on this annotation.
-        *
-        * @param <V> The annotation field type.
-        * @param type The annotation field type.
-        * @param name The annotation field name.
-        * @param test A predicate to apply to the value to determine if action 
should be performed.  Can be <jk>null</jk>.
-        * @param action An action to perform on the value.
-        * @return This object.
-        */
-       @SuppressWarnings("unchecked")
-       public <V> AnnotationInfo<?> forEachValue(Class<V> type, String name, 
Predicate<V> test, Consumer<V> action) {
-               methods.get().stream()
-                       .filter(m -> eq(m.getName(), name) && 
eq(m.getReturnType().inner(), type))
-                       .forEach(m -> safe(() -> consumeIf(test, action, 
(V)m.invoke(a))));
-               return this;
-       }
-
        /**
         * Returns the class name of the annotation.
         *
@@ -113,15 +94,13 @@ public class AnnotationInfo<T extends Annotation> {
         * @param <V> The annotation field type.
         * @param type The annotation field type.
         * @param name The annotation field name.
-        * @param test A predicate to apply to the value to determine if value 
should be used.  Can be <jk>null</jk>.
-        * @return This object.
+        * @return An optional containing the value, or empty if not found.
         */
        @SuppressWarnings("unchecked")
-       public <V> Optional<V> getValue(Class<V> type, String name, 
Predicate<V> test) {
+       public <V> Optional<V> getValue(Class<V> type, String name) {
                return methods.get().stream()
                        .filter(m -> eq(m.getName(), name) && 
eq(m.getReturnType().inner(), type))
                        .map(m -> safe(() -> (V)m.invoke(a)))
-                       .filter(v -> test(test, v))
                        .findFirst();
        }
 
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationMeta.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationMeta.java
index 82d3ab0657..c535563e2c 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationMeta.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationMeta.java
@@ -72,8 +72,8 @@ public class RemoteOperationMeta {
                        var _httpMethod = Value.<String>empty();
                        var _path = Value.<String>empty();
                        al.stream().map(x -> 
x.getName().substring(6).toUpperCase()).filter(x -> ! x.equals("OP")).forEach(x 
-> _httpMethod.set(x));
-                       al.forEach(ai -> ai.forEachValue(String.class, 
"method", NOT_EMPTY, x -> _httpMethod.set(x.trim().toUpperCase())));
-                       al.forEach(ai -> ai.forEachValue(String.class, "path", 
NOT_EMPTY, x -> _path.set(x.trim())));
+                       al.forEach(ai -> ai.getValue(String.class, 
"method").filter(NOT_EMPTY).ifPresent(x -> 
_httpMethod.set(x.trim().toUpperCase())));
+                       al.forEach(ai -> ai.getValue(String.class, 
"path").filter(NOT_EMPTY).ifPresent(x -> _path.set(x.trim())));
                        httpMethod = _httpMethod.orElse("").trim();
                        path = _path.orElse("").trim();
 
@@ -90,8 +90,8 @@ public class RemoteOperationMeta {
                                        path = v.substring(i).trim();
                                }
                        } else {
-                               al.stream().filter(x -> ! 
x.isType(RemoteOp.class) && isNotEmpty(x.getValue(String.class, "value", 
NOT_EMPTY).orElse("").trim()))
-                                       .forEach(x -> 
value.set(x.getValue(String.class, "value", NOT_EMPTY).get().trim()));
+                               al.stream().filter(x -> ! 
x.isType(RemoteOp.class) && isNotEmpty(x.getValue(String.class, 
"value").filter(NOT_EMPTY).orElse("").trim()))
+                                       .forEach(x -> 
value.set(x.getValue(String.class, "value").filter(NOT_EMPTY).get().trim()));
                                if (value.isPresent())
                                        path = value.get();
                        }
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationReturn.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationReturn.java
index 5ef11c76a7..a982b76ece 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationReturn.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationReturn.java
@@ -67,7 +67,7 @@ public class RemoteOperationReturn {
                        rv = RemoteReturn.NONE;
                } else {
                        Value<RemoteReturn> v = Value.of(RemoteReturn.BODY);
-                       al.forEach(ai -> ai.forEachValue(RemoteReturn.class, 
"returns", x -> true, x -> v.set(x)));
+                       al.forEach(ai -> ai.getValue(RemoteReturn.class, 
"returns").ifPresent(x -> v.set(x)));
                        rv = v.get();
                }
 
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/debug/BasicDebugEnablement.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/debug/BasicDebugEnablement.java
index a17300a2e9..b7fd804728 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/debug/BasicDebugEnablement.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/debug/BasicDebugEnablement.java
@@ -85,21 +85,14 @@ public class BasicDebugEnablement extends DebugEnablement {
                // Gather @RestOp(debug) settings.
                // @formatter:off
                ci.getPublicMethods().stream()
-                       .forEach(x -> {
-                               
rstream(x.getAllAnnotationInfos()).filter(REST_OP_GROUP).forEach(ai -> {
-                                               ai.forEachValue(
-                                                       String.class,
-                                                       "debug",
-                                                       y -> true,
-                                                       y -> {
-                                                               String y2 = 
varResolver.resolve(y);
-                                                               if (! 
y2.isEmpty())
-                                                                       
b.enable(Enablement.fromString(y2), x.getFullName());
-                                                       }
-                                               );
-                               });
-                       }
-               );
+                       .forEach(x -> 
+                               rstream(x.getAllAnnotationInfos())
+                                       .filter(REST_OP_GROUP)
+                                       .flatMap(ai -> 
ai.getValue(String.class, "debug").stream())
+                                       .map(varResolver::resolve)
+                                       .filter(y -> ! y.isEmpty())
+                                       .forEach(y -> 
b.enable(Enablement.fromString(y), x.getFullName()))
+                       );
                // @formatter:on
 
                // Gather @Rest(debugOn) settings.
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/matcher/ClientVersionMatcher.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/matcher/ClientVersionMatcher.java
index 482ebf29f2..a65991f41a 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/matcher/ClientVersionMatcher.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/matcher/ClientVersionMatcher.java
@@ -51,7 +51,7 @@ public class ClientVersionMatcher extends RestMatcher {
        public ClientVersionMatcher(String clientVersionHeader, MethodInfo mi) {
                this.clientVersionHeader = isEmpty(clientVersionHeader) ? 
"Client-Version" : clientVersionHeader;
                Value<String> clientVersion = Value.empty();
-               
rstream(mi.getAllAnnotationInfos()).filter(REST_OP_GROUP).forEach(ai -> 
ai.forEachValue(String.class, "clientVersion", NOT_EMPTY, x -> 
clientVersion.set(x)));
+               
rstream(mi.getAllAnnotationInfos()).filter(REST_OP_GROUP).forEach(ai -> 
ai.getValue(String.class, "clientVersion").filter(NOT_EMPTY).ifPresent(x -> 
clientVersion.set(x)));
                range = new VersionRange(clientVersion.orElse(null));
        }
 
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 1acfa0000c..5f3857146b 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
@@ -283,7 +283,7 @@ public class BasicSwaggerProviderSession {
 
                        // Add @RestOp(swagger)
                        Value<OpSwagger> _ms = Value.empty();
-                       al.forEach(ai -> ai.forEachValue(OpSwagger.class, 
"swagger", OpSwaggerAnnotation::notEmpty, x -> _ms.set(x)));
+                       al.forEach(ai -> ai.getValue(OpSwagger.class, 
"swagger").filter(OpSwaggerAnnotation::notEmpty).ifPresent(x -> _ms.set(x)));
                        OpSwagger ms = _ms.orElseGet(() -> 
OpSwaggerAnnotation.create().build());
 
                        op.append(parseMap(ms.value(), "@OpSwagger(value) on 
class {0} method {1}", c, m));
@@ -296,7 +296,7 @@ public class BasicSwaggerProviderSession {
                        );
 
                        Value<String> _summary = Value.empty();
-                       al.forEach(ai -> ai.forEachValue(String.class, 
"summary", NOT_EMPTY, x -> _summary.set(x)));
+                       al.forEach(ai -> ai.getValue(String.class, 
"summary").filter(NOT_EMPTY).ifPresent(x -> _summary.set(x)));
                        op.appendIf(ne, "summary",
                                firstNonEmpty(
                                        resolve(ms.summary()),
@@ -307,7 +307,7 @@ public class BasicSwaggerProviderSession {
                        );
 
                        Value<String[]> _description = Value.empty();
-                       al.forEach(ai -> ai.forEachValue(String[].class, 
"description", x -> x.length > 0, x -> _description.set(x)));
+                       al.forEach(ai -> ai.getValue(String[].class, 
"description").filter(x -> x.length > 0).ifPresent(x -> _description.set(x)));
                        op.appendIf(ne, "description",
                                firstNonEmpty(
                                        resolve(ms.description()),

Reply via email to