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 de0f71dd0d Utility class modernization
de0f71dd0d is described below
commit de0f71dd0d0022f1ab601c0b2fd5f912dfef112b
Author: James Bognar <[email protected]>
AuthorDate: Mon Nov 3 14:57:24 2025 -0500
Utility class modernization
---
.../juneau/common/reflect/AccessibleInfo.java | 164 ---------------------
.../juneau/common/reflect/ConstructorInfo.java | 1 -
.../apache/juneau/common/reflect/MethodInfo.java | 3 -
3 files changed, 168 deletions(-)
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AccessibleInfo.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AccessibleInfo.java
index 248aababc1..10ee1a68e7 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AccessibleInfo.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AccessibleInfo.java
@@ -41,14 +41,6 @@ public abstract class AccessibleInfo {
AccessibleObject ao; // Effectively final
- // Cached annotation lists
- private final Supplier<List<Annotation>> annotations = memoize(() ->
u(l(ao.getAnnotations())));
- private final Supplier<List<Annotation>> declaredAnnotations =
memoize(() -> u(l(ao.getDeclaredAnnotations())));
-
- // Cache for parameterized annotation queries
- private final Cache annotationsByType = Cache.of(Class.class,
List.class).supplier(k -> u(l(ao.getAnnotationsByType(k)))).build();
- private final Cache declaredAnnotationsByType = Cache.of(Class.class,
List.class) .supplier(k -> u(l(ao.getDeclaredAnnotationsByType(k)))).build();
-
/**
* Constructor.
*
@@ -100,160 +92,4 @@ public abstract class AccessibleInfo {
return false;
}
}
-
-
//-----------------------------------------------------------------------------------------------------------------
- // Annotations
-
//-----------------------------------------------------------------------------------------------------------------
-
- /**
- * Returns this element's annotation for the specified type if such an
annotation is <em>present</em>, else <jk>null</jk>.
- *
- * <p>
- * Same as calling {@link AccessibleObject#getAnnotation(Class)}.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Get @Deprecated annotation</jc>
- * Deprecated <jv>d</jv> =
accessibleInfo.getAnnotation(Deprecated.<jk>class</jk>);
- * </p>
- *
- * <p>
- * <b>Note:</b> This method may be overridden by subclasses to provide
enhanced annotation search capabilities
- * (e.g., searching through class hierarchies or interfaces).
- *
- * @param <A> The annotation type.
- * @param annotationClass The Class object corresponding to the
annotation type.
- * @return This element's annotation for the specified annotation type
if present, else <jk>null</jk>.
- * @see AccessibleObject#getAnnotation(Class)
- */
- public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
{
- return ao.getAnnotation(annotationClass);
- }
-
- /**
- * Returns <jk>true</jk> if this element has the specified annotation.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Check if method has @Deprecated annotation</jc>
- * <jk>if</jk>
(methodInfo.hasAnnotation(Deprecated.<jk>class</jk>)) {
- * <jc>// Handle deprecated method</jc>
- * }
- * </p>
- *
- * @param <A> The annotation type.
- * @param type The annotation to check for.
- * @return <jk>true</jk> if this element has the specified annotation.
- */
- public <A extends Annotation> boolean hasAnnotation(Class<A> type) {
- return ao.isAnnotationPresent(type);
- }
-
- /**
- * Returns <jk>true</jk> if this element doesn't have the specified
annotation.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Check if method is not deprecated</jc>
- * <jk>if</jk>
(methodInfo.hasNoAnnotation(Deprecated.<jk>class</jk>)) {
- * <jc>// Handle non-deprecated method</jc>
- * }
- * </p>
- *
- * @param <A> The annotation type.
- * @param type The annotation to check for.
- * @return <jk>true</jk> if this element doesn't have the specified
annotation.
- */
- public <A extends Annotation> boolean hasNoAnnotation(Class<A> type) {
- return ! hasAnnotation(type);
- }
-
- /**
- * Returns annotations that are <em>present</em> on this element.
- *
- * <p>
- * Returns a cached, unmodifiable list of annotations.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Get all annotations</jc>
- * List<Annotation> <jv>annotations</jv> =
accessibleInfo.getAnnotations();
- * </p>
- *
- * <p>
- * <b>Note:</b> This method may be overridden by subclasses to provide
enhanced annotation search capabilities.
- *
- * @return An unmodifiable list of annotations present on this element,
or an empty list if there are none.
- */
- public List<Annotation> getAnnotations() {
- return annotations.get();
- }
-
- /**
- * Returns annotations that are <em>directly present</em> on this
element (not inherited).
- *
- * <p>
- * Returns a cached, unmodifiable list of annotations.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Get declared annotations</jc>
- * List<Annotation> <jv>annotations</jv> =
accessibleInfo.getDeclaredAnnotations();
- * </p>
- *
- * <p>
- * <b>Note:</b> This method may be overridden by subclasses to provide
enhanced annotation search capabilities.
- *
- * @return An unmodifiable list of annotations directly present on this
element, or an empty list if there are none.
- */
- public List<Annotation> getDeclaredAnnotations() {
- return declaredAnnotations.get();
- }
-
- /**
- * Returns this element's annotations of the specified type (including
repeated annotations).
- *
- * <p>
- * Returns a cached, unmodifiable list of annotations.
- *
- * <p>
- * This method handles repeatable annotations by "looking through"
container annotations.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Get all @Author annotations (including repeated)</jc>
- * List<Author> <jv>authors</jv> =
accessibleInfo.getAnnotationsByType(Author.<jk>class</jk>);
- * </p>
- *
- * @param <A> The annotation type.
- * @param annotationClass The Class object corresponding to the
annotation type.
- * @return An unmodifiable list of all this element's annotations of
the specified type, or an empty list if there are none.
- */
- public <A extends Annotation> List<A> getAnnotationsByType(Class<A>
annotationClass) {
- return (List<A>) annotationsByType.get(annotationClass);
- }
-
- /**
- * Returns this element's declared annotations of the specified type
(including repeated annotations).
- *
- * <p>
- * Returns a cached, unmodifiable list of annotations.
- *
- * <p>
- * This method handles repeatable annotations by "looking through"
container annotations,
- * but only examines annotations directly declared on this element (not
inherited).
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Get declared @Author annotations (including
repeated)</jc>
- * List<Author> <jv>authors</jv> =
accessibleInfo.getDeclaredAnnotationsByType(Author.<jk>class</jk>);
- * </p>
- *
- * @param <A> The annotation type.
- * @param annotationClass The Class object corresponding to the
annotation type.
- * @return An unmodifiable list of all this element's declared
annotations of the specified type, or an empty list if there are none.
- */
- public <A extends Annotation> List<A>
getDeclaredAnnotationsByType(Class<A> annotationClass) {
- return (List<A>) declaredAnnotationsByType.get(annotationClass);
- }
}
\ No newline at end of file
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ConstructorInfo.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ConstructorInfo.java
index 227c9f7a9a..f25c9f0822 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ConstructorInfo.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ConstructorInfo.java
@@ -165,7 +165,6 @@ public class ConstructorInfo extends ExecutableInfo
implements Comparable<Constr
* @param type The annotation to look for.
* @return The annotation if found, or <jk>null</jk> if not.
*/
- @Override
public <A extends Annotation> A getAnnotation(Class<A> type) {
return getAnnotation(AnnotationProvider.DEFAULT, type);
}
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 e4aba79466..cc3ffbf081 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
@@ -330,7 +330,6 @@ public class MethodInfo extends ExecutableInfo implements
Comparable<MethodInfo>
* @param type The annotation to look for.
* @return The annotation if found, or <jk>null</jk> if not.
*/
- @Override
public <A extends Annotation> A getAnnotation(Class<A> type) {
return getAnnotation(AnnotationProvider.DEFAULT, type);
}
@@ -502,7 +501,6 @@ public class MethodInfo extends ExecutableInfo implements
Comparable<MethodInfo>
* @param type The annotation to look for.
* @return <jk>true</jk> if the specified annotation is present on this
method.
*/
- @Override
public <A extends Annotation> boolean hasAnnotation(Class<A> type) {
return hasAnnotation(AnnotationProvider.DEFAULT, type);
}
@@ -553,7 +551,6 @@ public class MethodInfo extends ExecutableInfo implements
Comparable<MethodInfo>
* @param type The annotation to look for.
* @return <jk>true</jk> if the specified annotation is not present on
this method.
*/
- @Override
public <A extends Annotation> boolean hasNoAnnotation(Class<A> type) {
return getAnnotation(type) == null;
}