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 fa7b1cdb76 Utility class modernization
fa7b1cdb76 is described below
commit fa7b1cdb76f31fd845775f974d1fb7e9354995eb
Author: James Bognar <[email protected]>
AuthorDate: Fri Nov 7 09:59:50 2025 -0500
Utility class modernization
---
.../apache/juneau/common/reflect/MethodInfo.java | 57 ++--------------------
.../juneau/common/reflect/ParameterInfo.java | 16 +++---
.../httppart/bean/RequestBeanPropertyMeta.java | 5 +-
.../juneau/httppart/bean/ResponseBeanMeta.java | 4 +-
.../java/org/apache/juneau/rest/RestContext.java | 4 +-
.../java/org/apache/juneau/rest/RestOpContext.java | 2 +-
.../juneau/common/reflect/MethodInfo_Test.java | 6 +--
7 files changed, 22 insertions(+), 72 deletions(-)
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 202574193d..d714e72dff 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
@@ -269,7 +269,7 @@ public class MethodInfo extends ExecutableInfo implements
Comparable<MethodInfo>
private List<AnnotationInfo<Annotation>> findAnnotationInfos() {
var list = new ArrayList<AnnotationInfo<Annotation>>();
- getMatching().forEach(m ->
list.addAll(m.getDeclaredAnnotationInfos()));
+ matchingCache.get().forEach(m ->
list.addAll(m.getDeclaredAnnotationInfos()));
return u(list);
}
@@ -282,13 +282,13 @@ public class MethodInfo extends ExecutableInfo implements
Comparable<MethodInfo>
list.addAll(getDeclaredAnnotationInfos());
// 2. Parent methods in child-to-parent order
- getMatching().skip(1).forEach(m ->
list.addAll(m.getDeclaredAnnotationInfos()));
+ matchingCache.get().stream().skip(1).forEach(m ->
list.addAll(m.getDeclaredAnnotationInfos()));
// 3. Return type on current
returnType.getDeclaredAnnotationInfos().forEach(x ->
list.add((AnnotationInfo<Annotation>)x));
// 4. Return type on parent methods in child-to-parent order
- getMatching().skip(1).forEach(m -> {
+ matchingCache.get().stream().skip(1).forEach(m -> {
m.getReturnType().unwrap(Value.class,
Optional.class).getDeclaredAnnotationInfos().forEach(x ->
list.add((AnnotationInfo<Annotation>)x));
});
@@ -438,29 +438,6 @@ public class MethodInfo extends ExecutableInfo implements
Comparable<MethodInfo>
getReturnType().unwrap(Value.class,
Optional.class).forEachAnnotation(annotationProvider, type, filter, action);
}
- /**
- * Returns a stream of annotations of the specified type in
parent-to-child order.
- *
- * <p>
- * This is the same as {@link #getAllAnnotationInfos(Class)} but
returns results in reversed (parent-to-child) order.
- *
- * @param <A> The annotation type.
- * @param type The annotation type to filter by.
- * @return A stream of matching annotation infos in parent-to-child
order.
- */
- public <A extends Annotation> Stream<AnnotationInfo<A>>
getAllAnnotationInfosParentFirst(Class<A> type) {
- return rstream(getAllAnnotationInfos())
- .map(x -> x.cast(type))
- .filter(Objects::nonNull);
- }
-
- public Stream<MethodInfo> getMatching() {
- return matchingCache.get().stream();
- }
-
- public Stream<MethodInfo> getMatchingParentFirst() {
- return rstream(matchingCache.get());
- }
/**
* Finds the annotation of the specified type defined on this method.
@@ -725,34 +702,6 @@ public class MethodInfo extends ExecutableInfo implements
Comparable<MethodInfo>
}
}
- /**
- * Invokes the specified method using lenient argument matching.
- *
- * <p>
- * Lenient matching allows arguments to be matched to parameters based
on parameter types.
- * <br>Arguments can be in any order.
- * <br>Extra arguments will be ignored.
- * <br>Missing arguments will be left <jk>null</jk>.
- *
- * <p>
- * Note that this only works for methods that have distinguishable
argument types.
- * <br>It's not going to work on methods with generic argument types
like <c>Object</c>
- *
- * @param pojo
- * The POJO the method is being called on.
- * <br>Can be <jk>null</jk> for static methods.
- * @param args
- * The arguments to pass to the method.
- * @return
- * The results of the method invocation.
- * @throws ExecutableException Exception occurred on invoked
constructor/method/field.
- * @deprecated Use {@link #invokeLenient(Object, Object...)}
- */
- @Deprecated
- public Object invokeFuzzy(Object pojo, Object...args) throws
ExecutableException {
- return invokeLenient(pojo, args);
- }
-
/**
* Invokes the specified method using lenient argument matching.
*
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ParameterInfo.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ParameterInfo.java
index 88f96734fd..0e006eb513 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ParameterInfo.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ParameterInfo.java
@@ -178,13 +178,13 @@ public class ParameterInfo extends ElementInfo implements
Annotatable {
for (int i = parents2.size() - 1; i >= 0; i--)
for (var ann :
parents2.get(i).inner().getDeclaredAnnotationsByType(type))
consumeIf(filter, action, ann);
- // Get annotations from matching parent methods'
parameters
- mi.getMatchingParentFirst().forEach(x -> {
-
x.getParameter(index).getAnnotationInfos().stream()
- .filter(ai ->
type.isInstance(ai.inner()))
- .map(ai -> type.cast(ai.inner()))
- .forEach(ann -> consumeIf(filter,
action, ann));
- });
+ // Get annotations from matching parent
methods' parameters
+ rstream(mi.getMatchingMethods()).forEach(x -> {
+
x.getParameter(index).getAnnotationInfos().stream()
+ .filter(ai ->
type.isInstance(ai.inner()))
+ .map(ai ->
type.cast(ai.inner()))
+ .forEach(ann ->
consumeIf(filter, action, ann));
+ });
}
return this;
}
@@ -818,7 +818,7 @@ public class ParameterInfo extends ElementInfo implements
Annotatable {
var mi = (MethodInfo)executable;
var ci =
executable.getParameter(index).getParameterType().unwrap(Value.class,
Optional.class);
ci.forEachAnnotation(ap, a, filter, action);
- mi.getMatchingParentFirst().forEach(x -> {
+ rstream(mi.getMatchingMethods()).forEach(x -> {
x.getParameter(index).getAnnotationInfos().stream()
.filter(ai -> a.isInstance(ai.inner()))
.map(ai -> a.cast(ai.inner()))
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/RequestBeanPropertyMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/RequestBeanPropertyMeta.java
index 7e0a86f76e..26241cc020 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/RequestBeanPropertyMeta.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/RequestBeanPropertyMeta.java
@@ -16,6 +16,7 @@
*/
package org.apache.juneau.httppart.bean;
+import static org.apache.juneau.common.utils.CollectionUtils.*;
import static org.apache.juneau.common.utils.Utils.*;
import java.lang.annotation.*;
@@ -64,8 +65,8 @@ public class RequestBeanPropertyMeta {
static RequestBeanPropertyMeta.Builder create(HttpPartType partType,
Class<? extends Annotation> c, MethodInfo m) {
HttpPartSchema.Builder sb =
HttpPartSchema.create().name(m.getPropertyName());
-
m.getAllAnnotationInfosParentFirst(Schema.class).map(AnnotationInfo::inner).forEach(x
-> sb.apply(x));
-
m.getAllAnnotationInfosParentFirst(c).map(AnnotationInfo::inner).forEach(x ->
sb.apply(x));
+ rstream(m.getAllAnnotationInfos()).map(x ->
x.cast(Schema.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
-> sb.apply(x));
+ rstream(m.getAllAnnotationInfos()).map(x ->
x.cast(c)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x ->
sb.apply(x));
return new
Builder().partType(partType).schema(sb.build()).getter(m.inner());
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java
index 7b5eee1c1a..d68094b10e 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java
@@ -125,8 +125,8 @@ public class ResponseBeanMeta {
return null;
var b = new Builder(annotations);
b.apply(m.getReturnType().unwrap(Value.class,
Optional.class).innerType());
-
m.getAllAnnotationInfosParentFirst(Response.class).map(AnnotationInfo::inner).forEach(x
-> b.apply(x));
-
m.getAllAnnotationInfosParentFirst(StatusCode.class).map(AnnotationInfo::inner).forEach(x
-> b.apply(x));
+ rstream(m.getAllAnnotationInfos()).map(x ->
x.cast(Response.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
-> b.apply(x));
+ rstream(m.getAllAnnotationInfos()).map(x ->
x.cast(StatusCode.class)).filter(Objects::nonNull).map(AnnotationInfo::inner).forEach(x
-> b.apply(x));
return b.build();
}
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 839a31b2d1..4b811a0158 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
@@ -205,7 +205,7 @@ public class RestContext extends Context {
// @formatter:off
ClassInfo.ofProxy(r).getAllMethodsParentFirst().stream()
.filter(y -> y.hasAnnotation(annotation))
- .forEach(y ->
y.getAllAnnotationInfosParentFirst(annotation).map(AnnotationInfo::inner)
+ .forEach(y ->
rstream(y.getAllAnnotationInfos()).map(ai ->
ai.cast(annotation)).filter(Objects::nonNull).map(AnnotationInfo::inner)
.filter(z -> predicate == null ||
predicate.test(z))
.forEach(z -> x.put(y.getSignature(),
y.accessible().inner())));
// @formatter:on
@@ -4586,7 +4586,7 @@ public class RestContext extends Context {
// Also include methods on @Rest-annotated
interfaces.
if (al.isEmpty()) {
Predicate<MethodInfo>
isRestAnnotatedInterface = x -> x.getDeclaringClass().isInterface() &&
nn(x.getDeclaringClass().getAnnotationInfos(Rest.class).findFirst().map(AnnotationInfo::inner).orElse(null));
-
mi.getMatching().filter(isRestAnnotatedInterface).forEach(x ->
al.add(AnnotationInfo.of(x, RestOpAnnotation.DEFAULT)));
+
mi.getMatchingMethods().stream().filter(isRestAnnotatedInterface).forEach(x ->
al.add(AnnotationInfo.of(x, RestOpAnnotation.DEFAULT)));
}
if (al.size() > 0) {
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
index d55620ae15..90379caeac 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
@@ -1949,7 +1949,7 @@ public class RestOpContext extends Context implements
Comparable<RestOpContext>
httpMethod = "delete";
else if (mi.hasAnnotation(RestOp.class)) {
var _httpMethod = Value.<String>empty();
-
mi.getAllAnnotationInfosParentFirst(RestOp.class).map(AnnotationInfo::inner)
+ rstream(mi.getAllAnnotationInfos()).map(x ->
x.cast(RestOp.class)).filter(Objects::nonNull).map(AnnotationInfo::inner)
.filter(x -> isNotEmpty(x.method()))
.forEach(x ->
_httpMethod.set(x.method()));
httpMethod = _httpMethod.orElse(null);
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 1ba32b22e8..9043dd04a7 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
@@ -153,8 +153,8 @@ class MethodInfo_Test extends TestBase {
@Test void findMatchingMethods() throws Exception {
var mi = MethodInfo.of(B3.class.getMethod("foo", int.class));
var l = new ArrayList<MethodInfo>();
- mi.getMatching().forEach(l::add);
- check("B3.foo(int),B2.foo(int),B1.foo(int)", l);
+ mi.getMatchingMethods().stream().forEach(l::add);
+ check("B3.foo(int),B1.foo(int),B2.foo(int)", l);
}
//-----------------------------------------------------------------------------------------------------------------
@@ -352,7 +352,7 @@ class MethodInfo_Test extends TestBase {
private static List<A> annotations(MethodInfo mi, Class<? extends
Annotation> a) {
var l = new ArrayList<A>();
-
mi.getAllAnnotationInfosParentFirst(a).map(AnnotationInfo::inner)
+ rstream(mi.getAllAnnotationInfos()).map(x ->
x.cast(a)).filter(Objects::nonNull).map(AnnotationInfo::inner)
.forEach(x -> l.add((A)x));
return l;
}