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

commit 0ae3b5aef36fb3f5aead9e7f9103d06d690996ba
Author: James Bognar <[email protected]>
AuthorDate: Thu Nov 20 10:29:04 2025 -0500

    org.apache.juneau.common.reflect API improvements
---
 .../juneau/common/reflect/AnnotationProvider.java  | 16 +++++++++----
 .../apache/juneau/common/reflect/ClassInfo.java    |  8 +++----
 .../apache/juneau/common/reflect/ElementInfo.java  |  9 ++++++++
 .../juneau/common/reflect/ExecutableInfo.java      |  2 +-
 .../apache/juneau/common/reflect/FieldInfo.java    |  2 +-
 .../apache/juneau/common/reflect/MethodInfo.java   | 11 ---------
 .../apache/juneau/common/reflect/PackageInfo.java  | 26 ----------------------
 .../juneau/common/reflect/ParameterInfo.java       |  2 +-
 8 files changed, 28 insertions(+), 48 deletions(-)

diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationProvider.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationProvider.java
index 75f64e9f2c..2c8c34236e 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationProvider.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationProvider.java
@@ -438,22 +438,22 @@ public class AnnotationProvider {
 
        private List<AnnotationInfo<Annotation>> findClassAnnotations(Class<?> 
forClass) {
                var ci = ClassInfo.of(forClass);
-               return annotationMap.find(forClass).map(a -> 
AnnotationInfo.of(ci, a)).toList();
+               return annotationMap.find(forClass).map(a -> ai(ci, 
a)).toList();
        }
 
        private List<AnnotationInfo<Annotation>> findMethodAnnotations(Method 
forMethod) {
                var mi = MethodInfo.of(forMethod);
-               return annotationMap.find(forMethod).map(a -> 
AnnotationInfo.of(mi, a)).toList();
+               return annotationMap.find(forMethod).map(a -> ai(mi, 
a)).toList();
        }
 
        private List<AnnotationInfo<Annotation>> findFieldAnnotations(Field 
forField) {
                var fi = FieldInfo.of(forField);
-               return annotationMap.find(forField).map(a -> 
AnnotationInfo.of(fi, a)).toList();
+               return annotationMap.find(forField).map(a -> ai(fi, 
a)).toList();
        }
 
        private List<AnnotationInfo<Annotation>> 
findConstructorAnnotations(Constructor<?> forConstructor) {
                var ci = ConstructorInfo.of(forConstructor);
-               return annotationMap.find(forConstructor).map(a -> 
AnnotationInfo.of(ci, a)).toList();
+               return annotationMap.find(forConstructor).map(a -> ai(ci, 
a)).toList();
        }
 
        
//-----------------------------------------------------------------------------------------------------------------
@@ -1314,4 +1314,12 @@ public class AnnotationProvider {
        public <A extends Annotation> boolean has(Class<A> type, 
ConstructorInfo constructor, AnnotationTraversal... traversals) {
                return find(type, constructor, 
traversals).findFirst().isPresent();
        }
+
+       
//-----------------------------------------------------------------------------------------------------------------
+       // Helper methods
+       
//-----------------------------------------------------------------------------------------------------------------
+
+       private <A extends Annotation> AnnotationInfo<A> ai(Annotatable on, A 
value) {
+               return AnnotationInfo.of(on, value);
+       }
 }
\ No newline at end of file
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 991008d0c1..9fa6f7dfe4 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
@@ -225,7 +225,7 @@ public class ClassInfo extends ElementInfo implements 
Annotatable {
                this.componentType = memoize(this::findComponentType);
                this.packageInfo = memoize(() -> opt(inner).map(x -> 
x.getPackage()).filter(p -> p != null).map(PackageInfo::of).orElse(null));  // 
PackageInfo may be null for primitive types and arrays.
                this.parents = memoize(this::findParents);
-               this.declaredAnnotations = memoize(() -> (List)opt(inner).map(x 
-> u(l(x.getDeclaredAnnotations()))).orElse(liste()).stream().flatMap(a -> 
streamRepeated(a)).map(a -> AnnotationInfo.of(this, a)).toList());
+               this.declaredAnnotations = memoize(() -> (List)opt(inner).map(x 
-> u(l(x.getDeclaredAnnotations()))).orElse(liste()).stream().flatMap(a -> 
streamRepeated(a)).map(a -> ai(this, a)).toList());
                this.fullName = memoize(() -> getNameFormatted(FULL, true, '$', 
BRACKETS));
                this.shortName = memoize(() -> getNameFormatted(SHORT, true, 
'$', BRACKETS));
                this.readableName = memoize(() -> getNameFormatted(SIMPLE, 
false, '$', WORD));
@@ -984,7 +984,7 @@ public class ClassInfo extends ElementInfo implements 
Annotatable {
                PackageInfo pi = getPackage();
                if (pi == null)
                        return null;
-               var ai = pi.getAnnotation(type);
+               var ai = pi.getAnnotations(type).findFirst().orElse(null);
                return ai == null ? null : ai.inner();
        }
 
@@ -2479,7 +2479,7 @@ public class ClassInfo extends ElementInfo implements 
Annotatable {
                        var ci = parentsAndInterfaces.get(i);
                        // Add declared annotations from this class/interface
                        for (var a : ci.inner().getDeclaredAnnotations())
-                               streamRepeated(a).forEach(a2 -> 
list.add(AnnotationInfo.of(ci, a2)));
+                               streamRepeated(a).forEach(a2 -> list.add(ai(ci, 
a2)));
                }
 
                // On the package of this class
@@ -2487,7 +2487,7 @@ public class ClassInfo extends ElementInfo implements 
Annotatable {
                if (nn(pkg)) {
                        var pi = PackageInfo.of(pkg.inner());
                        for (var a : pkg.inner().getAnnotations())
-                               streamRepeated(a).forEach(a2 -> 
list.add(AnnotationInfo.of(pi, a2)));
+                               streamRepeated(a).forEach(a2 -> list.add(ai(pi, 
a2)));
                }
 
                return u(list);
diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ElementInfo.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ElementInfo.java
index 64046e9793..c4c453b724 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ElementInfo.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ElementInfo.java
@@ -19,6 +19,7 @@ package org.apache.juneau.common.reflect;
 import static org.apache.juneau.common.utils.CollectionUtils.*;
 import static org.apache.juneau.common.utils.ThrowableUtils.*;
 
+import java.lang.annotation.*;
 import java.lang.reflect.Modifier;
 
 /**
@@ -334,4 +335,12 @@ public abstract class ElementInfo {
        public boolean isNotStrict() {
                return !Modifier.isStrict(modifiers);
        }
+
+       
//-----------------------------------------------------------------------------------------------------------------
+       // Helper methods
+       
//-----------------------------------------------------------------------------------------------------------------
+
+       protected <A extends Annotation> AnnotationInfo<A> ai(Annotatable on, A 
value) {
+               return AnnotationInfo.of(on, value);
+       }
 }
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 f8c03b3e8a..cfb9346605 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
@@ -65,7 +65,7 @@ public abstract class ExecutableInfo extends AccessibleInfo {
                this.isConstructor = inner instanceof Constructor;
                this.parameters = memoize(this::findParameters);
                this.exceptions = memoize(() -> 
stream(inner.getExceptionTypes()).map(ClassInfo::of).toList());
-               this.declaredAnnotations = memoize(() -> 
stream(inner.getDeclaredAnnotations()).flatMap(a -> streamRepeated(a)).map(a -> 
AnnotationInfo.of((Annotatable)this, a)).toList());
+               this.declaredAnnotations = memoize(() -> 
stream(inner.getDeclaredAnnotations()).flatMap(a -> streamRepeated(a)).map(a -> 
ai((Annotatable)this, a)).toList());
                this.shortName = memoize(() -> f("{0}({1})", getSimpleName(), 
getParameters().stream().map(p -> 
p.getParameterType().getNameSimple()).collect(joining(","))));
                this.fullName = memoize(this::findFullName);
        }
diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/FieldInfo.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/FieldInfo.java
index e25f0d20e8..5aa39d6be5 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/FieldInfo.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/FieldInfo.java
@@ -80,7 +80,7 @@ public class FieldInfo extends AccessibleInfo implements 
Comparable<FieldInfo>,
                this.declaringClass = declaringClass;
                this.inner = inner;
                this.type = memoize(() -> ClassInfo.of(inner.getType()));
-               this.annotations = memoize(() -> 
stream(inner.getAnnotations()).flatMap(a -> streamRepeated(a)).map(a -> 
AnnotationInfo.of(this, a)).toList());
+               this.annotations = memoize(() -> 
stream(inner.getAnnotations()).flatMap(a -> streamRepeated(a)).map(a -> 
ai(this, a)).toList());
                this.fullName = memoize(this::findFullName);
        }
 
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 525c8a6a3b..9e236a3250 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
@@ -377,17 +377,6 @@ public class MethodInfo extends ExecutableInfo implements 
Comparable<MethodInfo>
                return getAnnotations(type).findAny().isPresent();
        }
 
-       /**
-        * Returns <jk>true</jk> if at least one of the specified annotation is 
present on this method.
-        *
-        * @param types The annotation to look for.
-        * @return <jk>true</jk> if at least one of the specified annotation is 
present on this method.
-        */
-       @SafeVarargs
-       public final boolean hasAnyAnnotations(Class<? extends 
Annotation>...types) {
-               return getAnnotations().stream().anyMatch(ai -> 
stream(types).anyMatch(t -> t.isInstance(ai.inner())));
-       }
-
        /**
         * Returns <jk>true</jk> if this method has the specified parameter.
         *
diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/PackageInfo.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/PackageInfo.java
index 5b15467e07..e53b4c10d2 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/PackageInfo.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/PackageInfo.java
@@ -254,32 +254,6 @@ public class PackageInfo implements Annotatable {
                return inner.isCompatibleWith(desired);
        }
 
-       /**
-        * Returns this package's annotation for the specified type wrapped in 
an {@link AnnotationInfo}, else <jk>null</jk>.
-        *
-        * <p>
-        * Searches the memoized annotations list for the first matching 
annotation.
-        *
-        * <h5 class='section'>Example:</h5>
-        * <p class='bjava'>
-        *      <jc>// Check if package has @Deprecated annotation</jc>
-        *      PackageInfo <jv>pi</jv> = 
PackageInfo.<jsm>of</jsm>(MyClass.<jk>class</jk>);
-        *      AnnotationInfo&lt;Deprecated&gt; <jv>d</jv> = 
<jv>pi</jv>.getAnnotation(Deprecated.<jk>class</jk>);
-        *      <jk>if</jk> (<jv>d</jv> != <jk>null</jk>) {
-        *              <jc>// Package is deprecated</jc>
-        *      }
-        * </p>
-        *
-        * @param <A> The annotation type.
-        * @param annotationClass The Class object corresponding to the 
annotation type.
-        * @return This package's annotation for the specified annotation type 
wrapped in AnnotationInfo, or <jk>null</jk> if not present.
-        */
-       public <A extends Annotation> AnnotationInfo<A> getAnnotation(Class<A> 
annotationClass) {
-               return getAnnotations(annotationClass)
-                       .findFirst()
-                       .orElse(null);
-       }
-
        /**
         * Returns all annotations on this package, wrapped in {@link 
AnnotationInfo} objects.
         *
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 1546b39119..2a966d9ae9 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
@@ -77,7 +77,7 @@ public class ParameterInfo extends ElementInfo implements 
Annotatable {
                this.inner = inner;
                this.index = index;
                this.type = type;
-               this.annotations = memoize(() -> 
stream(inner.getAnnotations()).flatMap(a -> streamRepeated(a)).map(a -> 
AnnotationInfo.of(this, a)).toList());
+               this.annotations = memoize(() -> 
stream(inner.getAnnotations()).flatMap(a -> streamRepeated(a)).map(a -> 
ai(this, a)).toList());
                this.matchingParameters = memoize(this::findMatchingParameters);
        }
 

Reply via email to