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 d3054fda75 org.apache.juneau.common.reflect API improvements
d3054fda75 is described below
commit d3054fda75c06d0680e70c8b3627cec06870c533
Author: James Bognar <[email protected]>
AuthorDate: Wed Nov 19 11:58:36 2025 -0500
org.apache.juneau.common.reflect API improvements
---
.../src/main/java/org/apache/juneau/BeanMeta.java | 25 +++++++++++-----------
.../src/main/java/org/apache/juneau/ClassMeta.java | 25 +++++++++++-----------
2 files changed, 25 insertions(+), 25 deletions(-)
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 4503970ac7..0fd9517cb1 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
@@ -33,6 +33,7 @@ import org.apache.juneau.annotation.*;
import org.apache.juneau.common.collections.*;
import org.apache.juneau.common.reflect.*;
import org.apache.juneau.common.reflect.Visibility;
+import org.apache.juneau.common.utils.*;
/**
* Encapsulates all access to the properties of a bean class (like a souped-up
{@link java.beans.BeanInfo}).
@@ -192,17 +193,15 @@ public class BeanMeta<T> {
}
String init(BeanMeta<T> beanMeta) {
- Class<?> c = classMeta.getInnerClass();
- ClassInfo ci = classMeta.getInfo();
+ var c = classMeta.getInnerClass();
+ var ci = classMeta.getInfo();
+ var ap = ctx.getAnnotationProvider();
try {
- // @formatter:off
- Visibility
- conVis =
ctx.getBeanConstructorVisibility(),
- cVis = ctx.getBeanClassVisibility(),
- mVis = ctx.getBeanMethodVisibility(),
- fVis = ctx.getBeanFieldVisibility();
- // @formatter:on
+ var conVis = ctx.getBeanConstructorVisibility();
+ var cVis = ctx.getBeanClassVisibility();
+ var mVis = ctx.getBeanMethodVisibility();
+ var fVis = ctx.getBeanFieldVisibility();
List<Class<?>> bdClasses = list();
if (nn(beanFilter) &&
nn(beanFilter.getBeanDictionary()))
@@ -230,8 +229,8 @@ public class BeanMeta<T> {
Map<String,BeanPropertyMeta.Builder>
normalProps = map();
- boolean hasBean =
ctx.getAnnotationProvider().xfind(Bean.class,
ci.inner()).findFirst().isPresent();
- boolean hasBeanIgnore =
ctx.getAnnotationProvider().xfind(BeanIgnore.class,
ci.inner()).findFirst().isPresent();
+ var hasBean = ap.has(Bean.class, ci);
+ var hasBeanIgnore = ap.has(BeanIgnore.class,
ci);
/// See if this class matches one the patterns
in the exclude-class list.
if (ctx.isNotABean(c))
@@ -248,12 +247,12 @@ public class BeanMeta<T> {
return "Class is not serializable";
// Look for @Beanc constructor on public
constructors.
- ci.getPublicConstructors().stream().filter(x ->
ctx.getAnnotationProvider().xfind(Beanc.class,
x.inner()).findAny().isPresent()).forEach(x -> {
+ ci.getPublicConstructors().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(StringUtils::isNotBlank).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.");
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 9e515231ba..7e3d76a7ce 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
@@ -100,7 +100,8 @@ public class ClassMeta<T> implements Type {
ClassMetaBuilder(Class<T> innerClass, BeanContext beanContext,
ObjectSwap<T,?>[] swaps, ObjectSwap<?,?>[] childSwaps) {
this.innerClass = innerClass;
this.beanContext = beanContext;
- BeanContext bc = beanContext;
+ var bc = beanContext;
+ var ap = bc.getAnnotationProvider();
this.childSwaps = childSwaps;
if (childSwaps == null) {
@@ -163,7 +164,7 @@ public class ClassMeta<T> implements Type {
cc = DATE;
else if (c.isArray())
cc = ARRAY;
- else if (ci.isChildOfAny(URL.class, URI.class)
|| bc.getAnnotationProvider().xfind(Uri.class,
ci.inner()).findFirst().isPresent())
+ else if (ci.isChildOfAny(URL.class, URI.class)
|| ap.has(Uri.class, ci))
cc = URI;
else if (ci.isChildOf(Reader.class))
cc = READER;
@@ -204,19 +205,19 @@ public class ClassMeta<T> implements Type {
.orElse(null);
// @formatter:on
- ci.getAllFields().stream().filter(x ->
bc.getAnnotationProvider().xfind(ParentProperty.class,
x.inner()).findAny().isPresent()).forEach(x -> {
+ ci.getAllFields().stream().filter(x ->
ap.has(ParentProperty.class, x)).forEach(x -> {
if (x.isStatic())
throw new ClassMetaRuntimeException(c,
"@ParentProperty used on invalid field ''{0}''. Must be static.", x);
parentPropertyMethod = new
Setter.FieldSetter(x.accessible().inner());
});
- ci.getAllFields().stream().filter(x ->
bc.getAnnotationProvider().xfind(NameProperty.class,
x.inner()).findAny().isPresent()).forEach(x -> {
+ ci.getAllFields().stream().filter(x ->
ap.has(NameProperty.class, x)).forEach(x -> {
if (x.isStatic())
throw new ClassMetaRuntimeException(c,
"@NameProperty used on invalid field ''{0}''. Must be static.", x);
namePropertyMethod = new
Setter.FieldSetter(x.accessible().inner());
});
- ci.getDeclaredFields().stream().filter(x ->
bc.getAnnotationProvider().xfind(Example.class,
x.inner()).findAny().isPresent()).forEach(x -> {
+ ci.getDeclaredFields().stream().filter(x ->
ap.has(Example.class, x)).forEach(x -> {
if (! (x.isStatic() &&
ci.isParentOf(x.getFieldType().inner())))
throw new ClassMetaRuntimeException(c,
"@Example used on invalid field ''{0}''. Must be static and an instance of the
type.", x);
exampleField = x.accessible().inner();
@@ -226,13 +227,13 @@ public class ClassMeta<T> implements Type {
List<MethodInfo> methods = ci.getAllMethods();
for (int i = methods.size() - 1; i >= 0; i--) {
MethodInfo m = methods.get(i);
- if (m.getMatchingMethods().stream().anyMatch(m2
-> bc.getAnnotationProvider().xfind(ParentProperty.class,
m2.inner()).findFirst().isPresent())) {
+ if (m.getMatchingMethods().stream().anyMatch(m2
-> ap.has(ParentProperty.class, m2))) {
if (m.isStatic() || !
m.hasNumParameters(1))
throw new
ClassMetaRuntimeException(c, "@ParentProperty used on invalid method ''{0}''.
Must not be static and have one argument.", m);
m.setAccessible();
parentPropertyMethod = new
Setter.MethodSetter(m.inner());
}
- if (m.getMatchingMethods().stream().anyMatch(m2
-> bc.getAnnotationProvider().xfind(NameProperty.class,
m2.inner()).findFirst().isPresent())) {
+ if (m.getMatchingMethods().stream().anyMatch(m2
-> ap.has(NameProperty.class, m2))) {
if (m.isStatic() || !
m.hasNumParameters(1))
throw new
ClassMetaRuntimeException(c, "@NameProperty used on invalid method ''{0}''.
Must not be static and have one argument.", m);
m.setAccessible();
@@ -240,7 +241,7 @@ public class ClassMeta<T> implements Type {
}
}
- ci.getDeclaredMethods().stream().filter(m ->
m.getMatchingMethods().stream().anyMatch(m2 ->
bc.getAnnotationProvider().xfind(Example.class,
m2.inner()).findFirst().isPresent())).forEach(m -> {
+ ci.getDeclaredMethods().stream().filter(m ->
m.getMatchingMethods().stream().anyMatch(m2 -> ap.has(Example.class,
m2))).forEach(m -> {
if (! (m.isStatic() &&
m.hasParameterTypesLenient(BeanSession.class) &&
ci.isParentOf(m.getReturnType().inner())))
throw new ClassMetaRuntimeException(c,
"@Example used on invalid method ''{0}''. Must be static and return an
instance of the declaring class.", m.toString());
m.setAccessible();
@@ -361,7 +362,7 @@ public class ClassMeta<T> implements Type {
if (nn(bc)) {
// Inline Context.forEachAnnotation() call
- bc.getAnnotationProvider().xfind(Bean.class,
c).map(x -> x.inner()).filter(x -> true).forEach(x -> {
+ ap.find(Bean.class, ci).map(x ->
x.inner()).forEach(x -> {
if (x.dictionary().length != 0)
beanRegistry = new
BeanRegistry(bc, null, x.dictionary());
// This could be a non-bean POJO with a
type name.
@@ -372,7 +373,7 @@ public class ClassMeta<T> implements Type {
if (example == null && nn(bc)) {
// Inline Context.forEachAnnotation() call
- bc.getAnnotationProvider().xfind(Example.class,
c).map(x -> x.inner()).filter(x -> ! x.value().isEmpty()).forEach(x -> example
= x.value());
+ ap.find(Example.class, ci).map(x ->
x.inner().value()).filter(x -> isNotEmpty(x)).forEach(x -> example = x);
}
if (example == null) {
@@ -498,7 +499,7 @@ public class ClassMeta<T> implements Type {
if (nn(bc))
// Inline Context.forEachAnnotation() call
- bc.getAnnotationProvider().xfind(Swap.class,
innerClass).map(x -> x.inner()).filter(x -> true).forEach(x ->
l.add(createSwap(x)));
+ bc.getAnnotationProvider().find(Swap.class, ci).map(x
-> x.inner()).forEach(x -> l.add(createSwap(x)));
ObjectSwap defaultSwap = DefaultSwaps.find(ci);
if (defaultSwap == null)
@@ -1937,7 +1938,7 @@ public class ClassMeta<T> implements Type {
A[] array = (A[])annotationArrayMap.get(type);
if (array == null && nn(beanContext)) {
List<A> l = list();
- beanContext.getAnnotationProvider().xfind(type,
info.inner()).map(x -> x.inner()).filter(x -> true).forEach(x -> l.add(x));
+ beanContext.getAnnotationProvider().find(type,
info).map(x -> x.inner()).filter(x -> true).forEach(x -> l.add(x));
array = (A[])Array.newInstance(type, l.size());
for (int i = 0; i < l.size(); i++)
Array.set(array, i, l.get(i));