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 0fae24269a Utility class modernization
0fae24269a is described below
commit 0fae24269a8468bbc0437575d1ea67aa1f5f6957
Author: James Bognar <[email protected]>
AuthorDate: Tue Nov 4 07:30:51 2025 -0500
Utility class modernization
---
.../juneau/common/reflect/ExecutableInfo.java | 40 +---------------------
.../juneau/common/reflect/ParameterInfo.java | 10 +++---
.../juneau/common/reflect/ExecutableInfo_Test.java | 16 ++++-----
3 files changed, 14 insertions(+), 52 deletions(-)
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ExecutableInfo.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ExecutableInfo.java
index c32b9a73ab..ea0b5e0f89 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ExecutableInfo.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ExecutableInfo.java
@@ -47,9 +47,6 @@ public abstract class ExecutableInfo extends AccessibleInfo {
private final Supplier<List<ClassInfo>> exceptions =
memoize(this::findExceptions);
private final Supplier<List<AnnotationInfo<Annotation>>>
declaredAnnotations = memoize(this::findDeclaredAnnotations);
- private volatile Annotation[][] rawParameterAnnotations;
- private volatile Annotation[] rawDeclaredAnnotations;
-
/**
* Constructor.
*
@@ -98,7 +95,7 @@ public abstract class ExecutableInfo extends AccessibleInfo {
* @return This object.
*/
public final <A extends Annotation> ExecutableInfo
forEachParameterAnnotation(int index, Class<A> type, Predicate<A> predicate,
Consumer<A> consumer) {
- for (var a : _getParameterAnnotations(index))
+ for (var a : getParameter(index).getAnnotations())
if (type.isInstance(a))
consumeIf(predicate, consumer, type.cast(a));
return this;
@@ -734,41 +731,6 @@ public abstract class ExecutableInfo extends
AccessibleInfo {
.toList();
}
- final Annotation[] _getDeclaredAnnotations() {
- if (rawDeclaredAnnotations == null) {
- synchronized (this) {
- rawDeclaredAnnotations =
e.getDeclaredAnnotations();
- }
- }
- return rawDeclaredAnnotations;
- }
-
- final Annotation[][] _getParameterAnnotations() {
- if (rawParameterAnnotations == null) {
- synchronized (this) {
- rawParameterAnnotations =
e.getParameterAnnotations();
- }
- }
- return rawParameterAnnotations;
- }
-
- final Annotation[] _getParameterAnnotations(int index) {
- checkIndex(index);
- Annotation[][] x = _getParameterAnnotations();
- int c = e.getParameterCount();
- if (c != x.length) {
- // Seems to be a JVM bug where
getParameterAnnotations() don't take mandated parameters into account.
- Annotation[][] x2 = new Annotation[c][];
- int diff = c - x.length;
- for (int i = 0; i < diff; i++)
- x2[i] = new Annotation[0];
- for (int i = diff; i < c; i++)
- x2[i] = x[i - diff];
- x = x2;
- }
- return x[index];
- }
-
private List<ParameterInfo> findParameters() {
var rp = e.getParameters();
var ptc = e.getParameterTypes();
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 b9fb6815d0..65fdd3e109 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
@@ -130,7 +130,7 @@ public class ParameterInfo extends ElementInfo implements
Annotatable {
* @return This object.
*/
public <A extends Annotation> ParameterInfo
forEachDeclaredAnnotation(Class<A> type, Predicate<A> filter, Consumer<A>
action) {
- for (var a : executable._getParameterAnnotations(index))
+ for (var a : getAnnotations())
if (type.isInstance(a))
consumeIf(filter, action, type.cast(a));
return this;
@@ -178,7 +178,7 @@ public class ParameterInfo extends ElementInfo implements
Annotatable {
A o = ci.getAnnotation(type, filter);
if (nn(o))
return o;
- for (var a2 :
executable._getParameterAnnotations(index))
+ for (var a2 : getAnnotations())
if (type.isInstance(a2) && test(filter,
type.cast(a2)))
return (A)a2;
} else {
@@ -210,7 +210,7 @@ public class ParameterInfo extends ElementInfo implements
Annotatable {
*/
public <A extends Annotation> A getDeclaredAnnotation(Class<A> type) {
if (nn(type))
- for (var a : executable._getParameterAnnotations(index))
+ for (var a : getAnnotations())
if (type.isInstance(a))
return type.cast(a);
return null;
@@ -688,7 +688,7 @@ public class ParameterInfo extends ElementInfo implements
Annotatable {
private <A extends Annotation> A findAnnotation(Class<A> type) {
if (executable.isConstructor()) {
- for (var a2 :
executable._getParameterAnnotations(index))
+ for (var a2 : getAnnotations())
if (type.isInstance(a2))
return type.cast(a2);
return
executable.getParameter(index).getParameterType().unwrap(Value.class,
Optional.class).getAnnotation(type);
@@ -702,7 +702,7 @@ public class ParameterInfo extends ElementInfo implements
Annotatable {
private <A extends Annotation> ParameterInfo
forEachAnnotation(AnnotationProvider ap, Class<A> a, Predicate<A> filter,
Consumer<A> action) {
if (executable.isConstructor) {
var ci =
executable.getParameter(index).getParameterType().unwrap(Value.class,
Optional.class);
- Annotation[] annotations =
executable._getParameterAnnotations(index);
+ var annotations = getAnnotations();
ci.forEachAnnotation(ap, a, filter, action);
for (var a2 : annotations)
if (a.isInstance(a2))
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ExecutableInfo_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ExecutableInfo_Test.java
index 472a985e48..4ead7db8c8 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ExecutableInfo_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ExecutableInfo_Test.java
@@ -257,17 +257,17 @@ class ExecutableInfo_Test extends TestBase {
;
@Test void getParameterAnnotations() {
- check("", c_c1._getParameterAnnotations());
- check("@CA()", c_c2._getParameterAnnotations());
- check("", c_c3._getParameterAnnotations());
- check("", c_m1._getParameterAnnotations());
- check("@CA()", c_m2._getParameterAnnotations());
- check("", c_m3._getParameterAnnotations());
+ check("", c_c1.getParameters().stream().map(p ->
p.getAnnotations()).toArray());
+ check("@CA()", c_c2.getParameters().stream().map(p ->
p.getAnnotations()).toArray());
+ check("", c_c3.getParameters().stream().map(p ->
p.getAnnotations()).toArray());
+ check("", c_m1.getParameters().stream().map(p ->
p.getAnnotations()).toArray());
+ check("@CA()", c_m2.getParameters().stream().map(p ->
p.getAnnotations()).toArray());
+ check("", c_m3.getParameters().stream().map(p ->
p.getAnnotations()).toArray());
}
@Test void getParameterAnnotations_atIndex() {
- check("@CA()", c_c2._getParameterAnnotations(0));
- check("@CA()", c_m2._getParameterAnnotations(0));
+ check("@CA()", c_c2.getParameter(0).getAnnotations());
+ check("@CA()", c_m2.getParameter(0).getAnnotations());
}
@Test void hasAnnotation() {