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
commit ea867cde4e1e3f880de695d1f38e1d5df47c2de9 Author: James Bognar <[email protected]> AuthorDate: Fri Nov 7 08:48:35 2025 -0500 Utility class modernization --- .../juneau/common/reflect/ConstructorInfo.java | 29 ---------------------- .../src/main/java/org/apache/juneau/BeanMeta.java | 8 +++--- .../java/org/apache/juneau/swap/AutoListSwap.java | 2 +- .../java/org/apache/juneau/swap/AutoMapSwap.java | 2 +- .../org/apache/juneau/swap/AutoNumberSwap.java | 2 +- .../org/apache/juneau/swap/AutoObjectSwap.java | 2 +- .../java/org/apache/juneau/swap/SurrogateSwap.java | 2 +- 7 files changed, 8 insertions(+), 39 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 864f7c32e1..c132c62c55 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 @@ -16,14 +16,8 @@ */ package org.apache.juneau.common.reflect; -import static org.apache.juneau.common.utils.PredicateUtils.*; -import static org.apache.juneau.common.utils.Utils.*; - -import java.lang.annotation.*; import java.lang.reflect.*; -import java.util.function.*; -import org.apache.juneau.common.collections.*; import org.apache.juneau.common.utils.*; /** @@ -126,29 +120,6 @@ public class ConstructorInfo extends ExecutableInfo implements Comparable<Constr return i; } - /** - * Returns <jk>true</jk> if the specified annotation is present on this constructor. - * - * @param <A> The annotation type to look for. - * @param annotationProvider The annotation provider. - * @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(AnnotationProvider annotationProvider, Class<A> type) { - return nn(annotationProvider.find(type, c).map(x -> x.inner()).filter(x -> true).findFirst().orElse(null)); - } - - /** - * Returns <jk>true</jk> if the specified annotation is not present on this constructor. - * - * @param <A> The annotation type to look for. - * @param annotationProvider The annotation provider. - * @param type The annotation to look for. - * @return <jk>true</jk> if the specified annotation is not present on this constructor. - */ - public <A extends Annotation> boolean hasNoAnnotation(AnnotationProvider annotationProvider, Class<A> type) { - return ! hasAnnotation(annotationProvider, type); - } /** * Returns the wrapped method. diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java index 59c434b924..e9cb5c93d8 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java @@ -248,13 +248,12 @@ public class BeanMeta<T> { return "Class is not serializable"; // Look for @Beanc constructor on public constructors. - ci.getPublicConstructors().stream().filter(x -> x.hasAnnotation(ctx.getAnnotationProvider(), Beanc.class)).forEach(x -> { + ci.getPublicConstructors().stream().filter(x -> ctx.getAnnotationProvider().find(Beanc.class, x.inner()).findAny().isPresent()).forEach(x -> { if (nn(constructor)) throw new BeanRuntimeException(c, "Multiple instances of '@Beanc' found."); constructor = x; constructorArgs = new String[0]; - // Inline Context.forEachAnnotation() call - ctx.getAnnotationProvider().find(Beanc.class, x.inner()).map(x2 -> x2.inner()).filter(y -> ! y.properties().isEmpty()).forEach(z -> constructorArgs = splita(z.properties())); + ctx.getAnnotationProvider().find(Beanc.class, x.inner()).map(x2 -> x2.inner()).filter(y -> ! y.properties().isEmpty()).forEach(z -> constructorArgs = splita(z.properties())); if (! x.hasNumParameters(constructorArgs.length)) { if (constructorArgs.length != 0) throw new BeanRuntimeException(c, "Number of properties defined in '@Beanc' annotation does not match number of parameters in constructor."); @@ -272,12 +271,11 @@ public class BeanMeta<T> { // Look for @Beanc on all other constructors. if (constructor == null) { - ci.getDeclaredConstructors().stream().filter(x -> x.hasAnnotation(ctx.getAnnotationProvider(), Beanc.class)).forEach(x -> { + ci.getDeclaredConstructors().stream().filter(x -> ctx.getAnnotationProvider().find(Beanc.class, x.inner()).findAny().isPresent()).forEach(x -> { if (nn(constructor)) throw new BeanRuntimeException(c, "Multiple instances of '@Beanc' found."); constructor = x; constructorArgs = new String[0]; - // Inline Context.forEachAnnotation() call ctx.getAnnotationProvider().find(Beanc.class, x.inner()).map(x2 -> x2.inner()).filter(y -> ! y.properties().isEmpty()).forEach(z -> constructorArgs = splita(z.properties())); if (! x.hasNumParameters(constructorArgs.length)) { if (constructorArgs.length != 0) diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoListSwap.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoListSwap.java index 3a14d76c32..45732efb93 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoListSwap.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoListSwap.java @@ -143,7 +143,7 @@ public class AutoListSwap<T> extends ObjectSwap<T,List<?>> { cs.isNotDeprecated() && cs.isVisible(bc.getBeanConstructorVisibility()) && cs.hasMatchingParameterTypes(rt) - && cs.hasNoAnnotation(bc.getAnnotationProvider(), BeanIgnore.class); + && bc.getAnnotationProvider().find(BeanIgnore.class, cs.inner()).findAny().isEmpty(); // @formatter:on } diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoMapSwap.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoMapSwap.java index a9d32c15d5..c4898a0908 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoMapSwap.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoMapSwap.java @@ -143,7 +143,7 @@ public class AutoMapSwap<T> extends ObjectSwap<T,Map<?,?>> { cs.isNotDeprecated() && cs.isVisible(bc.getBeanConstructorVisibility()) && cs.hasMatchingParameterTypes(rt) - && cs.hasNoAnnotation(bc.getAnnotationProvider(), BeanIgnore.class); + && bc.getAnnotationProvider().find(BeanIgnore.class, cs.inner()).findAny().isEmpty(); // @formatter:on } diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoNumberSwap.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoNumberSwap.java index bf707e94b1..684533fa0f 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoNumberSwap.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoNumberSwap.java @@ -168,7 +168,7 @@ public class AutoNumberSwap<T> extends ObjectSwap<T,Number> { cs.isNotDeprecated() && cs.isVisible(bc.getBeanConstructorVisibility()) && cs.hasMatchingParameterTypes(rt) - && cs.hasNoAnnotation(bc.getAnnotationProvider(), BeanIgnore.class); + && bc.getAnnotationProvider().find(BeanIgnore.class, cs.inner()).findAny().isEmpty(); // @formatter:on } diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoObjectSwap.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoObjectSwap.java index 81754f114c..58afc73217 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoObjectSwap.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/AutoObjectSwap.java @@ -144,7 +144,7 @@ public class AutoObjectSwap<T> extends ObjectSwap<T,Object> { cs.isNotDeprecated() && cs.isVisible(bc.getBeanConstructorVisibility()) && cs.hasMatchingParameterTypes(rt) - && cs.hasNoAnnotation(bc.getAnnotationProvider(), BeanIgnore.class); + && bc.getAnnotationProvider().find(BeanIgnore.class, cs.inner()).findAny().isEmpty(); // @formatter:on } diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/SurrogateSwap.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/SurrogateSwap.java index 99eff33f27..623d5856a7 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/SurrogateSwap.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/SurrogateSwap.java @@ -54,7 +54,7 @@ public class SurrogateSwap<T,F> extends ObjectSwap<T,F> { public static List<SurrogateSwap<?,?>> findObjectSwaps(Class<?> c, BeanContext bc) { List<SurrogateSwap<?,?>> l = new LinkedList<>(); var ci = ClassInfo.of(c); - ci.getPublicConstructors().stream().filter(x -> x.hasNoAnnotation(bc.getAnnotationProvider(), BeanIgnore.class) && x.hasNumParameters(1) && x.isPublic()).forEach(x -> { + ci.getPublicConstructors().stream().filter(x -> bc.getAnnotationProvider().find(BeanIgnore.class, x.inner()).findAny().isEmpty() && x.hasNumParameters(1) && x.isPublic()).forEach(x -> { var pt = x.getParameter(0).getParameterType().inner(); if (! pt.equals(c.getDeclaringClass())) { // Find the unswap method if there is one.
