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 f6f8a07763 Utility class modernization
f6f8a07763 is described below
commit f6f8a077636091715d14baa48d15c32024e10f78
Author: James Bognar <[email protected]>
AuthorDate: Mon Nov 3 16:35:04 2025 -0500
Utility class modernization
---
.../juneau/common/reflect/AnnotationInfo.java | 3 +-
.../juneau/common/reflect/ExecutableInfo.java | 38 ++++++++++++++--------
.../apache/juneau/common/reflect/MethodInfo.java | 3 +-
3 files changed, 28 insertions(+), 16 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 b7255f7669..ef9cdc6252 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
@@ -491,7 +491,6 @@ public class AnnotationInfo<T extends Annotation> {
private static void forEachDeclaredMethodAnnotationInfo(MethodInfo
methodInfo, ClassInfo ci, Predicate<AnnotationInfo<?>> filter,
Consumer<AnnotationInfo<?>> action) {
MethodInfo mi = methodInfo.findMatchingOnClass(ci);
if (nn(mi))
- for (var a : mi._getDeclaredAnnotations())
- AnnotationInfo.of(mi, a).accept(filter, action);
+ mi.getDeclaredAnnotationInfos().forEach(ai ->
ai.accept(filter, action));
}
}
\ No newline at end of file
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 def5d8a8e6..339c9164e5 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
@@ -40,12 +40,14 @@ import java.util.stream.*;
public abstract class ExecutableInfo extends AccessibleInfo {
final ClassInfo declaringClass;
- Executable e; // Effectively final.
+ final Executable e; // Effectively final.
final boolean isConstructor;
private final Supplier<List<ParameterInfo>> parameters =
memoize(this::findParameters);
+ private final Supplier<List<ClassInfo>> exceptions =
memoize(this::findExceptions);
+ private final Supplier<List<AnnotationInfo<Annotation>>>
declaredAnnotations = memoize(this::findDeclaredAnnotations);
- private volatile ClassInfo[] paramTypes, exceptionInfos;
+ private volatile ClassInfo[] paramTypes;
private volatile Class<?>[] rawParamTypes;
private volatile Type[] rawGenericParamTypes;
private volatile Parameter[] rawParameters;
@@ -207,7 +209,14 @@ public abstract class ExecutableInfo extends
AccessibleInfo {
*
* @return The exception types on this executable.
*/
- public final List<ClassInfo> getExceptionTypes() { return
u(l(_getExceptionTypes())); }
+ public final List<ClassInfo> getExceptionTypes() { return
exceptions.get(); }
+
+ /**
+ * Returns the declared annotations on this executable.
+ *
+ * @return The declared annotations on this executable as {@link
AnnotationInfo} objects.
+ */
+ public final List<AnnotationInfo<Annotation>>
getDeclaredAnnotationInfos() { return declaredAnnotations.get(); }
/**
* Returns the full name of this executable.
@@ -1021,6 +1030,18 @@ public abstract class ExecutableInfo extends
AccessibleInfo {
throw new IndexOutOfBoundsException(format("Invalid
index ''{0}''. Parameter count: {1}", index, pc));
}
+ private List<AnnotationInfo<Annotation>> findDeclaredAnnotations() {
+ return stream(e.getDeclaredAnnotations())
+ .map(a -> AnnotationInfo.of((Annotatable)this, a))
+ .toList();
+ }
+
+ private List<ClassInfo> findExceptions() {
+ return stream(e.getExceptionTypes())
+ .map(ClassInfo::of)
+ .toList();
+ }
+
final Annotation[] _getDeclaredAnnotations() {
if (rawDeclaredAnnotations == null) {
synchronized (this) {
@@ -1031,16 +1052,7 @@ public abstract class ExecutableInfo extends
AccessibleInfo {
}
final ClassInfo[] _getExceptionTypes() {
- if (exceptionInfos == null) {
- synchronized (this) {
- Class<?>[] exceptionTypes =
e.getExceptionTypes();
- ClassInfo[] l = new
ClassInfo[exceptionTypes.length];
- for (int i = 0; i < exceptionTypes.length; i++)
- l[i] = ClassInfo.of(exceptionTypes[i]);
- exceptionInfos = l;
- }
- }
- return exceptionInfos;
+ return exceptions.get().toArray(new ClassInfo[0]);
}
final Annotation[][] _getParameterAnnotations() {
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 b9a3287e2c..f4af1ff5dc 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
@@ -219,7 +219,8 @@ public class MethodInfo extends ExecutableInfo implements
Comparable<MethodInfo>
public <A extends Annotation> MethodInfo
forEachAnnotation(AnnotationProvider annotationProvider, Class<A> type,
Predicate<A> filter, Consumer<A> action) {
declaringClass.forEachAnnotation(annotationProvider, type,
filter, action);
rstream(matchingCache.get())
- .flatMap(m ->
Arrays.stream(m._getDeclaredAnnotations()))
+ .flatMap(m -> m.getDeclaredAnnotationInfos().stream())
+ .map(AnnotationInfo::inner)
.filter(type::isInstance)
.map(type::cast)
.forEach(a -> consumeIf(filter, action, a));