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 9d5a2b80b3 Utility class modernization
9d5a2b80b3 is described below
commit 9d5a2b80b33b795cef0e6af0b73d3d1ae6b152c2
Author: James Bognar <[email protected]>
AuthorDate: Wed Nov 5 08:43:11 2025 -0500
Utility class modernization
---
.../juneau/common/reflect/ConstructorInfo.java | 11 -------
.../juneau/common/reflect/ExecutableInfo.java | 38 ++++++++++++++++++++++
.../apache/juneau/common/reflect/MethodInfo.java | 11 +++++--
.../juneau/common/reflect/FieldInfo_Test.java | 9 -----
4 files changed, 46 insertions(+), 23 deletions(-)
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 27e48f8aab..52c5df832c 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
@@ -152,17 +152,6 @@ public class ConstructorInfo extends ExecutableInfo
implements Comparable<Constr
return nn(annotationProvider.firstAnnotation(type, c, x ->
true));
}
- /**
- * Returns <jk>true</jk> if the specified annotation is present on this
constructor.
- *
- * @param <A> The annotation type to look for.
- * @param type The annotation to look for.
- * @return <jk>true</jk> if the specified annotation is present on this
constructor.
- */
- public <A extends Annotation> boolean hasAnnotation(Class<A> type) {
- return hasAnnotation(AnnotationProvider.DEFAULT, type);
- }
-
/**
* Returns <jk>true</jk> if the specified annotation is not present on
this constructor.
*
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 a3659dd61c..ff3eeaedbf 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
@@ -18,6 +18,7 @@ package org.apache.juneau.common.reflect;
import static org.apache.juneau.common.reflect.ClassArrayFormat.*;
import static org.apache.juneau.common.reflect.ClassNameFormat.*;
+import static org.apache.juneau.common.utils.AssertionUtils.*;
import static org.apache.juneau.common.utils.CollectionUtils.*;
import static org.apache.juneau.common.utils.PredicateUtils.*;
import static org.apache.juneau.common.utils.StringUtils.*;
@@ -167,6 +168,43 @@ public abstract class ExecutableInfo extends
AccessibleInfo {
*/
public final List<AnnotationInfo<Annotation>>
getDeclaredAnnotationInfos() { return declaredAnnotations.get(); }
+ /**
+ * Returns the declared annotations of the specified type on this
executable.
+ *
+ * @param <A> The annotation type.
+ * @param type The annotation type.
+ * @return A stream of matching annotations.
+ */
+ @SuppressWarnings("unchecked")
+ public final <A extends Annotation> Stream<AnnotationInfo<A>>
getDeclaredAnnotationInfos(Class<A> type) {
+ assertArgNotNull("type", type);
+ return declaredAnnotations.get().stream()
+ .filter(x -> type.isInstance(x.inner()))
+ .map(x -> (AnnotationInfo<A>)x);
+ }
+
+ /**
+ * Returns <jk>true</jk> if this executable has the specified
annotation.
+ *
+ * @param <A> The annotation type.
+ * @param type The annotation type.
+ * @return <jk>true</jk> if this executable has the specified
annotation.
+ */
+ public <A extends Annotation> boolean hasAnnotation(Class<A> type) {
+ return getDeclaredAnnotationInfos(type).findFirst().isPresent();
+ }
+
+ /**
+ * Returns <jk>true</jk> if this executable does not have the specified
annotation.
+ *
+ * @param <A> The annotation type.
+ * @param type The annotation type.
+ * @return <jk>true</jk> if this executable does not have the specified
annotation.
+ */
+ public <A extends Annotation> boolean hasNoAnnotation(Class<A> type) {
+ return !hasAnnotation(type);
+ }
+
/**
* Returns the full name of this executable.
*
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 47a55eface..eabca7bb79 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
@@ -569,12 +569,16 @@ public class MethodInfo extends ExecutableInfo implements
Comparable<MethodInfo>
}
/**
- * Returns <jk>true</jk> if the specified annotation is present on this
method.
+ * Returns <jk>true</jk> if the specified annotation is present on this
method or any matching methods in parent classes/interfaces.
+ *
+ * <p>
+ * This method searches through all matching methods in the hierarchy.
*
* @param <A> The annotation type to look for.
* @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);
}
@@ -619,14 +623,15 @@ public class MethodInfo extends ExecutableInfo implements
Comparable<MethodInfo>
}
/**
- * Returns <jk>true</jk> if the specified annotation is not present on
this method.
+ * Returns <jk>true</jk> if the specified annotation is not present on
this method or any matching methods in parent classes/interfaces.
*
* @param <A> The annotation type to look for.
* @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;
+ return !hasAnnotation(type);
}
/**
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/FieldInfo_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/FieldInfo_Test.java
index dc303be7e8..4b7a0586fc 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/FieldInfo_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/FieldInfo_Test.java
@@ -118,15 +118,6 @@ class FieldInfo_Test extends TestBase {
b_a1 = off(B.class, "a1"),
b_a2 = off(B.class, "a2");
- @Test void getAnnotation() {
- check("@A(a1)", b_a1.getAnnotation(A.class));
- check(null, b_a2.getAnnotation(A.class));
- }
-
- @Test void getAnnotation_null() {
- check(null, b_a1.getAnnotation(null));
- }
-
@Test void hasAnnotation_true() {
assertTrue(b_a1.hasAnnotation(A.class));
}