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 294e9ae592 org.apache.juneau.common.reflect API improvements
294e9ae592 is described below
commit 294e9ae592ebc850ac28ec7d1459c9d4f7f80961
Author: James Bognar <[email protected]>
AuthorDate: Wed Nov 19 13:39:13 2025 -0500
org.apache.juneau.common.reflect API improvements
---
.../juneau/common/reflect/AnnotationProvider.java | 380 +--------------------
.../src/main/java/org/apache/juneau/BeanMeta.java | 78 +++--
.../java/org/apache/juneau/BeanPropertyMeta.java | 65 ++--
.../src/main/java/org/apache/juneau/ClassMeta.java | 9 +-
.../src/main/java/org/apache/juneau/Context.java | 48 ---
.../apache/juneau/html/HtmlBeanPropertyMeta.java | 6 +-
.../java/org/apache/juneau/swap/AutoListSwap.java | 8 +-
.../java/org/apache/juneau/swap/AutoMapSwap.java | 8 +-
.../org/apache/juneau/swap/AutoNumberSwap.java | 12 +-
.../org/apache/juneau/swap/AutoObjectSwap.java | 8 +-
.../java/org/apache/juneau/swap/BuilderSwap.java | 5 +-
.../java/org/apache/juneau/swap/SurrogateSwap.java | 2 +-
.../java/org/apache/juneau/xml/XmlBeanMeta.java | 11 +-
.../juneau/common/reflect/ClassInfo_Test.java | 16 +-
14 files changed, 127 insertions(+), 529 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 7645d17a88..dddef37fbd 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
@@ -405,14 +405,10 @@ public class AnnotationProvider {
}
// @formatter:off
- private final Cache<Class<?>,List<AnnotationInfo<Annotation>>>
classAnnotations;
private final Cache<Class<?>,List<AnnotationInfo<Annotation>>>
classDeclaredAnnotations;
private final Cache<Class<?>,List<AnnotationInfo<Annotation>>>
classRuntimeAnnotations;
- private final Cache<Method,List<AnnotationInfo<Annotation>>>
methodAnnotations;
private final Cache<Method,List<AnnotationInfo<Annotation>>>
methodRuntimeAnnotations;
- private final Cache<Field,List<AnnotationInfo<Annotation>>>
fieldAnnotations;
private final Cache<Field,List<AnnotationInfo<Annotation>>>
fieldRuntimeAnnotations;
- private final Cache<Constructor<?>,List<AnnotationInfo<Annotation>>>
constructorAnnotations;
private final Cache<Constructor<?>,List<AnnotationInfo<Annotation>>>
constructorRuntimeAnnotations;
private final ReflectionMap<Annotation> runtimeAnnotations;
// @formatter:on
@@ -423,10 +419,6 @@ public class AnnotationProvider {
* @param builder The builder containing configuration settings.
*/
protected AnnotationProvider(Builder builder) {
- this.classAnnotations =
Cache.<Class<?>,List<AnnotationInfo<Annotation>>>create()
- .supplier(this::findClassAnnotations)
- .disableCaching(builder.disableCaching)
- .build();
this.classDeclaredAnnotations =
Cache.<Class<?>,List<AnnotationInfo<Annotation>>>create()
.supplier(this::findClassDeclaredAnnotations)
.disableCaching(builder.disableCaching)
@@ -435,26 +427,14 @@ public class AnnotationProvider {
.supplier(this::findClassRuntimeAnnotations)
.disableCaching(builder.disableCaching)
.build();
- this.methodAnnotations =
Cache.<Method,List<AnnotationInfo<Annotation>>>create()
- .supplier(this::findMethodAnnotations)
- .disableCaching(builder.disableCaching)
- .build();
this.methodRuntimeAnnotations =
Cache.<Method,List<AnnotationInfo<Annotation>>>create()
.supplier(this::findMethodRuntimeAnnotations)
.disableCaching(builder.disableCaching)
.build();
- this.fieldAnnotations =
Cache.<Field,List<AnnotationInfo<Annotation>>>create()
- .supplier(this::findFieldAnnotations)
- .disableCaching(builder.disableCaching)
- .build();
this.fieldRuntimeAnnotations =
Cache.<Field,List<AnnotationInfo<Annotation>>>create()
.supplier(this::findFieldRuntimeAnnotations)
.disableCaching(builder.disableCaching)
.build();
- this.constructorAnnotations =
Cache.<Constructor<?>,List<AnnotationInfo<Annotation>>>create()
- .supplier(this::findConstructorAnnotations)
- .disableCaching(builder.disableCaching)
- .build();
this.constructorRuntimeAnnotations =
Cache.<Constructor<?>,List<AnnotationInfo<Annotation>>>create()
.supplier(this::findConstructorRuntimeAnnotations)
.disableCaching(builder.disableCaching)
@@ -467,133 +447,6 @@ public class AnnotationProvider {
// Public API
//-----------------------------------------------------------------------------------------------------------------
- /**
- * Finds all annotations on the specified class, including runtime
annotations.
- *
- * <p>
- * Searches the class, its parent classes, interfaces, and package for
annotations.
- * Returns annotations in <b>child-to-parent</b> order with runtime
annotations
- * taking precedence at each level.
- *
- * <p>
- * <b>Order of precedence</b> (see class javadocs for details):
- * <ol>
- * <li>Runtime + declared annotations on this class
- * <li>Runtime + declared annotations on parent classes
(child-to-parent)
- * <li>Runtime + declared annotations on interfaces
(child-to-parent)
- * <li>Declared annotations on the package
- * </ol>
- *
- * <p>
- * <b>Comparison with {@link ClassInfo#getAnnotations(Class)}:</b>
- * <ul>
- * <li>This method includes <b>runtime annotations</b>; ClassInfo
does not
- * <li>Same traversal order (child-to-parent with interfaces and
package)
- * <li>Runtime annotations are inserted with higher priority at
each level
- * </ul>
- *
- * @param onClass The class to search on.
- * @return A list of {@link AnnotationInfo} objects representing all
annotations on the specified class,
- * its parents, interfaces, and package. Never <jk>null</jk>.
- * @deprecated Use {@link #find(ClassInfo, AnnotationTraversal...)}
instead.
- */
- @Deprecated
- public List<AnnotationInfo<Annotation>> xfind(Class<?> onClass) {
- assertArgNotNull("onClass", onClass);
- return classAnnotations.get(onClass);
- }
-
- /**
- * Finds all annotations of the specified type on the specified class,
including runtime annotations.
- *
- * <p>
- * Searches the class, its parent classes, interfaces, and package for
annotations of the specified type.
- * Returns annotations in <b>child-to-parent</b> order with runtime
annotations
- * taking precedence at each level.
- *
- * <p>
- * This is a filtered version of {@link #xfind(Class)} that only
returns annotations matching the specified type.
- *
- * <p>
- * <b>Comparison with {@link ClassInfo#getAnnotations(Class)}:</b>
- * <ul>
- * <li>This method includes <b>runtime annotations</b>; ClassInfo
does not
- * <li>Same traversal order (child-to-parent with interfaces and
package)
- * <li>Runtime annotations are inserted with higher priority at
each level
- * </ul>
- *
- * @param <A> The annotation type to find.
- * @param type The annotation type to find.
- * @param onClass The class to search on.
- * @return A stream of {@link AnnotationInfo} objects representing
annotations of the specified type on the
- * specified class, its parents, interfaces, and package. Never
<jk>null</jk>.
- * @deprecated Use {@link #find(Class, ClassInfo,
AnnotationTraversal...)} instead.
- */
- @Deprecated
- @SuppressWarnings("unchecked")
- public <A extends Annotation> Stream<AnnotationInfo<A>> xfind(Class<A>
type, Class<?> onClass) {
- assertArgNotNull("type", type);
- assertArgNotNull("onClass", onClass);
- return xfind(onClass).stream()
- .filter(a -> a.isType(type))
- .map(a -> (AnnotationInfo<A>)a);
- }
-
- /**
- * Finds annotations declared directly on the specified class,
including runtime annotations.
- *
- * <p>
- * Unlike {@link #xfind(Class)}, this method only returns annotations
declared directly on the specified class,
- * not on its parents, interfaces, or package.
- *
- * <p>
- * <b>Order of precedence</b>:
- * <ol>
- * <li>Runtime annotations on this class (highest priority)
- * <li>Declared annotations on this class
- * </ol>
- *
- * <p>
- * <b>Comparison with {@link ClassInfo#getDeclaredAnnotations()}:</b>
- * <ul>
- * <li>This method includes <b>runtime annotations</b>; ClassInfo
does not
- * <li>Runtime annotations are returned first (higher priority)
- * </ul>
- *
- * @param onClass The class to search on.
- * @return A list of {@link AnnotationInfo} objects representing
annotations declared directly on the class.
- * Never <jk>null</jk>.
- * @deprecated Use {@link #find(ClassInfo, AnnotationTraversal...)}
with {@link AnnotationTraversal#SELF SELF} instead.
- */
- @Deprecated
- public List<AnnotationInfo<Annotation>> xfindDeclared(Class<?> onClass)
{
- assertArgNotNull("onClass", onClass);
- return classDeclaredAnnotations.get(onClass);
- }
-
- /**
- * Finds annotations of the specified type declared directly on the
specified class, including runtime annotations.
- *
- * <p>
- * This is a filtered version of {@link #xfindDeclared(Class)} that
only returns annotations matching the specified type.
- *
- * @param <A> The annotation type to find.
- * @param type The annotation type to find.
- * @param onClass The class to search on.
- * @return A stream of {@link AnnotationInfo} objects representing
annotations of the specified type declared
- * directly on the class. Never <jk>null</jk>.
- * @deprecated Use {@link #find(Class, ClassInfo,
AnnotationTraversal...)} with {@link AnnotationTraversal#SELF SELF} instead.
- */
- @Deprecated
- @SuppressWarnings("unchecked")
- public <A extends Annotation> Stream<AnnotationInfo<A>>
xfindDeclared(Class<A> type, Class<?> onClass) {
- assertArgNotNull("type", type);
- assertArgNotNull("onClass", onClass);
- return xfindDeclared(onClass).stream()
- .filter(a -> a.isType(type))
- .map(a -> (AnnotationInfo<A>)a);
- }
-
/**
* Finds all declared annotations on the specified class in
parent-to-child order (reversed).
*
@@ -647,205 +500,10 @@ public class AnnotationProvider {
.map(a -> (AnnotationInfo<A>)a);
}
- /**
- * Finds all annotations on the specified method, including runtime
annotations.
- *
- * <p>
- * Searches the method and all overridden parent methods for
annotations.
- * Returns annotations in <b>child-to-parent</b> order with runtime
annotations
- * taking precedence at each level.
- *
- * <p>
- * <b>Order of precedence</b> (see class javadocs for details):
- * <ol>
- * <li>Runtime annotations on this method (highest priority)
- * <li>Declared annotations on this method
- * <li>Runtime annotations on overridden parent methods
(child-to-parent)
- * <li>Declared annotations on overridden parent methods
(child-to-parent)
- * </ol>
- *
- * <p>
- * <b>Comparison with {@link MethodInfo#getAnnotations()}:</b>
- * <ul>
- * <li>This method includes <b>runtime annotations</b>; MethodInfo
does not
- * <li>Runtime annotations are inserted with higher priority at
each level
- * </ul>
- *
- * @param onMethod The method to search on.
- * @return A list of {@link AnnotationInfo} objects representing all
annotations on the method and
- * overridden parent methods. Never <jk>null</jk>.
- * @deprecated Use {@link #find(MethodInfo, AnnotationTraversal...)}
instead.
- */
- @Deprecated
- public List<AnnotationInfo<Annotation>> xfind(Method onMethod) {
- assertArgNotNull("onMethod", onMethod);
- return methodAnnotations.get(onMethod);
- }
-
- /**
- * Finds all annotations of the specified type on the specified method,
including runtime annotations.
- *
- * <p>
- * This is a filtered version of {@link #xfind(Method)} that only
returns annotations matching the specified type.
- *
- * @param <A> The annotation type to find.
- * @param type The annotation type to find.
- * @param onMethod The method to search on.
- * @return A stream of {@link AnnotationInfo} objects representing
annotations of the specified type on the
- * method and overridden parent methods. Never <jk>null</jk>.
- * @deprecated Use {@link #find(Class, MethodInfo,
AnnotationTraversal...)} instead.
- */
- @Deprecated
- @SuppressWarnings("unchecked")
- public <A extends Annotation> Stream<AnnotationInfo<A>> xfind(Class<A>
type, Method onMethod) {
- assertArgNotNull("type", type);
- assertArgNotNull("onMethod", onMethod);
- return xfind(onMethod).stream()
- .filter(a -> a.isType(type))
- .map(a -> (AnnotationInfo<A>)a);
- }
-
- /**
- * Finds all annotations on the specified field, including runtime
annotations.
- *
- * <p>
- * <b>Order of precedence</b>:
- * <ol>
- * <li>Runtime annotations on this field (highest priority)
- * <li>Declared annotations on this field
- * </ol>
- *
- * <p>
- * <b>Comparison with {@link FieldInfo#getAnnotations()}:</b>
- * <ul>
- * <li>This method includes <b>runtime annotations</b>; FieldInfo
does not
- * <li>Runtime annotations are returned first (higher priority)
- * </ul>
- *
- * @param onField The field to search on.
- * @return A list of {@link AnnotationInfo} objects representing all
annotations on the field.
- * Never <jk>null</jk>.
- * @deprecated Use {@link #find(FieldInfo, AnnotationTraversal...)}
instead.
- */
- @Deprecated
- public List<AnnotationInfo<Annotation>> xfind(Field onField) {
- assertArgNotNull("onField", onField);
- return fieldAnnotations.get(onField);
- }
-
- /**
- * Finds all annotations of the specified type on the specified field,
including runtime annotations.
- *
- * <p>
- * This is a filtered version of {@link #xfind(Field)} that only
returns annotations matching the specified type.
- *
- * @param <A> The annotation type to find.
- * @param type The annotation type to find.
- * @param onField The field to search on.
- * @return A stream of {@link AnnotationInfo} objects representing
annotations of the specified type on the field.
- * Never <jk>null</jk>.
- * @deprecated Use {@link #find(Class, FieldInfo,
AnnotationTraversal...)} instead.
- */
- @Deprecated
- @SuppressWarnings("unchecked")
- public <A extends Annotation> Stream<AnnotationInfo<A>> xfind(Class<A>
type, Field onField) {
- assertArgNotNull("type", type);
- assertArgNotNull("onField", onField);
- return xfind(onField).stream()
- .filter(a -> a.isType(type))
- .map(a -> (AnnotationInfo<A>)a);
- }
-
- /**
- * Finds all annotations on the specified constructor, including
runtime annotations.
- *
- * <p>
- * <b>Order of precedence</b>:
- * <ol>
- * <li>Runtime annotations on this constructor (highest priority)
- * <li>Declared annotations on this constructor
- * </ol>
- *
- * <p>
- * <b>Comparison with {@link
ConstructorInfo#getDeclaredAnnotations()}:</b>
- * <ul>
- * <li>This method includes <b>runtime annotations</b>;
ConstructorInfo does not
- * <li>Runtime annotations are returned first (higher priority)
- * </ul>
- *
- * @param onConstructor The constructor to search on.
- * @return A list of {@link AnnotationInfo} objects representing all
annotations on the constructor.
- * Never <jk>null</jk>.
- * @deprecated Use {@link #find(ConstructorInfo,
AnnotationTraversal...)} instead.
- */
- @Deprecated
- public List<AnnotationInfo<Annotation>> xfind(Constructor<?>
onConstructor) {
- assertArgNotNull("onConstructor", onConstructor);
- return constructorAnnotations.get(onConstructor);
- }
-
- /**
- * Finds all annotations of the specified type on the specified
constructor, including runtime annotations.
- *
- * <p>
- * This is a filtered version of {@link #xfind(Constructor)} that only
returns annotations matching the specified type.
- *
- * @param <A> The annotation type to find.
- * @param type The annotation type to find.
- * @param onConstructor The constructor to search on.
- * @return A stream of {@link AnnotationInfo} objects representing
annotations of the specified type on the constructor.
- * Never <jk>null</jk>.
- * @deprecated Use {@link #find(Class, ConstructorInfo,
AnnotationTraversal...)} instead.
- */
- @Deprecated
- @SuppressWarnings("unchecked")
- public <A extends Annotation> Stream<AnnotationInfo<A>> xfind(Class<A>
type, Constructor<?> onConstructor) {
- assertArgNotNull("type", type);
- assertArgNotNull("onConstructor", onConstructor);
- return xfind(onConstructor).stream()
- .filter(a -> a.isType(type))
- .map(a -> (AnnotationInfo<A>)a);
- }
-
//-----------------------------------------------------------------------------------------------------------------
// Private implementation
//-----------------------------------------------------------------------------------------------------------------
- /**
- * Finds all annotations on the specified class in child-to-parent
order.
- *
- * <p>
- * Annotations are appended in the following order:
- * <ol>
- * <li>On this class.
- * <li>On parent classes ordered child-to-parent.
- * <li>On interfaces ordered child-to-parent.
- * <li>On the package of this class.
- * </ol>
- *
- * @param forClass The class to find annotations on.
- * @return A list of {@link AnnotationInfo} objects in child-to-parent
order.
- */
- private List<AnnotationInfo<Annotation>> findClassAnnotations(Class<?>
forClass) {
- var ci = ClassInfo.of(forClass);
- var list = new ArrayList<AnnotationInfo<Annotation>>();
-
- // On all parent classes and interfaces (properly traversed to
avoid duplicates)
- var parentsAndInterfaces = ci.getParentsAndInterfaces();
- for (int i = 0; i < parentsAndInterfaces.size(); i++)
- findDeclaredAnnotations(list,
parentsAndInterfaces.get(i).inner());
-
- // On the package of this class
- var pkg = ci.getPackage();
- 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)));
- }
-
- return u(list);
- }
-
private List<AnnotationInfo<Annotation>>
findClassDeclaredAnnotations(Class<?> forClass) {
var list = new ArrayList<AnnotationInfo<Annotation>>();
@@ -860,47 +518,16 @@ public class AnnotationProvider {
return runtimeAnnotations.find(forClass).map(a ->
AnnotationInfo.of(ci, a)).toList();
}
- private List<AnnotationInfo<Annotation>> findMethodAnnotations(Method
forMethod) {
- var list = new ArrayList<AnnotationInfo<Annotation>>();
-
- MethodInfo.of(forMethod).getMatchingMethods().forEach(m -> {
- runtimeAnnotations.find(m.inner()).forEach(a ->
list.add(AnnotationInfo.of(m, a)));
- list.addAll(m.getDeclaredAnnotations());
- });
-
- return u(list);
- }
-
private List<AnnotationInfo<Annotation>>
findMethodRuntimeAnnotations(Method forMethod) {
MethodInfo mi = MethodInfo.of(forMethod);
return runtimeAnnotations.find(forMethod).map(a ->
AnnotationInfo.of(mi, a)).toList();
}
- private List<AnnotationInfo<Annotation>> findFieldAnnotations(Field
forField) {
- var list = new ArrayList<AnnotationInfo<Annotation>>();
-
- FieldInfo fi = FieldInfo.of(forField);
- runtimeAnnotations.find(forField).forEach(a ->
list.add(AnnotationInfo.of(fi, a)));
- list.addAll(fi.getAnnotations());
-
- return u(list);
- }
-
private List<AnnotationInfo<Annotation>>
findFieldRuntimeAnnotations(Field forField) {
FieldInfo fi = FieldInfo.of(forField);
return runtimeAnnotations.find(forField).map(a ->
AnnotationInfo.of(fi, a)).toList();
}
- private List<AnnotationInfo<Annotation>>
findConstructorAnnotations(Constructor<?> forConstructor) {
- var list = new ArrayList<AnnotationInfo<Annotation>>();
-
- ConstructorInfo ci = ConstructorInfo.of(forConstructor);
- runtimeAnnotations.find(forConstructor).forEach(a ->
list.add(AnnotationInfo.of(ci, a)));
- list.addAll(ci.getDeclaredAnnotations());
-
- return u(list);
- }
-
private List<AnnotationInfo<Annotation>>
findConstructorRuntimeAnnotations(Constructor<?> forConstructor) {
ConstructorInfo ci = ConstructorInfo.of(forConstructor);
return runtimeAnnotations.find(forConstructor).map(a ->
AnnotationInfo.of(ci, a)).toList();
@@ -1017,7 +644,7 @@ public class AnnotationProvider {
assertArgNotNull("type", type);
assertArgNotNull("clazz", clazz);
if (traversals.length == 0)
- traversals = a(SELF, PARENTS, PACKAGE);
+ traversals = a(PARENTS, PACKAGE);
return Arrays.stream(traversals)
.sorted(Comparator.comparingInt(AnnotationTraversal::getOrder))
@@ -1068,7 +695,7 @@ public class AnnotationProvider {
public Stream<AnnotationInfo<Annotation>> find(ClassInfo clazz,
AnnotationTraversal... traversals) {
assertArgNotNull("clazz", clazz);
if (traversals.length == 0)
- traversals = a(SELF, PARENTS, PACKAGE);
+ traversals = a(PARENTS, PACKAGE);
return Arrays.stream(traversals)
.sorted(Comparator.comparingInt(AnnotationTraversal::getOrder))
@@ -1141,7 +768,8 @@ public class AnnotationProvider {
* </ul>
*
* <p>
- * <b>Default:</b> If no traversals are specified, defaults to: {@code
SELF, PARENTS, PACKAGE}
+ * <b>Default:</b> If no traversals are specified, defaults to: {@code
PARENTS, PACKAGE}
+ * <br>Note: {@code PARENTS} includes the class itself plus all parent
classes and interfaces.
*
* <h5 class='section'>Example:</h5>
* <p class='bjava'>
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 0fd9517cb1..9025b65599 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
@@ -17,6 +17,7 @@
package org.apache.juneau;
import static org.apache.juneau.BeanMeta.MethodType.*;
+import static org.apache.juneau.common.reflect.AnnotationTraversal.*;
import static org.apache.juneau.common.utils.CollectionUtils.*;
import static org.apache.juneau.common.utils.PredicateUtils.*;
import static org.apache.juneau.common.utils.StringUtils.*;
@@ -131,6 +132,7 @@ public class BeanMeta<T> {
private static class Builder<T> {
ClassMeta<T> classMeta;
BeanContext ctx;
+ AnnotationProvider ap;
BeanFilter beanFilter;
String[] pNames;
Map<String,BeanPropertyMeta> properties;
@@ -150,6 +152,7 @@ public class BeanMeta<T> {
Builder(ClassMeta<T> classMeta, BeanContext ctx, BeanFilter
beanFilter, String[] pNames, ConstructorInfo implClassConstructor) {
this.classMeta = classMeta;
this.ctx = ctx;
+ this.ap = ctx.getAnnotationProvider();
this.beanFilter = beanFilter;
this.pNames = pNames;
this.implClassConstructor = implClassConstructor;
@@ -180,12 +183,12 @@ public class BeanMeta<T> {
* Returns the property name of the specified field if it's a
valid property.
* Returns null if the field isn't a valid property.
*/
- private String findPropertyName(Field f) {
+ private String findPropertyName(FieldInfo f) {
List<Beanp> lp = list();
List<Name> ln = list();
// Inline Context.forEachAnnotation() calls
- ctx.getAnnotationProvider().xfind(Beanp.class, f).map(x
-> x.inner()).filter(x -> true).forEach(x -> lp.add(x));
- ctx.getAnnotationProvider().xfind(Name.class, f).map(x
-> x.inner()).filter(x -> true).forEach(x -> ln.add(x));
+ ap.find(Beanp.class, f).map(x -> x.inner()).forEach(x
-> lp.add(x));
+ ap.find(Name.class, f).map(x -> x.inner()).forEach(x ->
ln.add(x));
String name = bpName(lp, ln);
if (isNotEmpty(name))
return name;
@@ -270,12 +273,12 @@ public class BeanMeta<T> {
// Look for @Beanc on all other constructors.
if (constructor == null) {
-
ci.getDeclaredConstructors().stream().filter(x ->
ctx.getAnnotationProvider().xfind(Beanc.class,
x.inner()).findAny().isPresent()).forEach(x -> {
+
ci.getDeclaredConstructors().stream().filter(x -> ap.has(Beanc.class,
x)).forEach(x -> {
if (nn(constructor))
throw new
BeanRuntimeException(c, "Multiple instances of '@Beanc' found.");
constructor = x;
constructorArgs = new String[0];
-
ctx.getAnnotationProvider().xfind(Beanc.class, x.inner()).map(x2 ->
x2.inner()).filter(y -> ! y.properties().isEmpty()).forEach(z ->
constructorArgs = splita(z.properties()));
+ ap.find(Beanc.class, x).map(x2
-> x2.inner().properties()).filter(y -> isNotEmpty(y)).forEach(z ->
constructorArgs = splita(z));
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.");
@@ -358,7 +361,7 @@ public class BeanMeta<T> {
} else /* Use 'better' introspection */ {
findBeanFields(ctx, c2, stopClass,
fVis).forEach(x -> {
- String name =
findPropertyName(x);
+ String name =
findPropertyName(FieldInfo.of(x));
if (nn(name)) {
if (!
normalProps.containsKey(name))
normalProps.put(name, BeanPropertyMeta.builder(beanMeta, name));
@@ -372,6 +375,7 @@ public class BeanMeta<T> {
bms.forEach(x -> {
String pn = x.propertyName;
Method m = x.method;
+ MethodInfo mi =
MethodInfo.of(m);
if (!
normalProps.containsKey(pn))
normalProps.put(pn, new
BeanPropertyMeta.Builder(beanMeta, pn));
BeanPropertyMeta.Builder bpm =
normalProps.get(pn);
@@ -379,7 +383,7 @@ public class BeanMeta<T> {
// Two getters. Pick
the best.
if (nn(bpm.getter)) {
- if (!
ctx.hasAnnotation(Beanp.class, m) && ctx.hasAnnotation(Beanp.class, bpm.getter))
+ if (!
ap.has(Beanp.class, mi) && ap.has(Beanp.class, MethodInfo.of(bpm.getter)))
m =
bpm.getter; // @Beanp annotated method takes precedence.
else if
(m.getName().startsWith("is") && bpm.getter.getName().startsWith("get"))
@@ -569,8 +573,8 @@ public class BeanMeta<T> {
.filter(x -> x.isNotStatic()
&& (x.isNotTransient() || noIgnoreTransients)
&& (! x.hasAnnotation(Transient.class) ||
noIgnoreTransients)
- &&
ctx.getAnnotationProvider().xfind(BeanIgnore.class,
x.inner()).findAny().isEmpty()
- && (v.isVisible(x.inner()) ||
ctx.getAnnotationProvider().xfind(Beanp.class,
x.inner()).findAny().isPresent()))
+ && !
ctx.getAnnotationProvider().has(BeanIgnore.class, x)
+ && (v.isVisible(x.inner()) ||
ctx.getAnnotationProvider().has(Beanp.class, x)))
.forEach(x -> l.add(x.inner())
);
// @formatter:on
@@ -589,13 +593,14 @@ public class BeanMeta<T> {
*/
static final List<BeanMethod> findBeanMethods(BeanContext ctx, Class<?>
c, Class<?> stopClass, Visibility v, PropertyNamer pn, boolean fluentSetters) {
List<BeanMethod> l = new LinkedList<>();
+ var ap = ctx.getAnnotationProvider();
forEachClass(ClassInfo.of(c), stopClass, c2 -> {
for (var m : c2.getDeclaredMethods()) {
- if (m.isStatic() || m.isBridge() ||
m.getParameterCount() > 2 || m.getMatchingMethods().stream().anyMatch(m2 ->
ctx.getAnnotationProvider().xfind(BeanIgnore.class,
m2.inner()).findFirst().isPresent()))
+ if (m.isStatic() || m.isBridge() ||
m.getParameterCount() > 2 || m.getMatchingMethods().stream().anyMatch(m2 ->
ap.has(BeanIgnore.class, m2, SELF, MATCHING_METHODS)))
continue;
Transient t = m.getMatchingMethods().stream()
- .map(m2 ->
ctx.getAnnotationProvider().xfind(Transient.class, m2.inner()).map(x ->
x.inner()).filter(x -> true).findFirst().orElse(null))
+ .map(m2 -> ap.find(Transient.class,
m2).map(x -> x.inner()).findFirst().orElse(null))
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
@@ -604,8 +609,8 @@ public class BeanMeta<T> {
List<Beanp> lp = list();
List<Name> ln = list();
- ctx.getAnnotationProvider().xfind(Beanp.class,
m.inner()).map(x -> x.inner()).filter(x -> true).forEach(x -> lp.add(x));
- ctx.getAnnotationProvider().xfind(Name.class,
m.inner()).map(x -> x.inner()).filter(x -> true).forEach(x -> ln.add(x));
+ ap.find(Beanp.class, m).map(x ->
x.inner()).forEach(x -> lp.add(x));
+ ap.find(Name.class, m).map(x ->
x.inner()).forEach(x -> ln.add(x));
// If this method doesn't have @Beanp or @Name,
check if it overrides a parent method that does
// This ensures property names are inherited
correctly, preventing duplicate property definitions
@@ -709,7 +714,7 @@ public class BeanMeta<T> {
x -> x.isNotStatic()
&& (x.isNotTransient() || noIgnoreTransients)
&& (! x.hasAnnotation(Transient.class) ||
noIgnoreTransients)
- &&
ctx.getAnnotationProvider().xfind(BeanIgnore.class,
x.inner()).findAny().isEmpty()
+ && !
ctx.getAnnotationProvider().has(BeanIgnore.class, x)
&& x.hasName(name))
.ifPresent(f -> value.set(f.inner()));
// @formatter:on
@@ -794,32 +799,33 @@ public class BeanMeta<T> {
if (! lp.isEmpty() || ! ln.isEmpty())
return;
- String methodName = method.getSimpleName();
- List<ParameterInfo> params = method.getParameters();
-
- // Walk up the class hierarchy looking for a matching parent method
with @Beanp or @Name
- var currentClass = ClassInfo.of(c);
- ClassInfo sc = currentClass.getSuperclass();
-
- while (nn(sc) && ! sc.is(stopClass) && ! sc.is(Object.class)) {
- // Look for a method with the same signature in the parent class
- for (var parentMethod : sc.getDeclaredMethods()) {
- if (parentMethod.getSimpleName().equals(methodName) &&
params.size() == parentMethod.getParameters().size()) {
-
- // Check if parameter types match
- boolean paramsMatch = true;
- List<ParameterInfo> parentParams =
parentMethod.getParameters();
- for (int i = 0; i < params.size(); i++) {
- if (!
params.get(i).getParameterType().is(parentParams.get(i).getParameterType().inner()))
{
- paramsMatch = false;
- break;
+ String methodName = method.getSimpleName();
+ List<ParameterInfo> params = method.getParameters();
+ var ap = ctx.getAnnotationProvider();
+
+ // Walk up the class hierarchy looking for a matching parent
method with @Beanp or @Name
+ var currentClass = ClassInfo.of(c);
+ ClassInfo sc = currentClass.getSuperclass();
+
+ while (nn(sc) && ! sc.is(stopClass) && ! sc.is(Object.class)) {
+ // Look for a method with the same signature in the
parent class
+ for (var parentMethod : sc.getDeclaredMethods()) {
+ if
(parentMethod.getSimpleName().equals(methodName) && params.size() ==
parentMethod.getParameters().size()) {
+
+ // Check if parameter types match
+ boolean paramsMatch = true;
+ List<ParameterInfo> parentParams =
parentMethod.getParameters();
+ for (int i = 0; i < params.size(); i++)
{
+ if (!
params.get(i).getParameterType().is(parentParams.get(i).getParameterType().inner()))
{
+ paramsMatch = false;
+ break;
+ }
}
- }
if (paramsMatch) {
// Found a matching parent
method - check for @Beanp and @Name annotations
-
ctx.getAnnotationProvider().xfind(Beanp.class, parentMethod.inner()).map(x ->
x.inner()).filter(x -> true).forEach(x -> lp.add(x));
-
ctx.getAnnotationProvider().xfind(Name.class, parentMethod.inner()).map(x ->
x.inner()).filter(x -> true).forEach(x -> ln.add(x));
+ ap.find(Beanp.class,
parentMethod).map(x -> x.inner()).forEach(x -> lp.add(x));
+ ap.find(Name.class,
parentMethod).map(x -> x.inner()).forEach(x -> ln.add(x));
// If we found annotations,
we're done
if (! lp.isEmpty() || !
ln.isEmpty())
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
index 46c16be05b..b32e96ff05 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
@@ -65,8 +65,8 @@ public class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
BeanMeta<?> beanMeta;
BeanContext beanContext;
String name;
- Field field, innerField;
- Method getter, setter, extraKeys;
+ Field field, innerField; // TODO - Replace with FieldInfo
fields
+ Method getter, setter, extraKeys; // TODO - Replace with
MethodInfo fields
boolean isConstructorArg, isUri, isDyna, isDynaGetterMap;
ClassMeta<?> rawTypeMeta, typeMeta;
String[] properties;
@@ -208,6 +208,7 @@ public class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
boolean validate(BeanContext bc, BeanRegistry
parentBeanRegistry, Map<Class<?>,Class<?>[]> typeVarImpls, Set<String> bpro,
Set<String> bpwo) throws Exception {
List<Class<?>> bdClasses = list();
+ var ap = bc.getAnnotationProvider();
if (field == null && getter == null && setter == null)
return false;
@@ -218,10 +219,14 @@ public class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
canRead |= (nn(field) || nn(getter));
canWrite |= (nn(field ) || nn(setter));
+ var ifi = innerField == null ? null :
FieldInfo.of(innerField);
+ var gi = getter == null ? null : MethodInfo.of(getter);
+ var si = setter == null ? null : MethodInfo.of(setter);
+
if (nn(innerField)) {
List<Beanp> lp = list();
// Inline Context.forEachAnnotation() call
- bc.getAnnotationProvider().xfind(Beanp.class,
innerField).map(x -> x.inner()).filter(x -> true).forEach(x -> lp.add(x));
+ ap.find(Beanp.class, ifi).map(x ->
x.inner()).forEach(x -> lp.add(x));
if (nn(field) || isNotEmpty(lp)) {
// Only use field type if it's a bean
property or has @Beanp annotation.
// Otherwise, we want to infer the type
from the getter or setter.
@@ -240,16 +245,16 @@ public class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
writeOnly =
Boolean.valueOf(x.wo());
});
// Inline Context.forEachAnnotation() call
- bc.getAnnotationProvider().xfind(Swap.class,
innerField).map(x -> x.inner()).filter(x -> true).forEach(x -> swap =
getPropertySwap(x));
- isUri |=
nn(bc.getAnnotationProvider().xfind(Uri.class, innerField).map(x ->
x.inner()).filter(x -> true).findFirst().orElse(null));
+ ap.find(Swap.class, ifi).map(x ->
x.inner()).forEach(x -> swap = getPropertySwap(x));
+ isUri |= ap.has(Uri.class, ifi);
}
if (nn(getter)) {
List<Beanp> lp = list();
- bc.getAnnotationProvider().xfind(Beanp.class,
getter).map(x -> x.inner()).filter(x -> true).forEach(x -> lp.add(x));
+ ap.find(Beanp.class, gi).map(x ->
x.inner()).forEach(x -> lp.add(x));
if (rawTypeMeta == null)
rawTypeMeta =
bc.resolveClassMeta(last(lp), getter.getGenericReturnType(), typeVarImpls);
- isUri |= (rawTypeMeta.isUri() ||
bc.hasAnnotation(Uri.class, getter));
+ isUri |= (rawTypeMeta.isUri() ||
ap.has(Uri.class, gi));
lp.forEach(x -> {
if (swap == null)
swap = getPropertySwap(x);
@@ -261,15 +266,15 @@ public class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
if (! x.wo().isEmpty())
writeOnly =
Boolean.valueOf(x.wo());
});
- bc.getAnnotationProvider().xfind(Swap.class,
getter).map(x -> x.inner()).filter(x -> true).forEach(x -> swap =
getPropertySwap(x));
+ ap.find(Swap.class, gi).map(x ->
x.inner()).forEach(x -> swap = getPropertySwap(x));
}
if (nn(setter)) {
List<Beanp> lp = list();
- bc.getAnnotationProvider().xfind(Beanp.class,
setter).map(x -> x.inner()).filter(x -> true).forEach(x -> lp.add(x));
+ ap.find(Beanp.class, si).map(x ->
x.inner()).forEach(x -> lp.add(x));
if (rawTypeMeta == null)
rawTypeMeta =
bc.resolveClassMeta(last(lp), setter.getGenericParameterTypes()[0],
typeVarImpls);
- isUri |= (rawTypeMeta.isUri() ||
bc.hasAnnotation(Uri.class, setter));
+ isUri |= (rawTypeMeta.isUri() ||
ap.has(Uri.class, si));
lp.forEach(x -> {
if (swap == null)
swap = getPropertySwap(x);
@@ -281,7 +286,7 @@ public class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
if (! x.wo().isEmpty())
writeOnly =
Boolean.valueOf(x.wo());
});
- bc.getAnnotationProvider().xfind(Swap.class,
setter).map(x -> x.inner()).filter(x -> true).forEach(x -> swap =
getPropertySwap(x));
+ ap.find(Swap.class, si).map(x ->
x.inner()).forEach(x -> swap = getPropertySwap(x));
}
if (rawTypeMeta == null)
@@ -637,9 +642,9 @@ public class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
public <A extends Annotation> BeanPropertyMeta
forEachAnnotation(Class<A> a, Predicate<A> filter, Consumer<A> action) {
BeanContext bc = beanContext;
if (nn(a)) {
- if (nn(field)) bc.getAnnotationProvider().xfind(a,
field).map(x -> x.inner()).filter(filter).forEach(action);
- if (nn(getter)) bc.getAnnotationProvider().xfind(a,
getter).map(x -> x.inner()).filter(filter).forEach(action);
- if (nn(setter)) bc.getAnnotationProvider().xfind(a,
setter).map(x -> x.inner()).filter(filter).forEach(action);
+ if (nn(field)) bc.getAnnotationProvider().find(a,
FieldInfo.of(field)).map(x -> x.inner()).filter(filter).forEach(action);
+ if (nn(getter)) bc.getAnnotationProvider().find(a,
MethodInfo.of(getter)).map(x -> x.inner()).filter(filter).forEach(action);
+ if (nn(setter)) bc.getAnnotationProvider().find(a,
MethodInfo.of(setter)).map(x -> x.inner()).filter(filter).forEach(action);
}
return this;
}
@@ -677,36 +682,41 @@ public class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
public <A extends Annotation> List<A>
getAllAnnotationsParentFirst(Class<A> a) {
List<A> l = new LinkedList<>();
BeanContext bc = beanContext;
+ var ap = bc.getAnnotationProvider();
+ var fi = field == null ? null : FieldInfo.of(field);
+ var gi = getter == null ? null : MethodInfo.of(getter);
+ var si = setter == null ? null : MethodInfo.of(setter);
if (a == null)
return l;
- bc.getAnnotationProvider().xforEachClassAnnotation(a,
getBeanMeta().getClassMeta().getInfo(), x -> true, x -> l.add(x));
+ ap.xforEachClassAnnotation(a,
getBeanMeta().getClassMeta().getInfo(), x -> true, x -> l.add(x));
if (nn(field)) {
- bc.getAnnotationProvider().xfind(a, field).map(x ->
x.inner()).filter(x -> true).forEach(x -> l.add(x));
- bc.getAnnotationProvider().xforEachClassAnnotation(a,
ClassInfo.of(field.getType()), x -> true, x -> l.add(x));
+ ap.find(a, fi).map(x -> x.inner()).forEach(x ->
l.add(x));
+ ap.xforEachClassAnnotation(a,
ClassInfo.of(field.getType()), x -> true, x -> l.add(x));
}
- if (nn(getter)) {
+ if (nn(gi)) {
// Walk up the inheritance hierarchy for the getter
method
forEachParentMethod(getter, parentGetter -> {
- bc.getAnnotationProvider().xfind(a,
parentGetter).map(x -> x.inner()).filter(x -> true).forEach(x -> l.add(x));
+ ap.find(a, MethodInfo.of(parentGetter)).map(x
-> x.inner()).forEach(x -> l.add(x));
});
- bc.getAnnotationProvider().xfind(a, getter).map(x ->
x.inner()).filter(x -> true).forEach(x -> l.add(x));
- bc.getAnnotationProvider().xforEachClassAnnotation(a,
ClassInfo.of(getter.getReturnType()), x -> true, x -> l.add(x));
+ ap.find(a, gi).map(x -> x.inner()).forEach(x ->
l.add(x));
+ ap.xforEachClassAnnotation(a, gi.getReturnType(), x ->
true, x -> l.add(x));
}
if (nn(setter)) {
// Walk up the inheritance hierarchy for the setter
method
forEachParentMethod(setter, parentSetter -> {
- bc.getAnnotationProvider().xfind(a,
parentSetter).map(x -> x.inner()).filter(x -> true).forEach(x -> l.add(x));
+ ap.find(a, MethodInfo.of(parentSetter)).map(x
-> x.inner()).forEach(x -> l.add(x));
});
- bc.getAnnotationProvider().xfind(a, setter).map(x ->
x.inner()).filter(x -> true).forEach(x -> l.add(x));
- bc.getAnnotationProvider().xforEachClassAnnotation(a,
ClassInfo.of(setter.getReturnType()), x -> true, x -> l.add(x));
+ ap.find(a, si).map(x -> x.inner()).forEach(x ->
l.add(x));
+ ap.xforEachClassAnnotation(a,
ClassInfo.of(setter.getReturnType()), x -> true, x -> l.add(x));
}
if (nn(extraKeys)) {
+ MethodInfo eki = MethodInfo.of(extraKeys);
// Walk up the inheritance hierarchy for the extraKeys
method
forEachParentMethod(extraKeys, parentExtraKeys -> {
- bc.getAnnotationProvider().xfind(a,
parentExtraKeys).map(x -> x.inner()).filter(x -> true).forEach(x -> l.add(x));
+ ap.find(a,
MethodInfo.of(parentExtraKeys)).map(x -> x.inner()).forEach(x -> l.add(x));
});
- bc.getAnnotationProvider().xfind(a, extraKeys).map(x ->
x.inner()).filter(x -> true).forEach(x -> l.add(x));
- bc.getAnnotationProvider().xforEachClassAnnotation(a,
ClassInfo.of(extraKeys.getReturnType()), x -> true, x -> l.add(x));
+ ap.find(a, eki).map(x -> x.inner()).filter(x ->
true).forEach(x -> l.add(x));
+ ap.xforEachClassAnnotation(a,
ClassInfo.of(extraKeys.getReturnType()), x -> true, x -> l.add(x));
}
return l;
@@ -942,6 +952,7 @@ public class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
* @param consumer The action to perform for each parent method.
*/
private static void forEachParentMethod(Method method, Consumer<Method>
consumer) {
+ // TODO - Convert to use MethodInfo parameters
if (method == null)
return;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
index 7e3d76a7ce..0a38265bc5 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
@@ -17,6 +17,7 @@
package org.apache.juneau;
import static org.apache.juneau.ClassMeta.ClassCategory.*;
+import static org.apache.juneau.common.reflect.AnnotationTraversal.*;
import static org.apache.juneau.common.utils.CollectionUtils.*;
import static org.apache.juneau.common.utils.PredicateUtils.*;
import static org.apache.juneau.common.utils.ThrowableUtils.*;
@@ -864,7 +865,7 @@ public class ClassMeta<T> implements Type {
*/
public <A extends Annotation> ClassMeta<T> forEachAnnotation(Class<A>
type, Predicate<A> filter, Consumer<A> action) {
if (beanContext != null) {
- beanContext.getAnnotationProvider().xfind(type,
info.inner()).map(x -> x.inner()).filter(x -> x != null).filter(x -> filter ==
null || filter.test(x)).forEach(x -> action.accept(x));
+ beanContext.getAnnotationProvider().find(type,
info).map(x -> x.inner()).filter(x -> x != null).filter(x -> filter == null ||
filter.test(x)).forEach(x -> action.accept(x));
}
return this;
}
@@ -1115,8 +1116,8 @@ public class ClassMeta<T> implements Type {
Optional<A> o = (Optional<A>)annotationLastMap.get(a);
if (o == null) {
if (beanContext == null)
- return
BeanContext.DEFAULT.getAnnotationProvider().xfind(a,
info.inner()).findFirst().map(x -> x.inner()).orElse(null);
- o = opt(beanContext.getAnnotationProvider().xfind(a,
info.inner()).findFirst().map(x -> x.inner()).orElse(null));
+ return AnnotationProvider.INSTANCE.find(a,
info).findFirst().map(x -> x.inner()).orElse(null);
+ o = beanContext.getAnnotationProvider().find(a,
info).findFirst().map(x -> x.inner());
annotationLastMap.put(a, o);
}
return o.orElse(null);
@@ -1761,7 +1762,7 @@ public class ClassMeta<T> implements Type {
A[] array = annotationArray(type);
if (array == null) {
if (beanContext == null)
- return AnnotationProvider.INSTANCE.xfind(type,
info.inner())
+ return AnnotationProvider.INSTANCE.find(type,
info)
.map(AnnotationInfo::inner)
.filter(a -> test(filter, a))
.findFirst(); // AnnotationProvider
returns child-to-parent, so first is "last"
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
index 7a6f317019..2d29052855 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
@@ -819,54 +819,6 @@ public abstract class Context {
*/
public ContextSession getSession() { return createSession().build(); }
- /**
- * Returns <jk>true</jk> if <c>getAnnotation(a,c)</c> returns a
non-null value.
- *
- * @param <A> The annotation being checked for.
- * @param type The annotation being checked for.
- * @param onClass The class being checked on.
- * @return <jk>true</jk> if the annotation exists on the specified
class.
- */
- public <A extends Annotation> boolean hasAnnotation(Class<A> type,
Class<?> onClass) {
- return getAnnotationProvider().xfind(type, onClass).map(x ->
x.inner()).findFirst().isPresent();
- }
-
- /**
- * Returns <jk>true</jk> if <c>getAnnotation(a,c)</c> returns a
non-null value.
- *
- * @param <A> The annotation being checked for.
- * @param type The annotation being checked for.
- * @param onConstructor The constructor being checked on.
- * @return <jk>true</jk> if the annotation exists on the specified
field.
- */
- public <A extends Annotation> boolean hasAnnotation(Class<A> type,
Constructor<?> onConstructor) {
- return getAnnotationProvider().xfind(type, onConstructor).map(x
-> x.inner()).findFirst().isPresent();
- }
-
- /**
- * Returns <jk>true</jk> if <c>getAnnotation(a,f)</c> returns a
non-null value.
- *
- * @param <A> The annotation being checked for.
- * @param type The annotation being checked for.
- * @param onField The field being checked on.
- * @return <jk>true</jk> if the annotation exists on the specified
field.
- */
- public <A extends Annotation> boolean hasAnnotation(Class<A> type,
Field onField) {
- return getAnnotationProvider().xfind(type, onField).map(x ->
x.inner()).findFirst().isPresent();
- }
-
- /**
- * Returns <jk>true</jk> if <c>getAnnotation(a,m)</c> returns a
non-null value.
- *
- * @param <A> The annotation being checked for.
- * @param type The annotation being checked for.
- * @param onMethod The method being checked on.
- * @return <jk>true</jk> if the annotation exists on the specified
method.
- */
- public <A extends Annotation> boolean hasAnnotation(Class<A> type,
Method onMethod) {
- return getAnnotationProvider().xfind(type, onMethod).map(x ->
x.inner()).findFirst().isPresent();
- }
-
/**
* Debug mode.
*
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlBeanPropertyMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlBeanPropertyMeta.java
index 51b22fa3e5..528a8020f2 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlBeanPropertyMeta.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlBeanPropertyMeta.java
@@ -81,11 +81,11 @@ public class HtmlBeanPropertyMeta extends
ExtendedBeanPropertyMeta {
Builder b = new Builder();
if (nn(bpm.getInnerField()))
- annotationProvider.xfind(Html.class,
bpm.getInnerField()).map(x -> x.inner()).filter(x -> true).forEach(x ->
b.findHtmlInfo(x));
+ annotationProvider.find(Html.class,
FieldInfo.of(bpm.getInnerField())).map(x -> x.inner()).forEach(x ->
b.findHtmlInfo(x));
if (nn(bpm.getGetter()))
- annotationProvider.xfind(Html.class,
bpm.getGetter()).map(x -> x.inner()).filter(x -> true).forEach(x ->
b.findHtmlInfo(x));
+ annotationProvider.find(Html.class,
MethodInfo.of(bpm.getGetter())).map(x -> x.inner()).forEach(x ->
b.findHtmlInfo(x));
if (nn(bpm.getSetter()))
- annotationProvider.xfind(Html.class,
bpm.getSetter()).map(x -> x.inner()).filter(x -> true).forEach(x ->
b.findHtmlInfo(x));
+ annotationProvider.find(Html.class,
MethodInfo.of(bpm.getSetter())).map(x -> x.inner()).forEach(x ->
b.findHtmlInfo(x));
this.format = b.format;
this.noTables = b.noTables;
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 8703d42ea9..0d670d4381 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
@@ -133,7 +133,7 @@ public class AutoListSwap<T> extends ObjectSwap<T,List<?>> {
&& mi.hasAnyName(SWAP_METHOD_NAMES)
&& mi.hasReturnTypeParent(List.class)
&& mi.hasParameterTypesLenient(BeanSession.class)
- && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().xfind(BeanIgnore.class,
m2.inner()).findFirst().isPresent());
+ && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().has(BeanIgnore.class, m2));
// @formatter:on
}
@@ -143,7 +143,7 @@ public class AutoListSwap<T> extends ObjectSwap<T,List<?>> {
cs.isNotDeprecated()
&&
cs.isVisible(bc.getBeanConstructorVisibility())
&& cs.hasParameterTypeParents(rt)
- &&
bc.getAnnotationProvider().xfind(BeanIgnore.class,
cs.inner()).findAny().isEmpty();
+ && !
bc.getAnnotationProvider().has(BeanIgnore.class, cs);
// @formatter:on
}
@@ -156,12 +156,12 @@ public class AutoListSwap<T> extends
ObjectSwap<T,List<?>> {
&& mi.hasAnyName(UNSWAP_METHOD_NAMES)
&& mi.hasParameterTypesLenient(BeanSession.class,
rt.inner())
&& mi.hasReturnTypeParent(ci)
- && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().xfind(BeanIgnore.class,
m2.inner()).findFirst().isPresent());
+ && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().has(BeanIgnore.class, m2));
// @formatter:on
}
private static boolean shouldIgnore(BeanContext bc, ClassInfo ci) {
- return bc.getAnnotationProvider().xfind(BeanIgnore.class,
ci.inner()).findFirst().isPresent() || ci.isNonStaticMemberClass();
+ return ci.isNonStaticMemberClass() ||
bc.getAnnotationProvider().has(BeanIgnore.class, ci);
}
//------------------------------------------------------------------------------------------------------------------
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 75a1c59ede..55b73aa72e 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
@@ -133,7 +133,7 @@ public class AutoMapSwap<T> extends ObjectSwap<T,Map<?,?>> {
&& mi.hasAnyName(SWAP_METHOD_NAMES)
&& mi.hasReturnTypeParent(Map.class)
&& mi.hasParameterTypesLenient(BeanSession.class)
- && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().xfind(BeanIgnore.class,
m2.inner()).findFirst().isPresent());
+ && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().has(BeanIgnore.class, m2));
// @formatter:on
}
@@ -143,7 +143,7 @@ public class AutoMapSwap<T> extends ObjectSwap<T,Map<?,?>> {
cs.isNotDeprecated()
&&
cs.isVisible(bc.getBeanConstructorVisibility())
&& cs.hasParameterTypeParents(rt)
- &&
bc.getAnnotationProvider().xfind(BeanIgnore.class,
cs.inner()).findAny().isEmpty();
+ && !
bc.getAnnotationProvider().has(BeanIgnore.class, cs);
// @formatter:on
}
@@ -156,12 +156,12 @@ public class AutoMapSwap<T> extends
ObjectSwap<T,Map<?,?>> {
&& mi.hasAnyName(UNSWAP_METHOD_NAMES)
&& mi.hasParameterTypesLenient(BeanSession.class,
rt.inner())
&& mi.hasReturnTypeParent(ci)
- && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().xfind(BeanIgnore.class,
m2.inner()).findFirst().isPresent());
+ && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().has(BeanIgnore.class, m2));
// @formatter:on
}
private static boolean shouldIgnore(BeanContext bc, ClassInfo ci) {
- return bc.getAnnotationProvider().xfind(BeanIgnore.class,
ci.inner()).findFirst().isPresent() || ci.isNonStaticMemberClass();
+ return ci.isNonStaticMemberClass() ||
bc.getAnnotationProvider().has(BeanIgnore.class, ci);
}
//------------------------------------------------------------------------------------------------------------------
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 f56ef730c8..d45667f813 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
@@ -158,7 +158,7 @@ public class AutoNumberSwap<T> extends ObjectSwap<T,Number>
{
&& (rt.isChildOf(Number.class) || (rt.isPrimitive() &&
rt.isAny(int.class, short.class, long.class, float.class, double.class,
byte.class)))
&& mi.hasAnyName(SWAP_METHOD_NAMES)
&& mi.hasParameterTypesLenient(BeanSession.class)
- && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().xfind(BeanIgnore.class,
m2.inner()).findFirst().isPresent());
+ && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().has(BeanIgnore.class, m2));
// @formatter:on
}
@@ -168,7 +168,7 @@ public class AutoNumberSwap<T> extends ObjectSwap<T,Number>
{
cs.isNotDeprecated()
&& cs.isVisible(bc.getBeanConstructorVisibility())
&& cs.hasParameterTypeParents(rt)
- && bc.getAnnotationProvider().xfind(BeanIgnore.class,
cs.inner()).findAny().isEmpty();
+ && ! bc.getAnnotationProvider().has(BeanIgnore.class,
cs);
// @formatter:on
}
@@ -181,17 +181,17 @@ public class AutoNumberSwap<T> extends
ObjectSwap<T,Number> {
&& mi.hasAnyName(UNSWAP_METHOD_NAMES)
&& mi.hasParameterTypesLenient(BeanSession.class,
rt.inner())
&& mi.hasReturnTypeParent(ci)
- && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().xfind(BeanIgnore.class,
m2.inner()).findFirst().isPresent());
+ && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().has(BeanIgnore.class, m2));
// @formatter:on
}
private static boolean shouldIgnore(BeanContext bc, ClassInfo ci) {
// @formatter:off
return
- bc.getAnnotationProvider().xfind(BeanIgnore.class,
ci.inner()).findFirst().isPresent()
- || ci.isNonStaticMemberClass()
+ ci.isNonStaticMemberClass()
|| ci.isPrimitive()
- || ci.isChildOf(Number.class);
+ || ci.isChildOf(Number.class)
+ || bc.getAnnotationProvider().has(BeanIgnore.class, ci);
// @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 c579228436..cc6cdf57e4 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
@@ -134,7 +134,7 @@ public class AutoObjectSwap<T> extends ObjectSwap<T,Object>
{
&& mi.isVisible(bc.getBeanMethodVisibility())
&& mi.hasAnyName(SWAP_METHOD_NAMES)
&& mi.hasParameterTypesLenient(BeanSession.class)
- && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().xfind(BeanIgnore.class,
m2.inner()).findFirst().isPresent());
+ && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().has(BeanIgnore.class, m2));
// @formatter:on
}
@@ -144,7 +144,7 @@ public class AutoObjectSwap<T> extends ObjectSwap<T,Object>
{
cs.isNotDeprecated()
&&
cs.isVisible(bc.getBeanConstructorVisibility())
&& cs.hasParameterTypeParents(rt)
- &&
bc.getAnnotationProvider().xfind(BeanIgnore.class,
cs.inner()).findAny().isEmpty();
+ && !
bc.getAnnotationProvider().has(BeanIgnore.class, cs);
// @formatter:on
}
@@ -157,12 +157,12 @@ public class AutoObjectSwap<T> extends
ObjectSwap<T,Object> {
&& mi.hasAnyName(UNSWAP_METHOD_NAMES)
&& mi.hasParameterTypesLenient(BeanSession.class,
rt.inner())
&& mi.hasReturnTypeParent(ci)
- && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().xfind(BeanIgnore.class,
m2.inner()).findFirst().isPresent());
+ && ! mi.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().has(BeanIgnore.class, m2));
// @formatter:on
}
private static boolean shouldIgnore(BeanContext bc, ClassInfo ci) {
- return bc.getAnnotationProvider().xfind(BeanIgnore.class,
ci.inner()).findFirst().isPresent() || ci.isNonStaticMemberClass();
+ return ci.isNonStaticMemberClass() ||
bc.getAnnotationProvider().has(BeanIgnore.class, ci);
}
//------------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/BuilderSwap.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/BuilderSwap.java
index 125866d891..b289385bb8 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/BuilderSwap.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swap/BuilderSwap.java
@@ -96,11 +96,10 @@ public class BuilderSwap<T,B> {
MethodInfo objectCreateMethod, builderCreateMethod;
ConstructorInfo objectConstructor = null;
ConstructorInfo builderConstructor;
-
-
bc.getAnnotationProvider().xfind(org.apache.juneau.annotation.Builder.class,
objectClass).map(x -> x.inner()).filter(x -> isNotVoid(x.value())).forEach(x ->
builderClass.set(x.value()));
-
var pci = ClassInfo.of(objectClass);
+
bc.getAnnotationProvider().find(org.apache.juneau.annotation.Builder.class,
pci).map(x -> x.inner()).filter(x -> isNotVoid(x.value())).forEach(x ->
builderClass.set(x.value()));
+
builderCreateMethod = getBuilderCreateMethod(pci);
if (builderClass.isEmpty() && nn(builderCreateMethod))
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 7b5a55397c..99aa7268d5 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 ->
bc.getAnnotationProvider().xfind(BeanIgnore.class,
x.inner()).findAny().isEmpty() && x.hasNumParameters(1) &&
x.isPublic()).forEach(x -> {
+ ci.getPublicConstructors().stream().filter(x -> !
bc.getAnnotationProvider().has(BeanIgnore.class, x) && 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.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanMeta.java
index 281955c828..0d606bf063 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanMeta.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanMeta.java
@@ -43,11 +43,12 @@ public class XmlBeanMeta extends ExtendedBeanMeta {
XmlFormat contentFormat = DEFAULT;
XmlBeanMetaBuilder(BeanMeta<?> beanMeta, XmlMetaProvider mp) {
- Class<?> c = beanMeta.getClassMeta().getInnerClass();
+ var c = beanMeta.getClassMeta().getInnerClass();
+ var ci = beanMeta.getClassMeta().getInfo();
Value<XmlFormat> defaultFormat = Value.empty();
-
beanMeta.getClassMeta().getBeanContext().getAnnotationProvider().xfind(Xml.class,
c).map(x -> x.inner()).filter(x -> true).forEach(x -> {
- XmlFormat xf = x.format();
+
beanMeta.getClassMeta().getBeanContext().getAnnotationProvider().find(Xml.class,
ci).map(x -> x.inner()).forEach(x -> {
+ var xf = x.format();
if (xf == ATTRS)
defaultFormat.set(XmlFormat.ATTR);
else if (xf.isOneOf(ELEMENTS, DEFAULT))
@@ -60,8 +61,8 @@ public class XmlBeanMeta extends ExtendedBeanMeta {
});
beanMeta.forEachProperty(null, p -> {
- XmlFormat xf =
mp.getXmlBeanPropertyMeta(p).getXmlFormat();
- ClassMeta<?> pcm = p.getClassMeta();
+ var xf =
mp.getXmlBeanPropertyMeta(p).getXmlFormat();
+ var pcm = p.getClassMeta();
if (xf == ATTR) {
attrs.put(p.getName(), p);
} else if (xf == ELEMENT) {
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
index f104ab6754..2d8f64b6ce 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/common/reflect/ClassInfo_Test.java
@@ -595,10 +595,10 @@ public class ClassInfo_Test extends TestBase {
@Test void lastAnnotation() {
// Use AnnotationProvider to get last annotation (first in
child-to-parent order stream)
var ap =
org.apache.juneau.common.reflect.AnnotationProvider.INSTANCE;
- assertEquals(7, ap.xfind(A.class, g3.inner()).map(x ->
x.inner()).findFirst().get().value());
- assertEquals(7, ap.xfind(A.class, g4.inner()).map(x ->
x.inner()).findFirst().get().value());
- assertEquals(3, ap.xfind(A.class, g5.inner()).map(x ->
x.inner()).findFirst().get().value());
- assertEquals(5, ap.xfind(A.class, g3.inner()).map(x ->
x.inner()).filter(x -> x.value() == 5).findFirst().get().value());
+ assertEquals(7, ap.find(A.class, g3).map(x ->
x.inner()).findFirst().get().value());
+ assertEquals(7, ap.find(A.class, g4).map(x ->
x.inner()).findFirst().get().value());
+ assertEquals(3, ap.find(A.class, g5).map(x ->
x.inner()).findFirst().get().value());
+ assertEquals(5, ap.find(A.class, g3).map(x ->
x.inner()).filter(x -> x.value() == 5).findFirst().get().value());
}
@Test void getPackageAnnotation() {
@@ -1872,7 +1872,7 @@ public class ClassInfo_Test extends TestBase {
void getParentsAndInterfaces_includesAllInterfaces() {
var ci = ClassInfo.of(Child.class);
var parentsAndInterfaces = ci.getParentsAndInterfaces();
-
+
// Should include:
// 1. Child itself
// 2. IChild (direct interface on Child)
@@ -1882,16 +1882,16 @@ public class ClassInfo_Test extends TestBase {
// 6. GrandParent (parent's parent)
// 7. IGrandParent (direct interface on GrandParent)
// 8. ISuperGrandParent (parent interface of IGrandParent)
-
+
var names = parentsAndInterfaces.stream()
.map(ClassInfo::getNameSimple)
.collect(Collectors.toList());
-
+
// Verify all expected classes/interfaces are present
assertTrue(names.contains("Child"), "Should include Child
itself");
assertTrue(names.contains("Parent"), "Should include Parent");
assertTrue(names.contains("GrandParent"), "Should include
GrandParent");
-
+
assertTrue(names.contains("IChild"), "Should include IChild");
assertTrue(names.contains("IParent"), "Should include IParent
from Parent");
assertTrue(names.contains("ISuperParent"), "Should include
ISuperParent from IParent hierarchy");