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 33c7b01 ClassInfo refactoring.
33c7b01 is described below
commit 33c7b0168c0eef462a59c8460eb6292833f66145
Author: JamesBognar <[email protected]>
AuthorDate: Tue Jan 25 12:27:59 2022 -0500
ClassInfo refactoring.
---
.../{MetaProvider.java => AnnotationProvider.java} | 64 ++-
.../src/main/java/org/apache/juneau/BeanMeta.java | 43 +-
.../java/org/apache/juneau/BeanPropertyMeta.java | 36 +-
.../main/java/org/apache/juneau/BeanRegistry.java | 5 +-
.../src/main/java/org/apache/juneau/ClassMeta.java | 67 ++-
.../src/main/java/org/apache/juneau/Context.java | 233 ++++-----
.../org/apache/juneau/csv/CsvMetaProvider.java | 2 +-
.../apache/juneau/html/HtmlBeanPropertyMeta.java | 6 +-
.../org/apache/juneau/html/HtmlMetaProvider.java | 2 +-
.../org/apache/juneau/json/JsonMetaProvider.java | 2 +-
.../juneau/jsonschema/JsonSchemaMetaProvider.java | 2 +-
.../apache/juneau/msgpack/MsgPackMetaProvider.java | 2 +-
.../apache/juneau/oapi/OpenApiMetaProvider.java | 2 +-
.../juneau/plaintext/PlainTextMetaProvider.java | 2 +-
.../java/org/apache/juneau/reflect/ClassInfo.java | 561 ++++++++++-----------
.../org/apache/juneau/reflect/ConstructorInfo.java | 33 +-
.../java/org/apache/juneau/reflect/FieldInfo.java | 20 +-
.../java/org/apache/juneau/reflect/MethodInfo.java | 31 +-
.../apache/juneau/soap/SoapXmlMetaProvider.java | 2 +-
.../java/org/apache/juneau/swap/AutoListSwap.java | 8 +-
.../java/org/apache/juneau/swap/AutoMapSwap.java | 8 +-
.../org/apache/juneau/swap/AutoNumberSwap.java | 8 +-
.../org/apache/juneau/swap/AutoObjectSwap.java | 8 +-
.../java/org/apache/juneau/swap/BuilderSwap.java | 6 +-
.../java/org/apache/juneau/swap/SurrogateSwap.java | 2 +-
.../org/apache/juneau/uon/UonMetaProvider.java | 2 +-
.../urlencoding/UrlEncodingMetaProvider.java | 2 +-
.../java/org/apache/juneau/xml/XmlBeanMeta.java | 2 +-
.../org/apache/juneau/xml/XmlBeanPropertyMeta.java | 2 +-
.../org/apache/juneau/xml/XmlMetaProvider.java | 2 +-
.../java/org/apache/juneau/rest/RestContext.java | 25 +-
.../apache/juneau/reflection/ClassInfoTest.java | 55 +-
32 files changed, 582 insertions(+), 663 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MetaProvider.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationProvider.java
similarity index 82%
rename from
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MetaProvider.java
rename to
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationProvider.java
index 4b236ce..953bb59 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MetaProvider.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationProvider.java
@@ -17,24 +17,25 @@ import java.lang.reflect.*;
import java.util.function.*;
/**
- * Parent interface for all class/method language-specific metadata providers.
+ * Interface that provides the ability to look up annotations on
classes/methods/constructors/fields.
*
* <ul class='seealso'>
* <li class='extlink'>{@source}
* </ul>
*/
-public interface MetaProvider {
+public interface AnnotationProvider {
/**
* Default metadata provider.
*/
- public static MetaProvider DEFAULT = new MetaProvider() {
+ public static AnnotationProvider DEFAULT = new AnnotationProvider() {
@Override /* MetaProvider */
- public <A extends Annotation> void getAnnotations(Class<A> a,
Class<?> c, Consumer<A> consumer) {
+ public <A extends Annotation> void getAnnotations(Class<A> a,
Class<?> c, Predicate<A> predicate, Consumer<A> consumer) {
if (a != null && c != null)
for (A aa : c.getAnnotationsByType(a))
- consumer.accept(aa);
+ if (predicate.test(aa))
+ consumer.accept(aa);
}
@Override /* MetaProvider */
@@ -47,10 +48,11 @@ public interface MetaProvider {
}
@Override /* MetaProvider */
- public <A extends Annotation> void
getDeclaredAnnotations(Class<A> a, Class<?> c, Consumer<A> consumer) {
+ public <A extends Annotation> void
getDeclaredAnnotations(Class<A> a, Class<?> c, Predicate<A> predicate,
Consumer<A> consumer) {
if (a != null && c != null)
for (A aa : c.getDeclaredAnnotationsByType(a))
- consumer.accept(aa);
+ if (predicate.test(aa))
+ consumer.accept(aa);
}
@Override /* MetaProvider */
@@ -63,10 +65,11 @@ public interface MetaProvider {
}
@Override /* MetaProvider */
- public <A extends Annotation> void getAnnotations(Class<A> a,
Method m, Consumer<A> consumer) {
+ public <A extends Annotation> void getAnnotations(Class<A> a,
Method m, Predicate<A> predicate, Consumer<A> consumer) {
if (a != null && m != null)
for (A aa : m.getAnnotationsByType(a))
- consumer.accept(aa);
+ if (predicate.test(aa))
+ consumer.accept(aa);
}
@Override /* MetaProvider */
@@ -79,10 +82,11 @@ public interface MetaProvider {
}
@Override /* MetaProvider */
- public <A extends Annotation> void getAnnotations(Class<A> a,
Field f, Consumer<A> consumer) {
+ public <A extends Annotation> void getAnnotations(Class<A> a,
Field f, Predicate<A> predicate, Consumer<A> consumer) {
if (a != null && f != null)
for (A aa : f.getAnnotationsByType(a))
- consumer.accept(aa);
+ if (predicate.test(aa))
+ consumer.accept(aa);
}
@Override /* MetaProvider */
@@ -95,10 +99,11 @@ public interface MetaProvider {
}
@Override /* MetaProvider */
- public <A extends Annotation> void getAnnotations(Class<A> a,
Constructor<?> c, Consumer<A> consumer) {
+ public <A extends Annotation> void getAnnotations(Class<A> a,
Constructor<?> c, Predicate<A> predicate, Consumer<A> consumer) {
if (a != null && c != null)
for (A aa : c.getAnnotationsByType(a))
- consumer.accept(aa);
+ if (predicate.test(aa))
+ consumer.accept(aa);
}
@Override /* MetaProvider */
@@ -116,16 +121,17 @@ public interface MetaProvider {
*
* @param a The annotation type to find.
* @param c The class to search on.
- * @param consumer The consumer of the annotations.
+ * @param predicate The predicate.
+ * @param consumer The consumer.
*/
- <A extends Annotation> void getAnnotations(Class<A> a, Class<?> c,
Consumer<A> consumer);
+ <A extends Annotation> void getAnnotations(Class<A> a, Class<?> c,
Predicate<A> predicate, Consumer<A> consumer);
/**
* Finds the first annotation on the specified class matching the
specified predicate.
*
* @param a The annotation type to find.
* @param c The class to search on.
- * @param predicate The predicate to test against.
+ * @param predicate The predicate.
* @return The annotations in an unmodifiable list, or an empty list if
not found.
*/
<A extends Annotation> A getAnnotation(Class<A> a, Class<?> c,
Predicate<A> predicate);
@@ -135,16 +141,17 @@ public interface MetaProvider {
*
* @param a The annotation type to find.
* @param c The class to search on.
- * @param consumer The consumer of the annotations.
+ * @param predicate The predicate.
+ * @param consumer The consumer.
*/
- <A extends Annotation> void getDeclaredAnnotations(Class<A> a, Class<?>
c, Consumer<A> consumer);
+ <A extends Annotation> void getDeclaredAnnotations(Class<A> a, Class<?>
c, Predicate<A> predicate, Consumer<A> consumer);
/**
* Finds the specified declared annotations on the specified class that
match the specified predicate.
*
* @param a The annotation type to find.
* @param c The class to search on.
- * @param predicate The predicate to match the annotation against.
+ * @param predicate The predicate.
* @return The matched annotation, or <jk>null</jk> if no annotations
matched.
*/
<A extends Annotation> A getDeclaredAnnotation(Class<A> a, Class<?> c,
Predicate<A> predicate);
@@ -155,9 +162,10 @@ public interface MetaProvider {
* @param <A> The annotation type to find.
* @param a The annotation type to find.
* @param m The method to search on.
- * @param consumer The consumer of the annotations.
+ * @param predicate The predicate.
+ * @param consumer The consumer.
*/
- <A extends Annotation> void getAnnotations(Class<A> a, Method m,
Consumer<A> consumer);
+ <A extends Annotation> void getAnnotations(Class<A> a, Method m,
Predicate<A> predicate, Consumer<A> consumer);
/**
* Finds the specified annotations on the specified method.
@@ -165,7 +173,7 @@ public interface MetaProvider {
* @param <A> The annotation type to find.
* @param a The annotation type to find.
* @param m The method to search on.
- * @param predicate The predicate to match the annotation against.
+ * @param predicate The predicate.
* @return The matched annotation, or <jk>null</jk> if no annotations
matched.
*/
<A extends Annotation> A getAnnotation(Class<A> a, Method m,
Predicate<A> predicate);
@@ -176,9 +184,10 @@ public interface MetaProvider {
* @param <A> The annotation type to find.
* @param a The annotation type to find.
* @param f The field to search on.
- * @param consumer The consumer of the annotations.
+ * @param predicate The predicate.
+ * @param consumer The consumer.
*/
- <A extends Annotation> void getAnnotations(Class<A> a, Field f,
Consumer<A> consumer);
+ <A extends Annotation> void getAnnotations(Class<A> a, Field f,
Predicate<A> predicate, Consumer<A> consumer);
/**
* Finds the specified annotations on the specified field.
@@ -186,7 +195,7 @@ public interface MetaProvider {
* @param <A> The annotation type to find.
* @param a The annotation type to find.
* @param f The field to search on.
- * @param predicate The predicate to match the annotation against.
+ * @param predicate The predicate.
* @return The matched annotation, or <jk>null</jk> if no annotations
matched.
*/
<A extends Annotation> A getAnnotation(Class<A> a, Field f,
Predicate<A> predicate);
@@ -197,9 +206,10 @@ public interface MetaProvider {
* @param <A> The annotation type to find.
* @param a The annotation type to find.
* @param c The constructor to search on.
- * @param consumer The consumer of the annotations.
+ * @param predicate The predicate.
+ * @param consumer The consumer.
*/
- <A extends Annotation> void getAnnotations(Class<A> a, Constructor<?>
c, Consumer<A> consumer);
+ <A extends Annotation> void getAnnotations(Class<A> a, Constructor<?>
c, Predicate<A> predicate, Consumer<A> consumer);
/**
* Finds the specified annotations on the specified constructor.
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 be14842..f7f712e 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
@@ -20,11 +20,8 @@ import static org.apache.juneau.BeanMeta.MethodType.*;
import java.beans.*;
import java.io.*;
-import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.*;
-import java.util.function.*;
-
import org.apache.juneau.annotation.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.internal.*;
@@ -204,9 +201,8 @@ public class BeanMeta<T> {
Map<String,BeanPropertyMeta.Builder>
normalProps = new LinkedHashMap<>();
- Annotation ba = ci.getAnyLastAnnotation(ctx,
Bean.class, BeanIgnore.class);
- boolean hasBean = ba != null &&
ba.annotationType() == Bean.class;
- boolean hasBeanIgnore = ba != null &&
ba.annotationType() == BeanIgnore.class;
+ boolean hasBean = ci.hasAnnotation(ctx,
Bean.class);
+ boolean hasBeanIgnore = ci.hasAnnotation(ctx,
BeanIgnore.class);
/// See if this class matches one the patterns
in the exclude-class list.
if (ctx.isNotABean(c))
@@ -224,16 +220,12 @@ public class BeanMeta<T> {
// Look for @Beanc constructor on public
constructors.
for (ConstructorInfo x :
ci.getPublicConstructors()) {
- if (ctx.hasAnnotation(Beanc.class, x)) {
+ if (x.hasAnnotation(ctx, Beanc.class)) {
if (constructor != null)
throw new
BeanRuntimeException(c, "Multiple instances of '@Beanc' found.");
constructor = x;
constructorArgs = new String[0];
- Consumer<Beanc> consumer = y ->
{
- if (!
y.properties().isEmpty())
- constructorArgs
= split(y.properties());
- };
- ctx.getAnnotations(Beanc.class,
x.inner(), consumer);
+ ctx.getAnnotations(Beanc.class,
x.inner(), y -> ! y.properties().isEmpty(), z -> constructorArgs =
split(z.properties()));
if (!
x.hasNumParams(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.");
@@ -253,16 +245,12 @@ public class BeanMeta<T> {
// Look for @Beanc on all other constructors.
if (constructor == null) {
for (ConstructorInfo x :
ci.getDeclaredConstructors()) {
- if
(ctx.hasAnnotation(Beanc.class, x)) {
+ if (x.hasAnnotation(ctx,
Beanc.class)) {
if (constructor != null)
throw new
BeanRuntimeException(c, "Multiple instances of '@Beanc' found.");
constructor = x;
constructorArgs = new
String[0];
- Consumer<Beanc>
consumer = y -> {
- if (!
y.properties().isEmpty())
-
constructorArgs = split(y.properties());
- };
-
ctx.getAnnotations(Beanc.class, x.inner(), consumer);
+
ctx.getAnnotations(Beanc.class, x.inner(), y -> ! y.properties().isEmpty(), z
-> constructorArgs = split(z.properties()));
if (!
x.hasNumParams(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.");
@@ -546,8 +534,8 @@ public class BeanMeta<T> {
private String findPropertyName(Field f) {
List<Beanp> lp = new ArrayList<>();
List<Name> ln = new ArrayList<>();
- ctx.getAnnotations(Beanp.class, f, x -> lp.add(x));
- ctx.getAnnotations(Name.class, f, x -> ln.add(x));
+ ctx.getAnnotations(Beanp.class, f, x -> true, x ->
lp.add(x));
+ ctx.getAnnotations(Name.class, f, x -> true, x ->
ln.add(x));
String name = bpName(lp, ln);
if (isNotEmpty(name))
return name;
@@ -674,17 +662,16 @@ public class BeanMeta<T> {
if (m.getParamCount() > 2)
continue;
- BeanIgnore bi =
ctx.getLastAnnotation(BeanIgnore.class, m.inner());
- if (bi != null)
+ if (m.hasAnnotation(ctx, BeanIgnore.class))
continue;
- Transient t =
ctx.getLastAnnotation(Transient.class, m.inner());
+ Transient t = m.getLastAnnotation(ctx,
Transient.class);
if (t != null && t.value())
continue;
List<Beanp> lp = new ArrayList<>();
List<Name> ln = new ArrayList<>();
- ctx.getAnnotations(Beanp.class, m.inner(), x ->
lp.add(x));
- ctx.getAnnotations(Name.class, m.inner(), x ->
ln.add(x));
+ ctx.getAnnotations(Beanp.class, m.inner(), x ->
true, x -> lp.add(x));
+ ctx.getAnnotations(Name.class, m.inner(), x ->
true, x -> ln.add(x));
if (! (m.isVisible(v) || lp.size() > 0 ||
ln.size() > 0))
continue;
@@ -782,8 +769,8 @@ public class BeanMeta<T> {
x -> x.isNotStatic()
&& (x.isNotTransient() || noIgnoreTransients)
&& (x.hasNoAnnotation(Transient.class) ||
noIgnoreTransients)
- && x.hasNoAnnotation(BeanIgnore.class, ctx)
- && (v.isVisible(x.inner()) ||
ctx.hasAnnotation(Beanp.class, x)),
+ && x.hasNoAnnotation(ctx, BeanIgnore.class)
+ && (v.isVisible(x.inner()) ||
x.hasAnnotation(ctx, Beanp.class)),
x -> l.add(x.inner())
);
}
@@ -797,7 +784,7 @@ public class BeanMeta<T> {
x -> x.isNotStatic()
&& (x.isNotTransient() || noIgnoreTransients)
&& (x.hasNoAnnotation(Transient.class) ||
noIgnoreTransients)
- && x.hasNoAnnotation(BeanIgnore.class, ctx)
+ && x.hasNoAnnotation(ctx, BeanIgnore.class)
&& x.hasName(name)
);
if (f != null)
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 af3da26..ee4acb9 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
@@ -181,7 +181,7 @@ public final class BeanPropertyMeta {
if (innerField != null) {
List<Beanp> lp = new ArrayList<>();
- bc.getAnnotations(Beanp.class, innerField, x ->
lp.add(x));
+ bc.getAnnotations(Beanp.class, innerField, x ->
true, x -> lp.add(x));
if (field != null || lp.size() > 0) {
// 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.
@@ -197,13 +197,13 @@ public final class BeanPropertyMeta {
if (! p.wo().isEmpty())
writeOnly =
Boolean.valueOf(p.wo());
}
- bc.getAnnotations(Swap.class, innerField, x ->
swap = getPropertySwap(x));
+ bc.getAnnotations(Swap.class, innerField, x ->
true, x -> swap = getPropertySwap(x));
isUri |= bc.getAnnotation(Uri.class,
innerField, x->true) != null;
}
if (getter != null) {
List<Beanp> lp = new ArrayList<>();
- bc.getAnnotations(Beanp.class, getter, x ->
lp.add(x));
+ bc.getAnnotations(Beanp.class, getter, x ->
true, x -> lp.add(x));
if (rawTypeMeta == null)
rawTypeMeta =
bc.resolveClassMeta(last(lp), getter.getGenericReturnType(), typeVarImpls);
isUri |= (rawTypeMeta.isUri() ||
bc.hasAnnotation(Uri.class, getter));
@@ -216,12 +216,12 @@ public final class BeanPropertyMeta {
if (! p.wo().isEmpty())
writeOnly =
Boolean.valueOf(p.wo());
}
- bc.getAnnotations(Swap.class, getter, x -> swap
= getPropertySwap(x));
+ bc.getAnnotations(Swap.class, getter, x ->
true, x -> swap = getPropertySwap(x));
}
if (setter != null) {
List<Beanp> lp = new ArrayList<>();
- bc.getAnnotations(Beanp.class, setter, x ->
lp.add(x));
+ bc.getAnnotations(Beanp.class, setter, x ->
true, x -> lp.add(x));
if (rawTypeMeta == null)
rawTypeMeta =
bc.resolveClassMeta(last(lp), setter.getGenericParameterTypes()[0],
typeVarImpls);
isUri |= (rawTypeMeta.isUri() ||
bc.hasAnnotation(Uri.class, setter));
@@ -236,7 +236,7 @@ public final class BeanPropertyMeta {
if (! p.wo().isEmpty())
writeOnly =
Boolean.valueOf(p.wo());
}
- bc.getAnnotations(Swap.class, setter, x -> swap
= getPropertySwap(x));
+ bc.getAnnotations(Swap.class, setter, x ->
true, x -> swap = getPropertySwap(x));
}
if (rawTypeMeta == null)
@@ -1111,22 +1111,22 @@ public final class BeanPropertyMeta {
BeanContext bc = beanContext;
if (a == null)
return l;
- getBeanMeta().getClassMeta().getInfo().getAnnotations(a, bc, x
-> l.add(x));
+ getBeanMeta().getClassMeta().getInfo().getAnnotations(bc, a, x
-> true, x -> l.add(x));
if (field != null) {
- bc.getAnnotations(a, field, x -> l.add(x));
- ClassInfo.of(field.getType()).getAnnotations(a, bc, x
-> l.add(x));
+ bc.getAnnotations(a, field, x -> true, x -> l.add(x));
+ ClassInfo.of(field.getType()).getAnnotations(bc, a, x
-> true, x -> l.add(x));
}
if (getter != null) {
- bc.getAnnotations(a, getter, x -> l.add(x));
- ClassInfo.of(getter.getReturnType()).getAnnotations(a,
bc, x -> l.add(x));
+ bc.getAnnotations(a, getter, x -> true, x -> l.add(x));
+ ClassInfo.of(getter.getReturnType()).getAnnotations(bc,
a, x -> true, x -> l.add(x));
}
if (setter != null) {
- bc.getAnnotations(a, setter, x -> l.add(x));
- ClassInfo.of(setter.getReturnType()).getAnnotations(a,
bc, x -> l.add(x));
+ bc.getAnnotations(a, setter, x -> true, x -> l.add(x));
+ ClassInfo.of(setter.getReturnType()).getAnnotations(bc,
a, x -> true, x -> l.add(x));
}
if (extraKeys != null) {
- bc.getAnnotations(a, extraKeys, x -> l.add(x));
-
ClassInfo.of(extraKeys.getReturnType()).getAnnotations(a, bc, x -> l.add(x));
+ bc.getAnnotations(a, extraKeys, x -> true, x ->
l.add(x));
+
ClassInfo.of(extraKeys.getReturnType()).getAnnotations(bc, a, x -> true, x ->
l.add(x));
}
return l;
@@ -1144,9 +1144,9 @@ public final class BeanPropertyMeta {
BeanContext bc = beanContext;
if (a == null)
return l;
- bc.getAnnotations(a, field, x -> l.add(x));
- bc.getAnnotations(a, getter, x -> l.add(x));
- bc.getAnnotations(a, setter, x -> l.add(x));
+ bc.getAnnotations(a, field, x -> true, x -> l.add(x));
+ bc.getAnnotations(a, getter, x -> true, x -> l.add(x));
+ bc.getAnnotations(a, setter, x -> true, x -> l.add(x));
return l;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanRegistry.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanRegistry.java
index e8de10b..eee2938 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanRegistry.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanRegistry.java
@@ -20,7 +20,6 @@ import java.util.*;
import java.util.concurrent.*;
import org.apache.juneau.annotation.*;
-import org.apache.juneau.internal.*;
import org.apache.juneau.reflect.*;
/**
@@ -95,9 +94,9 @@ public class BeanRegistry {
}
} else {
Value<String> typeName = Value.empty();
- ci.getAnnotations(Bean.class,
beanContext, x -> typeName.setIf(x.typeName(), StringUtils::isNotEmpty));
+ ci.getAnnotations(beanContext,
Bean.class, x -> isNotEmpty(x.typeName()), x -> typeName.set(x.typeName()));
addToMap(
- typeName.orElseThrow(() -> new
BeanRuntimeException("Class ''{0}'' was passed to BeanRegistry but it doesn't
have a @Bean(typeName) annotation defined.", className(c))),
+ typeName.orElseThrow(() -> new
BeanRuntimeException("Class ''{0}'' was passed to BeanRegistry but it doesn't
have a @Bean(typeName) annotation defined.", className(c))),
beanContext.getClassMeta(c)
);
}
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 f1da906..25217d8 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
@@ -417,7 +417,7 @@ public final class ClassMeta<T> implements Type {
cc = DATE;
else if (c.isArray())
cc = ARRAY;
- else if (ci.isChildOfAny(URL.class, URI.class)
|| bc.hasAnnotation(Uri.class, c))
+ else if (ci.isChildOfAny(URL.class, URI.class)
|| ci.hasAnnotation(bc, Uri.class))
cc = URI;
else if (ci.isChildOf(Reader.class))
cc = READER;
@@ -456,41 +456,35 @@ public final class ClassMeta<T> implements Type {
).map(x -> x.inner())
.orElse(null);
- for (FieldInfo f : ci.getAllFieldsParentFirst()) {
- if (bc.hasAnnotation(ParentProperty.class, f)) {
- if (f.isStatic())
- throw new
ClassMetaRuntimeException(c, "@ParentProperty used on invalid field ''{0}''.
Must be static.", f);
- f.setAccessible();
- parentPropertyMethod = new
Setter.FieldSetter(f.inner());
- }
- if (bc.hasAnnotation(NameProperty.class, f)) {
- if (f.isStatic())
- throw new
ClassMetaRuntimeException(c, "@NameProperty used on invalid field ''{0}''.
Must be static.", f);
- f.setAccessible();
- namePropertyMethod = new
Setter.FieldSetter(f.inner());
- }
- }
+ ci.getAllFields(x -> x.hasAnnotation(bc,
ParentProperty.class), 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());
+ });
- for (FieldInfo f : ci.getDeclaredFields()) {
- if (bc.hasAnnotation(Example.class, f)) {
- if (! (f.isStatic() &&
ci.isParentOf(f.getType().inner())))
- throw new
ClassMetaRuntimeException(c, "@Example used on invalid field ''{0}''. Must be
static and an instance of the type.", f);
- f.setAccessible();
- exampleField = f.inner();
- }
- }
+ ci.getAllFields(x -> x.hasAnnotation(bc,
NameProperty.class), 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(x -> x.hasAnnotation(bc,
Example.class), x -> {
+ if (! (x.isStatic() &&
ci.isParentOf(x.getType().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();
+ });
// Find @NameProperty and @ParentProperty methods if
present.
List<MethodInfo> methods = ci.getMethods();
for (int i = methods.size()-1; i >=0; i--) {
MethodInfo m = methods.get(i);
- if (bc.hasAnnotation(ParentProperty.class, m)) {
+ if (m.hasAnnotation(bc, ParentProperty.class)) {
if (m.isStatic() || ! m.hasNumParams(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 (bc.hasAnnotation(NameProperty.class, m)) {
+ if (m.hasAnnotation(bc, NameProperty.class)) {
if (m.isStatic() || ! m.hasNumParams(1))
throw new
ClassMetaRuntimeException(c, "@NameProperty used on invalid method ''{0}''.
Must not be static and have one argument.", m);
m.setAccessible();
@@ -499,7 +493,7 @@ public final class ClassMeta<T> implements Type {
}
for (MethodInfo m : ci.getDeclaredMethods()) {
- if (bc.hasAnnotation(Example.class, m)) {
+ if (m.hasAnnotation(bc, Example.class)) {
if (! (m.isStatic() &&
m.hasFuzzyParamTypes(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();
@@ -622,7 +616,7 @@ public final class ClassMeta<T> implements Type {
invocationHandler = new
BeanProxyInvocationHandler<T>(beanMeta);
if (bc != null) {
- bc.getAnnotations(Bean.class, c, x -> {
+ bc.getAnnotations(Bean.class, c, x -> true, x
-> {
if (x.dictionary().length != 0)
beanRegistry = new
BeanRegistry(bc, null, x.dictionary());
// This could be a non-bean POJO with a
type name.
@@ -632,10 +626,7 @@ public final class ClassMeta<T> implements Type {
}
if (example == null && bc != null) {
- bc.getAnnotations(Example.class, c, x -> {
- if (! x.value().isEmpty())
- example = x.value();
- });
+ bc.getAnnotations(Example.class, c, x -> !
x.value().isEmpty(), x -> example = x.value());
}
if (example == null) {
@@ -693,7 +684,7 @@ public final class ClassMeta<T> implements Type {
private BeanFilter findBeanFilter(BeanContext bc) {
try {
- List<Bean> ba = info.getAnnotations(Bean.class,
bc);
+ List<Bean> ba = info.getAnnotations(bc,
Bean.class);
if (! ba.isEmpty())
return
BeanFilter.create(innerClass).applyAnnotations(ba).build();
} catch (Exception e) {
@@ -704,7 +695,7 @@ public final class ClassMeta<T> implements Type {
private MarshalledFilter findMarshalledFilter(BeanContext bc) {
try {
- List<Marshalled> ba =
info.getAnnotations(Marshalled.class, bc);
+ List<Marshalled> ba = info.getAnnotations(bc,
Marshalled.class);
if (! ba.isEmpty())
return
MarshalledFilter.create(innerClass).applyAnnotations(ba).build();
} catch (Exception e) {
@@ -716,7 +707,7 @@ public final class ClassMeta<T> implements Type {
private void findSwaps(List<ObjectSwap> l, BeanContext bc) {
if (bc != null)
- bc.getAnnotations(Swap.class, innerClass, x->
l.add(createSwap(x)));
+ bc.getAnnotations(Swap.class, innerClass, x ->
true, x -> l.add(createSwap(x)));
ObjectSwap defaultSwap = DefaultSwaps.find(ci);
if (defaultSwap == null)
@@ -2092,8 +2083,8 @@ public final class ClassMeta<T> implements Type {
Optional<A> o = (Optional<A>)annotationLastMap.get(a);
if (o == null) {
if (beanContext == null)
- return info.getLastAnnotation(a,
BeanContext.DEFAULT);
- o = Optional.ofNullable(info.getLastAnnotation(a,
beanContext));
+ return
info.getLastAnnotation(BeanContext.DEFAULT, a);
+ o =
Optional.ofNullable(info.getLastAnnotation(beanContext, a));
annotationLastMap.put(a, o);
}
return o.orElse(null);
@@ -2112,11 +2103,11 @@ public final class ClassMeta<T> implements Type {
A[] array = (A[])annotationArrayMap.get(a);
if (array == null) {
if (beanContext == null) {
- info.getAnnotations(a, BeanContext.DEFAULT,
consumer);
+ info.getAnnotations(BeanContext.DEFAULT, a, x->
true, consumer);
return this;
}
List<A> l = new ArrayList<>();
- info.getAnnotations(a, beanContext, x -> l.add(x));
+ info.getAnnotations(beanContext, a, x-> true, x ->
l.add(x));
array = (A[])Array.newInstance(a, l.size());
for (int i = 0; i < l.size(); i++)
Array.set(array, i, l.get(i));
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 62de0b2..a4b9310 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
@@ -73,7 +73,7 @@ import org.apache.juneau.xml.annotation.*;
* <li class='extlink'>{@source}
* </ul>
*/
-public abstract class Context implements MetaProvider {
+public abstract class Context implements AnnotationProvider {
//-----------------------------------------------------------------------------------------------------------------
// Static
@@ -935,10 +935,11 @@ public abstract class Context implements MetaProvider {
private TwoKeyConcurrentCache<Constructor<?>,Class<? extends
Annotation>,Annotation[]> constructorAnnotationCache = new
TwoKeyConcurrentCache<>(DISABLE_ANNOTATION_CACHING);
@Override /* MetaProvider */
- public <A extends Annotation> void getAnnotations(Class<A> a, Class<?>
c, Consumer<A> consumer) {
+ public <A extends Annotation> void getAnnotations(Class<A> a, Class<?>
c, Predicate<A> predicate, Consumer<A> consumer) {
if (a != null && c != null)
for (A aa : annotations(a, c))
- consumer.accept(aa);
+ if (predicate.test(aa))
+ consumer.accept(aa);
}
@Override /* MetaProvider */
@@ -950,26 +951,12 @@ public abstract class Context implements MetaProvider {
return null;
}
- @SuppressWarnings("unchecked")
- private <A extends Annotation> A[] annotations(Class<A> a, Class<?> c) {
- A[] aa = (A[])classAnnotationCache.get(c, a);
- if (aa == null) {
- A[] x = c.getAnnotationsByType(a);
- AList<Annotation> l = new AList<>(Arrays.asList(x));
- annotationMap.appendAll(c, a, l);
- aa = (A[]) Array.newInstance(a, l.size());
- for (int i = 0; i < l.size(); i++)
- Array.set(aa, i, l.get(i));
- classAnnotationCache.put(c, a, aa);
- }
- return aa;
- }
-
@Override /* MetaProvider */
- public <A extends Annotation> void getDeclaredAnnotations(Class<A> a,
Class<?> c, Consumer<A> consumer) {
+ public <A extends Annotation> void getDeclaredAnnotations(Class<A> a,
Class<?> c, Predicate<A> predicate, Consumer<A> consumer) {
if (a != null && c != null)
for (A aa : declaredAnnotations(a, c))
- consumer.accept(aa);
+ if (predicate.test(aa))
+ consumer.accept(aa);
}
@Override /* MetaProvider */
@@ -981,26 +968,12 @@ public abstract class Context implements MetaProvider {
return null;
}
- @SuppressWarnings("unchecked")
- private <A extends Annotation> A[] declaredAnnotations(Class<A> a,
Class<?> c) {
- A[] aa = (A[])declaredClassAnnotationCache.get(c, a);
- if (aa == null) {
- A[] x = c.getDeclaredAnnotationsByType(a);
- AList<Annotation> l = new AList<>(Arrays.asList(x));
- annotationMap.appendAll(c, a, l);
- aa = (A[]) Array.newInstance(a, l.size());
- for (int i = 0; i < l.size(); i++)
- Array.set(aa, i, l.get(i));
- declaredClassAnnotationCache.put(c, a, aa);
- }
- return aa;
- }
-
@Override /* MetaProvider */
- public <A extends Annotation> void getAnnotations(Class<A> a, Method m,
Consumer<A> consumer) {
+ public <A extends Annotation> void getAnnotations(Class<A> a, Method m,
Predicate<A> predicate, Consumer<A> consumer) {
if (a != null && m != null)
for (A aa : annotations(a, m))
- consumer.accept(aa);
+ if (predicate.test(aa))
+ consumer.accept(aa);
}
@Override /* MetaProvider */
@@ -1012,26 +985,12 @@ public abstract class Context implements MetaProvider {
return null;
}
- @SuppressWarnings("unchecked")
- private <A extends Annotation> A[] annotations(Class<A> a, Method m) {
- A[] aa = (A[])methodAnnotationCache.get(m, a);
- if (aa == null) {
- A[] x = m.getAnnotationsByType(a);
- AList<Annotation> l = new AList<>(Arrays.asList(x));
- annotationMap.appendAll(m, a, l);
- aa = (A[]) Array.newInstance(a, l.size());
- for (int i = 0; i < l.size(); i++)
- Array.set(aa, i, l.get(i));
- methodAnnotationCache.put(m, a, aa);
- }
- return aa;
- }
-
@Override /* MetaProvider */
- public <A extends Annotation> void getAnnotations(Class<A> a, Field f,
Consumer<A> consumer) {
+ public <A extends Annotation> void getAnnotations(Class<A> a, Field f,
Predicate<A> predicate, Consumer<A> consumer) {
if (a != null && f != null)
for (A aa : annotations(a, f))
- consumer.accept(aa);
+ if (predicate.test(aa))
+ consumer.accept(aa);
}
@Override /* MetaProvider */
@@ -1043,26 +1002,12 @@ public abstract class Context implements MetaProvider {
return null;
}
- @SuppressWarnings("unchecked")
- private <A extends Annotation> A[] annotations(Class<A> a, Field f) {
- A[] aa = (A[])fieldAnnotationCache.get(f, a);
- if (aa == null) {
- A[] x = f.getAnnotationsByType(a);
- AList<Annotation> l = new AList<>(Arrays.asList(x));
- annotationMap.appendAll(f, a, l);
- aa = (A[]) Array.newInstance(a, l.size());
- for (int i = 0; i < l.size(); i++)
- Array.set(aa, i, l.get(i));
- fieldAnnotationCache.put(f, a, aa);
- }
- return aa;
- }
-
@Override /* MetaProvider */
- public <A extends Annotation> void getAnnotations(Class<A> a,
Constructor<?> c, Consumer<A> consumer) {
+ public <A extends Annotation> void getAnnotations(Class<A> a,
Constructor<?> c, Predicate<A> predicate, Consumer<A> consumer) {
if (a != null && c != null)
for (A aa : annotations(a, c))
- consumer.accept(aa);
+ if (predicate.test(aa))
+ consumer.accept(aa);
}
@Override /* MetaProvider */
@@ -1074,45 +1019,6 @@ public abstract class Context implements MetaProvider {
return null;
}
- @SuppressWarnings("unchecked")
- private <A extends Annotation> A[] annotations(Class<A> a,
Constructor<?> c) {
- A[] aa = (A[])constructorAnnotationCache.get(c, a);
- if (aa == null) {
- A[] x = c.getAnnotationsByType(a);
- AList<Annotation> l = new AList<>(Arrays.asList(x));
- annotationMap.appendAll(c, a, l);
- aa = (A[]) Array.newInstance(a, l.size());
- for (int i = 0; i < l.size(); i++)
- Array.set(aa, i, l.get(i));
- constructorAnnotationCache.put(c, a, aa);
- }
- return aa;
- }
-
- /**
- * Finds the last specified annotations on the specified method.
- *
- * @param <A> The annotation type to find.
- * @param a The annotation type to find.
- * @param m The method to search on.
- * @return The annotation, or <jk>null</jk> if not found.
- */
- public <A extends Annotation> A getLastAnnotation(Class<A> a, Method m)
{
- return last(annotations(a, m));
- }
-
- /**
- * Finds the last specified annotations on the specified field.
- *
- * @param <A> The annotation type to find.
- * @param a The annotation type to find.
- * @param f The field to search on.
- * @return The annotation, or <jk>null</jk> if not found.
- */
- public <A extends Annotation> A getLastAnnotation(Class<A> a, Field f) {
- return last(annotations(a, f));
- }
-
/**
* Returns <jk>true</jk> if <c>getAnnotation(a,c)</c> returns a
non-null value.
*
@@ -1125,17 +1031,6 @@ public abstract class Context implements MetaProvider {
}
/**
- * Returns <jk>true</jk> if <c>getAnnotation(a,c)</c> returns a
non-null value.
- *
- * @param a The annotation being checked for.
- * @param c 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> a,
ClassInfo c) {
- return annotations(a, c == null ? null : c.inner()).length > 0;
- }
-
- /**
* Returns <jk>true</jk> if <c>getAnnotation(a,m)</c> returns a
non-null value.
*
* @param a The annotation being checked for.
@@ -1147,25 +1042,14 @@ public abstract class Context implements MetaProvider {
}
/**
- * Returns <jk>true</jk> if <c>getAnnotation(a,m)</c> returns a
non-null value.
- *
- * @param a The annotation being checked for.
- * @param m 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> a,
MethodInfo m) {
- return annotations(a, m == null ? null : m.inner()).length > 0;
- }
-
- /**
* Returns <jk>true</jk> if <c>getAnnotation(a,f)</c> returns a
non-null value.
*
* @param a The annotation being checked for.
* @param f 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> a,
FieldInfo f) {
- return annotations(a, f == null ? null : f.inner()).length > 0;
+ public <A extends Annotation> boolean hasAnnotation(Class<A> a, Field
f) {
+ return annotations(a, f).length > 0;
}
/**
@@ -1173,10 +1057,85 @@ public abstract class Context implements MetaProvider {
*
* @param a The annotation being checked for.
* @param c The constructor being checked on.
- * @return <jk>true</jk> if the annotation exists on the specified
constructor.
+ * @return <jk>true</jk> if the annotation exists on the specified
field.
*/
- public <A extends Annotation> boolean hasAnnotation(Class<A> a,
ConstructorInfo c) {
- return annotations(a, c == null ? null : c.inner()).length > 0;
+ public <A extends Annotation> boolean hasAnnotation(Class<A> a,
Constructor<?> c) {
+ return annotations(a, c).length > 0;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <A extends Annotation> A[] annotations(Class<A> a, Class<?> c) {
+ A[] aa = (A[])classAnnotationCache.get(c, a);
+ if (aa == null) {
+ A[] x = c.getAnnotationsByType(a);
+ AList<Annotation> l = new AList<>(Arrays.asList(x));
+ annotationMap.appendAll(c, a, l);
+ aa = (A[]) Array.newInstance(a, l.size());
+ for (int i = 0; i < l.size(); i++)
+ Array.set(aa, i, l.get(i));
+ classAnnotationCache.put(c, a, aa);
+ }
+ return aa;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <A extends Annotation> A[] declaredAnnotations(Class<A> a,
Class<?> c) {
+ A[] aa = (A[])declaredClassAnnotationCache.get(c, a);
+ if (aa == null) {
+ A[] x = c.getDeclaredAnnotationsByType(a);
+ AList<Annotation> l = new AList<>(Arrays.asList(x));
+ annotationMap.appendAll(c, a, l);
+ aa = (A[]) Array.newInstance(a, l.size());
+ for (int i = 0; i < l.size(); i++)
+ Array.set(aa, i, l.get(i));
+ declaredClassAnnotationCache.put(c, a, aa);
+ }
+ return aa;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <A extends Annotation> A[] annotations(Class<A> a, Method m) {
+ A[] aa = (A[])methodAnnotationCache.get(m, a);
+ if (aa == null) {
+ A[] x = m.getAnnotationsByType(a);
+ AList<Annotation> l = new AList<>(Arrays.asList(x));
+ annotationMap.appendAll(m, a, l);
+ aa = (A[]) Array.newInstance(a, l.size());
+ for (int i = 0; i < l.size(); i++)
+ Array.set(aa, i, l.get(i));
+ methodAnnotationCache.put(m, a, aa);
+ }
+ return aa;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <A extends Annotation> A[] annotations(Class<A> a, Field f) {
+ A[] aa = (A[])fieldAnnotationCache.get(f, a);
+ if (aa == null) {
+ A[] x = f.getAnnotationsByType(a);
+ AList<Annotation> l = new AList<>(Arrays.asList(x));
+ annotationMap.appendAll(f, a, l);
+ aa = (A[]) Array.newInstance(a, l.size());
+ for (int i = 0; i < l.size(); i++)
+ Array.set(aa, i, l.get(i));
+ fieldAnnotationCache.put(f, a, aa);
+ }
+ return aa;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <A extends Annotation> A[] annotations(Class<A> a,
Constructor<?> c) {
+ A[] aa = (A[])constructorAnnotationCache.get(c, a);
+ if (aa == null) {
+ A[] x = c.getAnnotationsByType(a);
+ AList<Annotation> l = new AList<>(Arrays.asList(x));
+ annotationMap.appendAll(c, a, l);
+ aa = (A[]) Array.newInstance(a, l.size());
+ for (int i = 0; i < l.size(); i++)
+ Array.set(aa, i, l.get(i));
+ constructorAnnotationCache.put(c, a, aa);
+ }
+ return aa;
}
//-----------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/csv/CsvMetaProvider.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/csv/CsvMetaProvider.java
index f335d94..b118858 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/csv/CsvMetaProvider.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/csv/CsvMetaProvider.java
@@ -22,7 +22,7 @@ import org.apache.juneau.*;
* <li class='extlink'>{@source}
* </ul>
*/
-public interface CsvMetaProvider extends MetaProvider {
+public interface CsvMetaProvider extends AnnotationProvider {
/**
* Returns the language-specific metadata on the specified class.
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 5c067dd..8f609a8 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
@@ -50,11 +50,11 @@ public final class HtmlBeanPropertyMeta extends
ExtendedBeanPropertyMeta {
Builder b = new Builder();
if (bpm.getInnerField() != null)
- mp.getAnnotations(Html.class, bpm.getInnerField(), x ->
b.findHtmlInfo(x));
+ mp.getAnnotations(Html.class, bpm.getInnerField(), x->
true, x -> b.findHtmlInfo(x));
if (bpm.getGetter() != null)
- mp.getAnnotations(Html.class, bpm.getGetter(), x ->
b.findHtmlInfo(x));
+ mp.getAnnotations(Html.class, bpm.getGetter(), x->
true, x -> b.findHtmlInfo(x));
if (bpm.getSetter() != null)
- mp.getAnnotations(Html.class, bpm.getSetter(), x ->
b.findHtmlInfo(x));
+ mp.getAnnotations(Html.class, bpm.getSetter(), x->
true, 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/html/HtmlMetaProvider.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlMetaProvider.java
index d578aa6..aac3e8a 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlMetaProvider.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlMetaProvider.java
@@ -22,7 +22,7 @@ import org.apache.juneau.*;
* <li class='extlink'>{@source}
* </ul>
*/
-public interface HtmlMetaProvider extends MetaProvider {
+public interface HtmlMetaProvider extends AnnotationProvider {
/**
* Returns the language-specific metadata on the specified class.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonMetaProvider.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonMetaProvider.java
index 902e6db..741652e 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonMetaProvider.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonMetaProvider.java
@@ -22,7 +22,7 @@ import org.apache.juneau.*;
* <li class='extlink'>{@source}
* </ul>
*/
-public interface JsonMetaProvider extends MetaProvider {
+public interface JsonMetaProvider extends AnnotationProvider {
/**
* Returns the language-specific metadata on the specified class.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaMetaProvider.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaMetaProvider.java
index 218dac4..d6ea8a4 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaMetaProvider.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaMetaProvider.java
@@ -22,7 +22,7 @@ import org.apache.juneau.*;
* <li class='extlink'>{@source}
* </ul>
*/
-public interface JsonSchemaMetaProvider extends MetaProvider {
+public interface JsonSchemaMetaProvider extends AnnotationProvider {
/**
* Returns the language-specific metadata on the specified class.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackMetaProvider.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackMetaProvider.java
index 0e351a9..7b03712 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackMetaProvider.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackMetaProvider.java
@@ -22,7 +22,7 @@ import org.apache.juneau.*;
* <li class='extlink'>{@source}
* </ul>
*/
-public interface MsgPackMetaProvider extends MetaProvider {
+public interface MsgPackMetaProvider extends AnnotationProvider {
/**
* Returns the language-specific metadata on the specified class.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/oapi/OpenApiMetaProvider.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/oapi/OpenApiMetaProvider.java
index a42746f..492f839 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/oapi/OpenApiMetaProvider.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/oapi/OpenApiMetaProvider.java
@@ -22,7 +22,7 @@ import org.apache.juneau.*;
* <li class='extlink'>{@source}
* </ul>
*/
-public interface OpenApiMetaProvider extends MetaProvider {
+public interface OpenApiMetaProvider extends AnnotationProvider {
/**
* Returns the language-specific metadata on the specified class.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/plaintext/PlainTextMetaProvider.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/plaintext/PlainTextMetaProvider.java
index 60c2fad..1c3c4f1 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/plaintext/PlainTextMetaProvider.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/plaintext/PlainTextMetaProvider.java
@@ -22,7 +22,7 @@ import org.apache.juneau.*;
* <li class='extlink'>{@source}
* </ul>
*/
-public interface PlainTextMetaProvider extends MetaProvider {
+public interface PlainTextMetaProvider extends AnnotationProvider {
/**
* Returns the language-specific metadata on the specified class.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
index b61d81f..b2b50b4 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
@@ -70,7 +70,7 @@ public final class ClassInfo {
private MethodInfo[] publicMethods, declaredMethods, allMethods,
allMethodsParentFirst;
private MethodInfo repeatedAnnotationMethod;
private ConstructorInfo[] publicConstructors, declaredConstructors;
- private FieldInfo[] publicFields, declaredFields, allFields,
allFieldsParentFirst;
+ private FieldInfo[] publicFields, declaredFields, allFields;
private int dim = -1;
private ClassInfo componentType;
@@ -409,25 +409,17 @@ public final class ClassInfo {
}
/**
- * Returns all methods declared on this class.
- *
- * @return
- * All methods declared on this class.
- * <br>Results are ordered alphabetically.
- */
- public List<MethodInfo> getDeclaredMethods() {
- return new UnmodifiableArray<>(_getDeclaredMethods());
- }
-
- /**
- * Returns all declared methods on this class and all parent classes.
+ * Returns the public method that matches the specified predicate.
*
- * @return
- * All declared methods on this class and all parent classes.
- * <br>Results are ordered child-to-parent, and then
alphabetically per class.
+ * @param predicate The predicate.
+ * @param consumer The consumer.
+ * @return This object.
*/
- public List<MethodInfo> getMethods() {
- return new UnmodifiableArray<>(_getAllMethods());
+ public final ClassInfo getPublicMethods(Predicate<MethodInfo>
predicate, Consumer<MethodInfo> consumer) {
+ for (MethodInfo mi : _getPublicMethods())
+ if (predicate.test(mi))
+ consumer.accept(mi);
+ return this;
}
/**
@@ -444,54 +436,63 @@ public final class ClassInfo {
}
/**
+ * Returns all methods declared on this class.
+ *
+ * @return
+ * All methods declared on this class.
+ * <br>Results are ordered alphabetically.
+ */
+ public List<MethodInfo> getDeclaredMethods() {
+ return new UnmodifiableArray<>(_getDeclaredMethods());
+ }
+
+ /**
* Returns the declared method that matches the specified predicate.
*
* @param predicate The predicate.
- * @return The first matching method, or <jk>null</jk> if no methods
matched.
+ * @param consumer The consumer.
+ * @return This object.
*/
- public MethodInfo getDeclaredMethod(Predicate<MethodInfo> predicate) {
+ public final ClassInfo getDeclaredMethods(Predicate<MethodInfo>
predicate, Consumer<MethodInfo> consumer) {
for (MethodInfo mi : _getDeclaredMethods())
if (predicate.test(mi))
- return mi;
- return null;
+ consumer.accept(mi);
+ return this;
}
/**
- * Returns the method that matches the specified predicate.
+ * Returns the declared method that matches the specified predicate.
*
* @param predicate The predicate.
* @return The first matching method, or <jk>null</jk> if no methods
matched.
*/
- public MethodInfo getMethod(Predicate<MethodInfo> predicate) {
- for (MethodInfo mi : _getAllMethods())
+ public MethodInfo getDeclaredMethod(Predicate<MethodInfo> predicate) {
+ for (MethodInfo mi : _getDeclaredMethods())
if (predicate.test(mi))
return mi;
return null;
}
/**
- * Returns the public method that matches the specified predicate.
+ * Returns all declared methods on this class and all parent classes.
*
- * @param predicate The predicate.
- * @param consumer The consumer of the matching predicate.
- * @return This object.
+ * @return
+ * All declared methods on this class and all parent classes.
+ * <br>Results are ordered child-to-parent, and then
alphabetically per class.
*/
- public final ClassInfo getPublicMethods(Predicate<MethodInfo>
predicate, Consumer<MethodInfo> consumer) {
- for (MethodInfo mi : _getPublicMethods())
- if (predicate.test(mi))
- consumer.accept(mi);
- return this;
+ public List<MethodInfo> getMethods() {
+ return new UnmodifiableArray<>(_getAllMethods());
}
/**
- * Returns the declared method that matches the specified predicate.
+ * Returns the method that matches the specified predicate.
*
* @param predicate The predicate.
- * @param consumer The consumer of the matching predicate.
+ * @param consumer The consumer.
* @return This object.
*/
- public final ClassInfo getDeclaredMethods(Predicate<MethodInfo>
predicate, Consumer<MethodInfo> consumer) {
- for (MethodInfo mi : _getDeclaredMethods())
+ public final ClassInfo getMethods(Predicate<MethodInfo> predicate,
Consumer<MethodInfo> consumer) {
+ for (MethodInfo mi : _getAllMethods())
if (predicate.test(mi))
consumer.accept(mi);
return this;
@@ -501,14 +502,13 @@ public final class ClassInfo {
* Returns the method that matches the specified predicate.
*
* @param predicate The predicate.
- * @param consumer The consumer of the matching predicate.
- * @return This object.
+ * @return The first matching method, or <jk>null</jk> if no methods
matched.
*/
- public final ClassInfo getMethods(Predicate<MethodInfo> predicate,
Consumer<MethodInfo> consumer) {
+ public MethodInfo getMethod(Predicate<MethodInfo> predicate) {
for (MethodInfo mi : _getAllMethods())
if (predicate.test(mi))
- consumer.accept(mi);
- return this;
+ return mi;
+ return null;
}
/**
@@ -523,6 +523,20 @@ public final class ClassInfo {
return new UnmodifiableArray<>(_getAllMethodsParentFirst());
}
+ /**
+ * Returns the method that matches the specified predicate from all
declared methods on this class and all parent classes.
+ *
+ * @param predicate The predicate.
+ * @param consumer The consumer.
+ * @return This object.
+ */
+ public final ClassInfo getAllMethodsParentFirst(Predicate<MethodInfo>
predicate, Consumer<MethodInfo> consumer) {
+ for (MethodInfo mi : _getAllMethodsParentFirst())
+ if (predicate.test(mi))
+ consumer.accept(mi);
+ return this;
+ }
+
private MethodInfo[] _getPublicMethods() {
if (publicMethods == null) {
Method[] mm = c == null ? new Method[0] :
c.getMethods();
@@ -590,6 +604,20 @@ public final class ClassInfo {
}
/**
+ * Consumes the public constructors defined on this class that match
the specified predicate.
+ *
+ * @param predicate The predicate.
+ * @param consumer The consumer.
+ * @return This object.
+ */
+ public final ClassInfo getPublicConstructors(Predicate<ConstructorInfo>
predicate, Consumer<ConstructorInfo> consumer) {
+ for (ConstructorInfo mi : _getPublicConstructors())
+ if (predicate.test(mi))
+ consumer.accept(mi);
+ return this;
+ }
+
+ /**
* Returns the public constructor that matches the specified predicate.
*
* @param predicate The predicate.
@@ -603,19 +631,26 @@ public final class ClassInfo {
}
/**
- * Returns the public constructor that passes the specified predicate
test.
+ * Returns all the constructors defined on this class.
*
- * <p>
- * The {@link ReflectionFilters} class has predefined predicates that
can be used for testing.
+ * @return All constructors defined on this class.
+ */
+ public List<ConstructorInfo> getDeclaredConstructors() {
+ return new UnmodifiableArray<>(_getDeclaredConstructors());
+ }
+
+ /**
+ * Consumes the declared constructors defined on this class that match
the specified predicate.
*
- * @param test The test that the public constructor must pass.
- * @return The first matching public constructor.
+ * @param predicate The predicate.
+ * @param consumer The consumer.
+ * @return This object.
*/
- public ConstructorInfo getConstructor(Predicate<ExecutableInfo> test) {
- for (ConstructorInfo ci : _getDeclaredConstructors())
- if (test.test(ci))
- return ci;
- return null;
+ public final ClassInfo
getDeclaredConstructors(Predicate<ConstructorInfo> predicate,
Consumer<ConstructorInfo> consumer) {
+ for (ConstructorInfo mi : _getDeclaredConstructors())
+ if (predicate.test(mi))
+ consumer.accept(mi);
+ return this;
}
/**
@@ -631,15 +666,6 @@ public final class ClassInfo {
return null;
}
- /**
- * Returns all the constructors defined on this class.
- *
- * @return All constructors defined on this class.
- */
- public List<ConstructorInfo> getDeclaredConstructors() {
- return new UnmodifiableArray<>(_getDeclaredConstructors());
- }
-
private ConstructorInfo[] _getPublicConstructors() {
if (publicConstructors == null) {
Constructor<?>[] cc = c == null ? new Constructor[0] :
c.getConstructors();
@@ -708,69 +734,61 @@ public final class ClassInfo {
}
/**
- * Returns all declared fields on this class.
+ * Returns the public field that matches the specified predicate.
*
- * @return
- * All declared fields on this class.
- * <br>Results are in alphabetical order.
- */
- public List<FieldInfo> getDeclaredFields() {
- return new UnmodifiableArray<>(_getDeclaredFields());
- }
-
- /**
- * Consumes all declared fields on this class that match the specified
predicate.
- *
- * @param predicate The predicate to test against.
+ * @param predicate The predicate.
* @param consumer The consumer.
* @return This object.
*/
- public ClassInfo getDeclaredFields(Predicate<FieldInfo> predicate,
Consumer<FieldInfo> consumer) {
- for (FieldInfo fi : _getDeclaredFields())
- if (predicate.test(fi))
- consumer.accept(fi);
+ public final ClassInfo getPublicFields(Predicate<FieldInfo> predicate,
Consumer<FieldInfo> consumer) {
+ for (FieldInfo mi : _getPublicFields())
+ if (predicate.test(mi))
+ consumer.accept(mi);
return this;
}
/**
- * Returns all declared fields on this class and all parent classes.
+ * Returns the public field that passes the specified predicate.
*
- * @return
- * All declared fields on this class.
- * <br>Results are ordered child-to-parent, and then alphabetical
per class.
+ * @param predicate The predicate.
+ * @return The public field, or <jk>null</jk> if not found.
*/
- public List<FieldInfo> getAllFields() {
- return new UnmodifiableArray<>(_getAllFields());
+ public FieldInfo getPublicField(Predicate<FieldInfo> predicate) {
+ for (FieldInfo f : _getPublicFields())
+ if (predicate.test(f))
+ return f;
+ return null;
}
/**
- * Returns all declared fields on this class and all parent classes.
+ * Returns all declared fields on this class.
*
* @return
* All declared fields on this class.
- * <br>Results are ordered parent-to-child, and then alphabetical
per class.
+ * <br>Results are in alphabetical order.
*/
- public List<FieldInfo> getAllFieldsParentFirst() {
- return new UnmodifiableArray<>(_getAllFieldsParentFirst());
+ public List<FieldInfo> getDeclaredFields() {
+ return new UnmodifiableArray<>(_getDeclaredFields());
}
/**
- * Returns the public field that passes the specified predicate.
+ * Consumes all declared fields on this class that match the specified
predicate.
*
- * @param predicate The predicate to test against.
- * @return The public field, or <jk>null</jk> if not found.
+ * @param predicate The predicate.
+ * @param consumer The consumer.
+ * @return This object.
*/
- public FieldInfo getPublicField(Predicate<FieldInfo> predicate) {
- for (FieldInfo f : _getPublicFields())
- if (predicate.test(f))
- return f;
- return null;
+ public ClassInfo getDeclaredFields(Predicate<FieldInfo> predicate,
Consumer<FieldInfo> consumer) {
+ for (FieldInfo fi : _getDeclaredFields())
+ if (predicate.test(fi))
+ consumer.accept(fi);
+ return this;
}
/**
* Returns the declared field that passes the specified predicate.
*
- * @param predicate The predicate to test against.
+ * @param predicate The predicate.
* @return The declared field, or <jk>null</jk> if not found.
*/
public FieldInfo getDeclaredField(Predicate<FieldInfo> predicate) {
@@ -780,26 +798,45 @@ public final class ClassInfo {
return null;
}
- private List<FieldInfo> _appendDeclaredFields(List<FieldInfo> l) {
- for (FieldInfo f : _getDeclaredFields())
- l.add(f);
- return l;
+ /**
+ * Returns all fields on this class and all parent classes.
+ *
+ * <p>
+ * Results are ordered parent-to-child, and then alphabetical per
class.
+ *
+ * @return All declared fields on this class.
+ */
+ public List<FieldInfo> getAllFields() {
+ return new UnmodifiableArray<>(_getAllFields());
}
- private Map<String,FieldInfo>
_appendDeclaredPublicFields(Map<String,FieldInfo> m) {
- for (FieldInfo f : _getDeclaredFields()) {
- String fn = f.getName();
- if (f.isPublic() && ! (m.containsKey(fn) ||
"$jacocoData".equals(fn)))
- m.put(f.getName(), f);
- }
- return m;
+ /**
+ * Consumes all fields on this class and all parent classes that
matches the specified predicate.
+ *
+ * <p>
+ * Results are ordered parent-to-child, and then alphabetical per
class.
+ *
+ * @param predicate The predicate.
+ * @param consumer The consumer.
+ * @return This object.
+ */
+ public ClassInfo getAllFields(Predicate<FieldInfo> predicate,
Consumer<FieldInfo> consumer) {
+ for (FieldInfo fi : _getAllFields())
+ if (predicate.test(fi))
+ consumer.accept(fi);
+ return this;
}
private FieldInfo[] _getPublicFields() {
if (publicFields == null) {
Map<String,FieldInfo> m = new LinkedHashMap<>();
- for (ClassInfo c : _getParents())
- c._appendDeclaredPublicFields(m);
+ for (ClassInfo c : _getParents()) {
+ for (FieldInfo f : c._getDeclaredFields()) {
+ String fn = f.getName();
+ if (f.isPublic() && !
(m.containsKey(fn) || "$jacocoData".equals(fn)))
+ m.put(f.getName(), f);
+ }
+ }
List<FieldInfo> l = new ArrayList<>(m.values());
l.sort(null);
publicFields = l.toArray(new FieldInfo[l.size()]);
@@ -823,22 +860,13 @@ public final class ClassInfo {
private FieldInfo[] _getAllFields() {
if (allFields == null) {
List<FieldInfo> l = new ArrayList<>();
- for (ClassInfo c : _getAllParents())
- c._appendDeclaredFields(l);
- allFields = l.toArray(new FieldInfo[l.size()]);
- }
- return allFields;
- }
-
- private FieldInfo[] _getAllFieldsParentFirst() {
- if (allFieldsParentFirst == null) {
- List<FieldInfo> l = new ArrayList<>();
ClassInfo[] parents = _getAllParents();
for (int i = parents.length-1; i >=0; i--)
- parents[i]._appendDeclaredFields(l);
- allFieldsParentFirst = l.toArray(new
FieldInfo[l.size()]);
+ for (FieldInfo f :
parents[i]._getDeclaredFields())
+ l.add(f);
+ allFields = l.toArray(new FieldInfo[l.size()]);
}
- return allFieldsParentFirst;
+ return allFields;
}
//-----------------------------------------------------------------------------------------------------------------
@@ -846,6 +874,74 @@ public final class ClassInfo {
//-----------------------------------------------------------------------------------------------------------------
/**
+ * Returns all annotations of the specified type defined on the
specified class or parent classes/interfaces in parent-to-child order.
+ *
+ * @param a
+ * The annotation to search for.
+ * @return
+ * A list of all matching annotations found or an empty list if
none found.
+ */
+ public <T extends Annotation> List<T> getAnnotations(Class<T> a) {
+ List<T> l = new ArrayList<>();
+ getAnnotations(a, x -> l.add(x));
+ return l;
+ }
+
+ /**
+ * Finds and consumes the specified annotation on the specified class
and superclasses/interfaces to the specified consumer.
+ *
+ * <p>
+ * Annotations are appended in the following orders:
+ * <ol>
+ * <li>On the package of this class.
+ * <li>On interfaces ordered child-to-parent.
+ * <li>On parent classes ordered child-to-parent.
+ * <li>On this class.
+ * </ol>
+ *
+ * @param ap The meta provider for looking up annotations on reflection
objects (classes, methods, fields, constructors).
+ * @param a The annotation to search for.
+ * @param predicate The predicate.
+ * @param consumer The consumer.
+ * @return This object.
+ */
+ public <T extends Annotation> ClassInfo
getAnnotations(AnnotationProvider ap, Class<T> a, Predicate<T> predicate,
Consumer<T> consumer) {
+ if (predicate == null) predicate = x->true;
+ if (ap == null) ap = AnnotationProvider.DEFAULT;
+ T t2 = getPackageAnnotation(a);
+ if (t2 != null && predicate.test(t2))
+ consumer.accept(t2);
+ ClassInfo[] interfaces = _getInterfaces();
+ for (int i = interfaces.length-1; i >= 0; i--)
+ ap.getDeclaredAnnotations(a, interfaces[i].inner(),
predicate, consumer);
+ ClassInfo[] parents = _getParents();
+ for (int i = parents.length-1; i >= 0; i--)
+ ap.getDeclaredAnnotations(a, parents[i].inner(),
predicate, consumer);
+ return this;
+ }
+
+ /**
+ * Finds and appends the specified annotation on the specified class
and superclasses/interfaces to the specified
+ * consumer.
+ *
+ * <p>
+ * Annotations are appended in the following orders:
+ * <ol>
+ * <li>On the package of this class.
+ * <li>On interfaces ordered child-to-parent.
+ * <li>On parent classes ordered child-to-parent.
+ * <li>On this class.
+ * </ol>
+ *
+ * @param consumer The consumer of the annotations.
+ * @param a The annotation to search for.
+ * @return The same list.
+ */
+ public <T extends Annotation> ClassInfo getAnnotations(Class<T> a,
Consumer<T> consumer) {
+ return getAnnotations(AnnotationProvider.DEFAULT, a, x-> true,
consumer);
+ }
+
+ /**
* Finds the annotation of the specified type defined on this class or
parent class/interface.
*
* <p>
@@ -857,7 +953,7 @@ public final class ClassInfo {
* @return The annotation if found, or <jk>null</jk> if not.
*/
public <T extends Annotation> T getLastAnnotation(Class<T> a) {
- return getLastAnnotation(a, MetaProvider.DEFAULT);
+ return getLastAnnotation(AnnotationProvider.DEFAULT, a);
}
/**
@@ -866,13 +962,13 @@ public final class ClassInfo {
* <p>
* If the annotation cannot be found on the immediate class, searches
methods with the same signature on the parent classes or interfaces. <br>
* The search is performed in child-to-parent order.
- *
+ * @param ap The meta provider for looking up annotations on reflection
objects (classes, methods, fields, constructors).
* @param a The annotation to search for.
- * @param mp The meta provider for looking up annotations on reflection
objects (classes, methods, fields, constructors).
+ *
* @return The annotation if found, or <jk>null</jk> if not.
*/
- public <T extends Annotation> T getLastAnnotation(Class<T> a,
MetaProvider mp) {
- return findAnnotation(a, mp);
+ public <T extends Annotation> T getLastAnnotation(AnnotationProvider
ap, Class<T> a) {
+ return findAnnotation(ap, a);
}
/**
@@ -882,7 +978,18 @@ public final class ClassInfo {
* @return The <jk>true</jk> if annotation if found.
*/
public boolean hasAnnotation(Class<? extends Annotation> a) {
- return getLastAnnotation(a) != null;
+ return hasAnnotation(AnnotationProvider.DEFAULT, a);
+ }
+
+ /**
+ * Returns <jk>true</jk> if this class has the specified annotation.
+ *
+ * @param ap The annotation provider.
+ * @param a The annotation to search for.
+ * @return The <jk>true</jk> if annotation if found.
+ */
+ public boolean hasAnnotation(AnnotationProvider ap, Class<? extends
Annotation> a) {
+ return ap.getAnnotation(a, c, x -> true) != null;
}
/**
@@ -912,50 +1019,14 @@ public final class ClassInfo {
}
/**
- * Same as {@link #getDeclaredAnnotation(Class)} but returns the
annotation wrapped in a {@link AnnotationInfo}.
- *
- * @param a The annotation to search for.
- * @return The annotation if found, or <jk>null</jk> if not.
- */
- public <T extends Annotation> AnnotationInfo<T>
getDeclaredAnnotationInfo(Class<T> a) {
- T ca = getDeclaredAnnotation(a);
- return ca == null ? null : AnnotationInfo.of(this, ca);
- }
-
- /**
- * Same as {@link #getPackageAnnotation(Class)} but returns the
annotation wrapped in a {@link AnnotationInfo}.
- *
- * @param a The annotation to search for.
- * @return The annotation if found, or <jk>null</jk> if not.
- */
- public <T extends Annotation> AnnotationInfo<T>
getPackageAnnotationInfo(Class<T> a) {
- T ca = getPackageAnnotation(a);
- return ca == null ? null : AnnotationInfo.of(getPackage(), ca);
- }
-
- /**
- * Returns all annotations of the specified type defined on the
specified class or parent classes/interfaces in parent-to-child order.
- *
- * @param a
- * The annotation to search for.
- * @return
- * A list of all matching annotations found or an empty list if
none found.
- */
- public <T extends Annotation> List<T> getAnnotations(Class<T> a) {
- List<T> l = new ArrayList<>();
- getAnnotations(a, x -> l.add(x));
- return l;
- }
-
- /**
* Returns the first matching annotation of the specified type defined
on the specified class or parent classes/interfaces in parent-to-child order.
*
* @param a The annotation to search for.
- * @param predicate The predicate to test against.
+ * @param predicate The predicate.
* @return This object.
*/
public <T extends Annotation> T getAnnotation(Class<T> a, Predicate<T>
predicate) {
- return getAnnotation(predicate, a, MetaProvider.DEFAULT);
+ return getAnnotation(predicate, a, AnnotationProvider.DEFAULT);
}
/**
@@ -963,16 +1034,16 @@ public final class ClassInfo {
*
* <p>
* Returns the list in reverse (parent-to-child) order.
- *
+ * @param ap The meta provider for looking up annotations on reflection
objects (classes, methods, fields, constructors).
* @param a
* The annotation to search for.
- * @param mp The meta provider for looking up annotations on reflection
objects (classes, methods, fields, constructors).
+ *
* @return
* A list of all matching annotations found or an empty list if
none found.
*/
- public <T extends Annotation> List<T> getAnnotations(Class<T> a,
MetaProvider mp) {
+ public <T extends Annotation> List<T> getAnnotations(AnnotationProvider
ap, Class<T> a) {
List<T> l = new ArrayList<>();
- getAnnotations(a, mp, x -> l.add(x));
+ getAnnotations(ap, a, x-> true, x -> l.add(x));
return l;
}
@@ -1029,57 +1100,44 @@ public final class ClassInfo {
}
/**
- * Finds and appends the specified annotation on the specified class
and superclasses/interfaces to the specified
- * consumer.
- *
- * <p>
- * Annotations are appended in the following orders:
- * <ol>
- * <li>On the package of this class.
- * <li>On interfaces ordered child-to-parent.
- * <li>On parent classes ordered child-to-parent.
- * <li>On this class.
- * </ol>
+ * If the annotation is an array of other annotations, returns the
inner annotations.
*
- * @param consumer The consumer of the annotations.
- * @param a The annotation to search for.
- * @return The same list.
+ * @param a The annotation to split if repeated.
+ * @return The nested annotations, or a singleton array of the same
annotation if it's not repeated.
*/
- public <T extends Annotation> ClassInfo getAnnotations(Class<T> a,
Consumer<T> consumer) {
- return getAnnotations(a, MetaProvider.DEFAULT, consumer);
+ private static Annotation[] splitRepeated(Annotation a) {
+ try {
+ ClassInfo ci = ClassInfo.ofc(a.annotationType());
+ MethodInfo mi = ci.getRepeatedAnnotationMethod();
+ if (mi != null)
+ return mi.invoke(a);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return new Annotation[]{a};
}
- /**
- * Finds and consumes the specified annotation on the specified class
and superclasses/interfaces to the specified consumer.
- *
- * <p>
- * Annotations are appended in the following orders:
- * <ol>
- * <li>On the package of this class.
- * <li>On interfaces ordered child-to-parent.
- * <li>On parent classes ordered child-to-parent.
- * <li>On this class.
- * </ol>
- *
- * @param consumer The consumer of the annotations.
- * @param a The annotation to search for.
- * @param mp The meta provider for looking up annotations on reflection
objects (classes, methods, fields, constructors).
- * @return This object.
- */
- public <T extends Annotation> ClassInfo getAnnotations(Class<T> a,
MetaProvider mp, Consumer<T> consumer) {
- T t2 = getPackageAnnotation(a);
- if (t2 != null)
- consumer.accept(t2);
- ClassInfo[] interfaces = _getInterfaces();
- for (int i = interfaces.length-1; i >= 0; i--)
- mp.getDeclaredAnnotations(a, interfaces[i].inner(),
consumer);
- ClassInfo[] parents = _getParents();
- for (int i = parents.length-1; i >= 0; i--)
- mp.getDeclaredAnnotations(a, parents[i].inner(),
consumer);
- return this;
+ <T extends Annotation> T findAnnotation(AnnotationProvider ap, Class<T>
a) {
+ if (a == null)
+ return null;
+ T t = ap.getDeclaredAnnotation(a, c, x -> true);
+ if (t != null)
+ return t;
+ ClassInfo sci = getParent();
+ if (sci != null) {
+ t = sci.getLastAnnotation(ap, a);
+ if (t != null)
+ return t;
+ }
+ for (ClassInfo c2 : _getInterfaces()) {
+ t = c2.getLastAnnotation(ap, a);
+ if (t != null)
+ return t;
+ }
+ return null;
}
- private <T extends Annotation> T getAnnotation(Predicate<T> p, Class<T>
a, MetaProvider mp) {
+ private <T extends Annotation> T getAnnotation(Predicate<T> p, Class<T>
a, AnnotationProvider mp) {
T t2 = getPackageAnnotation(a);
if (t2 != null && p.test(t2))
return t2;
@@ -1098,32 +1156,7 @@ public final class ClassInfo {
return null;
}
- /**
- * Searches up the parent hierarchy of this class for the first
annotation in the list it finds.
- *
- * @param mp Metadata provider.
- * @param annotations The annotations to search for.
- * @return The first annotation found, or <jk>null</jk> if not found.
- */
- @SafeVarargs
- public final Annotation getAnyLastAnnotation(MetaProvider mp, Class<?
extends Annotation>...annotations) {
- for (Class<? extends Annotation> ca : annotations) {
- Annotation x = getLastAnnotation(ca, mp);
- if (x != null)
- return x;
- }
- for (ClassInfo ci : _getInterfaces()) {
- for (Class<? extends Annotation> ca : annotations) {
- Annotation x = ci.getLastAnnotation(ca, mp);
- if (x != null)
- return x;
- }
- }
- ClassInfo ci = getParent();
- return ci == null ? null : ci.getAnyLastAnnotation(mp,
annotations);
- }
-
- void getAnnotationInfos(Consumer<AnnotationInfo<?>> consumer) {
+ private void getAnnotationInfos(Consumer<AnnotationInfo<?>> consumer) {
Package p = c.getPackage();
if (p != null)
for (Annotation a : p.getDeclaredAnnotations())
@@ -1141,48 +1174,6 @@ public final class ClassInfo {
consumer.accept(AnnotationInfo.of(parents[i], a2));
}
- /**
- * If the annotation is an array of other annotations, returns the
inner annotations.
- *
- * @param a The annotation to split if repeated.
- * @return The nested annotations, or a singleton array of the same
annotation if it's not repeated.
- */
- private static Annotation[] splitRepeated(Annotation a) {
- try {
- ClassInfo ci = ClassInfo.ofc(a.annotationType());
- MethodInfo mi = ci.getRepeatedAnnotationMethod();
- if (mi != null)
- return mi.invoke(a);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return new Annotation[]{a};
- }
-
- <T extends Annotation> T findAnnotation(Class<T> a, MetaProvider mp) {
- if (a == null)
- return null;
-
- T t = mp.getDeclaredAnnotation(a, c, x -> true);
- if (t != null)
- return t;
-
- ClassInfo sci = getParent();
- if (sci != null) {
- t = sci.getLastAnnotation(a, mp);
- if (t != null)
- return t;
- }
-
- for (ClassInfo c2 : _getInterfaces()) {
- t = c2.getLastAnnotation(a, mp);
- if (t != null)
- return t;
- }
-
- return null;
- }
-
//-----------------------------------------------------------------------------------------------------------------
// Characteristics
//-----------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ConstructorInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ConstructorInfo.java
index 00f65f5..cfa7c64 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ConstructorInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ConstructorInfo.java
@@ -89,28 +89,23 @@ public final class ConstructorInfo extends ExecutableInfo
implements Comparable<
/**
* Finds the annotation of the specified type defined on this
constructor.
*
- * @param a
- * The annotation to search for.
- * @return
- * The annotation if found, or <jk>null</jk> if not.
+ * @param a The annotation to search for.
+ * @return The annotation if found, or <jk>null</jk> if not.
*/
public final <T extends Annotation> T getAnnotation(Class<T> a) {
- return getAnnotation(a, MetaProvider.DEFAULT);
+ return getAnnotation(AnnotationProvider.DEFAULT, a);
}
/**
* Finds the annotation of the specified type defined on this
constructor.
*
- * @param a
- * The annotation to search for.
- * @param mp
- * The meta provider for looking up annotations on
classes/methods/fields.
- * @return
- * The first annotation found, or <jk>null</jk> if it doesn't
exist.
+ * @param ap The annotation provider.
+ * @param a The annotation to search for.
+ * @return The first annotation found, or <jk>null</jk> if it doesn't
exist.
*/
- public final <T extends Annotation> T getAnnotation(Class<T> a,
MetaProvider mp) {
+ public final <T extends Annotation> T getAnnotation(AnnotationProvider
ap, Class<T> a) {
Value<T> t = Value.empty();
- mp.getAnnotations(a, c, x -> t.set(x));
+ ap.getAnnotations(a, c, x-> true, x -> t.set(x));
return t.orElse(null);
}
@@ -121,9 +116,19 @@ public final class ConstructorInfo extends ExecutableInfo
implements Comparable<
* @return <jk>true</jk> if the specified annotation is present on this
constructor.
*/
public final boolean hasAnnotation(Class<? extends Annotation> a) {
- return getAnnotation(a) != null;
+ return hasAnnotation(AnnotationProvider.DEFAULT, a);
}
+ /**
+ * Returns <jk>true</jk> if the specified annotation is present on this
constructor.
+ *
+ * @param ap The annotation provider.
+ * @param a The annotation to check for.
+ * @return <jk>true</jk> if the specified annotation is present on this
constructor.
+ */
+ public final boolean hasAnnotation(AnnotationProvider ap, Class<?
extends Annotation> a) {
+ return ap.getAnnotation(a, c, x -> true) != null;
+ }
//-----------------------------------------------------------------------------------------------------------------
// Other methods
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/FieldInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/FieldInfo.java
index 2e8a451..81b87d0 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/FieldInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/FieldInfo.java
@@ -102,19 +102,19 @@ public final class FieldInfo implements
Comparable<FieldInfo> {
* @return The annotation, or <jk>null</jk> if not found.
*/
public <T extends Annotation> T getAnnotation(Class<T> a) {
- return getAnnotation(a, MetaProvider.DEFAULT);
+ return getAnnotation(AnnotationProvider.DEFAULT, a);
}
/**
* Returns the specified annotation on this field.
*
+ * @param ap The annotation provider.
* @param a The annotation to look for.
- * @param mp The meta provider for looking up annotations on reflection
objects (classes, methods, fields, constructors).
* @return The annotation, or <jk>null</jk> if not found.
*/
- public <T extends Annotation> T getAnnotation(Class<T> a, MetaProvider
mp) {
+ public <T extends Annotation> T getAnnotation(AnnotationProvider ap,
Class<T> a) {
Value<T> t = Value.empty();
- mp.getAnnotations(a, f, x -> t.set(x));
+ ap.getAnnotations(a, f, x -> true, x -> t.set(x));
return t.orElse(null);
}
@@ -141,23 +141,23 @@ public final class FieldInfo implements
Comparable<FieldInfo> {
/**
* Returns <jk>true</jk> if the specified annotation is present.
*
+ * @param ap The annotation provider.
* @param a The annotation to check for.
- * @param mp The meta provider for looking up annotations on reflection
objects (classes, methods, fields, constructors).
* @return <jk>true</jk> if the specified annotation is present.
*/
- public boolean hasAnnotation(Class<? extends Annotation> a,
MetaProvider mp) {
- return mp.getAnnotation(a, f, x -> true) != null;
+ public boolean hasAnnotation(AnnotationProvider ap, Class<? extends
Annotation> a) {
+ return ap.getAnnotation(a, f, x -> true) != null;
}
/**
* Returns <jk>true</jk> if the specified annotation is not present.
*
+ * @param ap The annotation provider.
* @param a The annotation to check for.
- * @param mp The meta provider for looking up annotations on reflection
objects (classes, methods, fields, constructors).
* @return <jk>true</jk> if the specified annotation is not present.
*/
- public boolean hasNoAnnotation(Class<? extends Annotation> a,
MetaProvider mp) {
- return ! hasAnnotation(a, mp);
+ public boolean hasNoAnnotation(AnnotationProvider ap, Class<? extends
Annotation> a) {
+ return ! hasAnnotation(ap, a);
}
//-----------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/MethodInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/MethodInfo.java
index 30035b4..262b90c 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/MethodInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/MethodInfo.java
@@ -215,7 +215,7 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
* The annotation if found, or <jk>null</jk> if not.
*/
public final <T extends Annotation> T getLastAnnotation(Class<T> a) {
- return getLastAnnotation(a, MetaProvider.DEFAULT);
+ return getLastAnnotation(AnnotationProvider.DEFAULT, a);
}
/**
@@ -225,19 +225,16 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
* Searches all methods with the same signature on the parent classes
or interfaces
* and the return type on the method.
*
- * @param a
- * The annotation to search for.
- * @param mp
- * The meta provider for looking up annotations on
classes/methods/fields.
- * @return
- * The first annotation found, or <jk>null</jk> if it doesn't
exist.
+ * @param ap The annotation provider.
+ * @param a The annotation to search for.
+ * @return The first annotation found, or <jk>null</jk> if it doesn't
exist.
*/
- public final <T extends Annotation> T getLastAnnotation(Class<T> a,
MetaProvider mp) {
+ public final <T extends Annotation> T
getLastAnnotation(AnnotationProvider ap, Class<T> a) {
if (a == null)
return null;
Value<T> t = Value.empty();
for (Method m2 : _getMatching()) {
- mp.getAnnotations(a, m2, x -> t.set(x));
+ ap.getAnnotations(a, m2, x -> true, x -> t.set(x));
if (t.isPresent())
return t.get();
}
@@ -251,7 +248,21 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
* @return <jk>true</jk> if the specified annotation is present on this
method.
*/
public final boolean hasAnnotation(Class<? extends Annotation> a) {
- return getLastAnnotation(a) != null;
+ return hasAnnotation(AnnotationProvider.DEFAULT, a);
+ }
+
+ /**
+ * Returns <jk>true</jk> if the specified annotation is present on this
method.
+ *
+ * @param ap The annotation provider.
+ * @param a The annotation to check for.
+ * @return <jk>true</jk> if the specified annotation is present on this
method.
+ */
+ public final boolean hasAnnotation(AnnotationProvider ap, Class<?
extends Annotation> a) {
+ for (Method m2 : _getMatching())
+ if (ap.getAnnotation(a, m2, x -> true) != null)
+ return true;
+ return false;
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/soap/SoapXmlMetaProvider.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/soap/SoapXmlMetaProvider.java
index 50c10f2..0977ff1 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/soap/SoapXmlMetaProvider.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/soap/SoapXmlMetaProvider.java
@@ -22,7 +22,7 @@ import org.apache.juneau.*;
* <li class='extlink'>{@source}
* </ul>
*/
-public interface SoapXmlMetaProvider extends MetaProvider {
+public interface SoapXmlMetaProvider extends AnnotationProvider {
/**
* Returns the language-specific metadata on the specified class.
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 848c890..aacf100 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
@@ -120,7 +120,7 @@ public class AutoListSwap<T> extends ObjectSwap<T,List<?>> {
private static boolean shouldIgnore(BeanContext bc, ClassInfo ci) {
return
- bc.hasAnnotation(BeanIgnore.class, ci)
+ ci.hasAnnotation(bc, BeanIgnore.class)
|| ci.isNonStaticMemberClass();
}
@@ -132,7 +132,7 @@ public class AutoListSwap<T> extends ObjectSwap<T,List<?>> {
&& mi.hasName(SWAP_METHOD_NAMES)
&& mi.hasReturnTypeParent(List.class)
&& mi.hasFuzzyParamTypes(BeanSession.class)
- && ! bc.hasAnnotation(BeanIgnore.class, mi);
+ && ! mi.hasAnnotation(bc, BeanIgnore.class);
}
private static boolean isUnswapMethod(BeanContext bc, MethodInfo mi,
ClassInfo ci, ClassInfo rt) {
@@ -143,7 +143,7 @@ public class AutoListSwap<T> extends ObjectSwap<T,List<?>> {
&& mi.hasName(UNSWAP_METHOD_NAMES)
&& mi.hasFuzzyParamTypes(BeanSession.class, rt.inner())
&& mi.hasReturnTypeParent(ci)
- && ! bc.hasAnnotation(BeanIgnore.class, mi);
+ && ! mi.hasAnnotation(bc, BeanIgnore.class);
}
private static boolean isUnswapConstructor(BeanContext bc,
ConstructorInfo cs, ClassInfo rt) {
@@ -151,7 +151,7 @@ public class AutoListSwap<T> extends ObjectSwap<T,List<?>> {
cs.isNotDeprecated()
&& cs.isVisible(bc.getBeanConstructorVisibility())
&& cs.hasMatchingParamTypes(rt)
- && ! bc.hasAnnotation(BeanIgnore.class, cs);
+ && ! cs.hasAnnotation(bc, BeanIgnore.class);
}
//------------------------------------------------------------------------------------------------------------------
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 f0f613f..9604fe0 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
@@ -119,7 +119,7 @@ public class AutoMapSwap<T> extends ObjectSwap<T,Map<?,?>> {
private static boolean shouldIgnore(BeanContext bc, ClassInfo ci) {
return
- bc.hasAnnotation(BeanIgnore.class, ci)
+ ci.hasAnnotation(bc, BeanIgnore.class)
|| ci.isNonStaticMemberClass();
}
@@ -131,7 +131,7 @@ public class AutoMapSwap<T> extends ObjectSwap<T,Map<?,?>> {
&& mi.hasName(SWAP_METHOD_NAMES)
&& mi.hasReturnTypeParent(Map.class)
&& mi.hasFuzzyParamTypes(BeanSession.class)
- && ! bc.hasAnnotation(BeanIgnore.class, mi);
+ && ! mi.hasAnnotation(bc, BeanIgnore.class);
}
private static boolean isUnswapMethod(BeanContext bc, MethodInfo mi,
ClassInfo ci, ClassInfo rt) {
@@ -142,7 +142,7 @@ public class AutoMapSwap<T> extends ObjectSwap<T,Map<?,?>> {
&& mi.hasName(UNSWAP_METHOD_NAMES)
&& mi.hasFuzzyParamTypes(BeanSession.class, rt.inner())
&& mi.hasReturnTypeParent(ci)
- && ! bc.hasAnnotation(BeanIgnore.class, mi);
+ && ! mi.hasAnnotation(bc, BeanIgnore.class);
}
private static boolean isUnswapConstructor(BeanContext bc,
ConstructorInfo cs, ClassInfo rt) {
@@ -150,7 +150,7 @@ public class AutoMapSwap<T> extends ObjectSwap<T,Map<?,?>> {
cs.isNotDeprecated()
&& cs.isVisible(bc.getBeanConstructorVisibility())
&& cs.hasMatchingParamTypes(rt)
- && ! bc.hasAnnotation(BeanIgnore.class, cs);
+ && ! cs.hasAnnotation(bc, BeanIgnore.class);
}
//------------------------------------------------------------------------------------------------------------------
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 ec1ec9e..1bee9ba 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
@@ -144,7 +144,7 @@ public class AutoNumberSwap<T> extends ObjectSwap<T,Number>
{
private static boolean shouldIgnore(BeanContext bc, ClassInfo ci) {
return
- bc.hasAnnotation(BeanIgnore.class, ci)
+ ci.hasAnnotation(bc, BeanIgnore.class)
|| ci.isNonStaticMemberClass()
|| ci.isPrimitive()
|| ci.isChildOf(Number.class);
@@ -159,7 +159,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.hasName(SWAP_METHOD_NAMES)
&& mi.hasFuzzyParamTypes(BeanSession.class)
- && ! bc.hasAnnotation(BeanIgnore.class, mi);
+ && ! mi.hasAnnotation(bc, BeanIgnore.class);
}
private static boolean isUnswapMethod(BeanContext bc, MethodInfo mi,
ClassInfo ci, ClassInfo rt) {
@@ -170,7 +170,7 @@ public class AutoNumberSwap<T> extends ObjectSwap<T,Number>
{
&& mi.hasName(UNSWAP_METHOD_NAMES)
&& mi.hasFuzzyParamTypes(BeanSession.class, rt.inner())
&& mi.hasReturnTypeParent(ci)
- && ! bc.hasAnnotation(BeanIgnore.class, mi);
+ && ! mi.hasAnnotation(bc, BeanIgnore.class);
}
private static boolean isUnswapConstructor(BeanContext bc,
ConstructorInfo cs, ClassInfo rt) {
@@ -178,7 +178,7 @@ public class AutoNumberSwap<T> extends ObjectSwap<T,Number>
{
cs.isNotDeprecated()
&& cs.isVisible(bc.getBeanConstructorVisibility())
&& cs.hasMatchingParamTypes(rt)
- && ! bc.hasAnnotation(BeanIgnore.class, cs);
+ && ! cs.hasAnnotation(bc, BeanIgnore.class);
}
//------------------------------------------------------------------------------------------------------------------
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 2b98fb7..113e3db 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
@@ -122,7 +122,7 @@ public class AutoObjectSwap<T> extends ObjectSwap<T,Object>
{
private static boolean shouldIgnore(BeanContext bc, ClassInfo ci) {
return
- bc.hasAnnotation(BeanIgnore.class, ci)
+ ci.hasAnnotation(bc, BeanIgnore.class)
|| ci.isNonStaticMemberClass();
}
@@ -133,7 +133,7 @@ public class AutoObjectSwap<T> extends ObjectSwap<T,Object>
{
&& mi.isVisible(bc.getBeanMethodVisibility())
&& mi.hasName(SWAP_METHOD_NAMES)
&& mi.hasFuzzyParamTypes(BeanSession.class)
- && ! bc.hasAnnotation(BeanIgnore.class, mi);
+ && ! mi.hasAnnotation(bc, BeanIgnore.class);
}
private static boolean isUnswapMethod(BeanContext bc, MethodInfo mi,
ClassInfo ci, ClassInfo rt) {
@@ -144,7 +144,7 @@ public class AutoObjectSwap<T> extends ObjectSwap<T,Object>
{
&& mi.hasName(UNSWAP_METHOD_NAMES)
&& mi.hasFuzzyParamTypes(BeanSession.class, rt.inner())
&& mi.hasReturnTypeParent(ci)
- && ! bc.hasAnnotation(BeanIgnore.class, mi);
+ && ! mi.hasAnnotation(bc, BeanIgnore.class);
}
private static boolean isUnswapConstructor(BeanContext bc,
ConstructorInfo cs, ClassInfo rt) {
@@ -152,7 +152,7 @@ public class AutoObjectSwap<T> extends ObjectSwap<T,Object>
{
cs.isNotDeprecated()
&& cs.isVisible(bc.getBeanConstructorVisibility())
&& cs.hasMatchingParamTypes(rt)
- && ! bc.hasAnnotation(BeanIgnore.class, cs);
+ && ! cs.hasAnnotation(bc, BeanIgnore.class);
}
//------------------------------------------------------------------------------------------------------------------
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 e6dfbbf..69a3a94 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
@@ -160,7 +160,7 @@ public class BuilderSwap<T,B> {
ClassInfo pci = ClassInfo.of(objectClass);
- objectConstructor = pci.getConstructor(x -> x.isVisible(cVis)
&& x.hasParamTypes(builderClass));
+ objectConstructor = pci.getDeclaredConstructor(x ->
x.isVisible(cVis) && x.hasParamTypes(builderClass));
if (objectConstructor == null)
return null;
@@ -189,7 +189,7 @@ public class BuilderSwap<T,B> {
ConstructorInfo objectConstructor = null;
ConstructorInfo builderConstructor;
- bc.getAnnotations(org.apache.juneau.annotation.Builder.class,
objectClass, x -> builderClass.setIf(x.value(), y -> y != Null.class));
+ bc.getAnnotations(org.apache.juneau.annotation.Builder.class,
objectClass, x -> x.value() != Null.class, x -> builderClass.set(x.value()));
ClassInfo pci = ClassInfo.of(objectClass);
@@ -221,7 +221,7 @@ public class BuilderSwap<T,B> {
objectCreateMethod = getBuilderBuildMethod(bci);
Class<?> builderClass2 = builderClass.get();
if (objectConstructor == null)
- objectConstructor = pci.getConstructor(x ->
x.isVisible(cVis) && x.hasParamTypes(builderClass2));
+ objectConstructor = pci.getDeclaredConstructor(x ->
x.isVisible(cVis) && x.hasParamTypes(builderClass2));
if (objectConstructor == null && objectCreateMethod == null)
return null;
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 1002b86..4f30797 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
@@ -69,7 +69,7 @@ public class SurrogateSwap<T,F> extends ObjectSwap<T,F> {
List<SurrogateSwap<?,?>> l = new LinkedList<>();
ClassInfo ci = ClassInfo.of(c);
for (ConstructorInfo cc : ci.getPublicConstructors()) {
- if (! bc.hasAnnotation(BeanIgnore.class, cc) &&
cc.hasNumParams(1) && cc.isPublic()) {
+ if (! cc.hasAnnotation(bc, BeanIgnore.class) &&
cc.hasNumParams(1) && cc.isPublic()) {
Class<?> pt = cc.getRawParamType(0);
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/uon/UonMetaProvider.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonMetaProvider.java
index 3c3fde8..712002b 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonMetaProvider.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonMetaProvider.java
@@ -22,7 +22,7 @@ import org.apache.juneau.*;
* <li class='extlink'>{@source}
* </ul>
*/
-public interface UonMetaProvider extends MetaProvider {
+public interface UonMetaProvider extends AnnotationProvider {
/**
* Returns the language-specific metadata on the specified class.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingMetaProvider.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingMetaProvider.java
index 9d70fd8..a2c53eb 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingMetaProvider.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingMetaProvider.java
@@ -22,7 +22,7 @@ import org.apache.juneau.*;
* <li class='extlink'>{@source}
* </ul>
*/
-public interface UrlEncodingMetaProvider extends MetaProvider {
+public interface UrlEncodingMetaProvider extends AnnotationProvider {
/**
* Returns the language-specific metadata on the specified class.
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 5658b79..f9aa26c 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
@@ -86,7 +86,7 @@ public class XmlBeanMeta extends ExtendedBeanMeta {
Class<?> c = beanMeta.getClassMeta().getInnerClass();
Value<XmlFormat> defaultFormat = Value.empty();
- mp.getAnnotations(Xml.class, c, x -> {
+ mp.getAnnotations(Xml.class, c, x-> true, x -> {
XmlFormat xf = x.format();
if (xf == ATTRS)
defaultFormat.set(XmlFormat.ATTR);
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanPropertyMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanPropertyMeta.java
index 6cb74a5..f40ca9d 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanPropertyMeta.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanPropertyMeta.java
@@ -101,7 +101,7 @@ public class XmlBeanPropertyMeta extends
ExtendedBeanPropertyMeta {
return childName;
}
- private void findXmlInfo(Xml xml, MetaProvider mp) {
+ private void findXmlInfo(Xml xml, AnnotationProvider mp) {
if (xml == null)
return;
BeanPropertyMeta bpm = getBeanPropertyMeta();
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlMetaProvider.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlMetaProvider.java
index 719c7ba..7433115 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlMetaProvider.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlMetaProvider.java
@@ -22,7 +22,7 @@ import org.apache.juneau.*;
* <li class='extlink'>{@source}
* </ul>
*/
-public interface XmlMetaProvider extends MetaProvider {
+public interface XmlMetaProvider extends AnnotationProvider {
/**
* Returns the language-specific metadata on the specified class.
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index faa8320..c2d4881 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -366,17 +366,16 @@ public class RestContext extends Context {
private void runInitHooks(BeanStore beanStore, Supplier<?>
resource) throws ServletException {
Object r = resource.get();
- ClassInfo rci = ClassInfo.ofProxy(r);
Map<String,MethodInfo> map = new LinkedHashMap<>();
- for (MethodInfo m : rci.getAllMethodsParentFirst()) {
- if (m.hasAnnotation(RestHook.class) &&
m.getLastAnnotation(RestHook.class).value() == HookEvent.INIT) {
- m.setAccessible();
- String sig = m.getSignature();
+ ClassInfo.ofProxy(r).getAllMethodsParentFirst(
+ y -> y.hasAnnotation(RestHook.class) &&
y.getLastAnnotation(RestHook.class).value() == HookEvent.INIT,
+ y -> {
+ String sig = y.getSignature();
if (! map.containsKey(sig))
- map.put(sig, m);
+ map.put(sig, y.accessible());
}
- }
+ );
for (MethodInfo m : map.values()) {
if (! beanStore.hasAllParams(m))
@@ -5756,10 +5755,14 @@ public class RestContext extends Context {
Map<String,Method> x = AMap.create();
Object r = resource.get();
- for (MethodInfo m :
ClassInfo.ofProxy(r).getAllMethodsParentFirst())
- for (RestHook h :
m.getAnnotations(RestHook.class))
- if (h.value() == event)
- x.put(m.getSignature(),
m.accessible().inner());
+ ClassInfo.ofProxy(r).getAllMethodsParentFirst(
+ y -> y.hasAnnotation(RestHook.class),
+ y -> {
+ for (RestHook h :
y.getAnnotations(RestHook.class))
+ if (h.value() == event)
+ x.put(y.getSignature(),
y.accessible().inner());
+ }
+ );
MethodList x2 = MethodList.of(x.values());
return x2;
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/reflection/ClassInfoTest.java
b/juneau-utest/src/test/java/org/apache/juneau/reflection/ClassInfoTest.java
index 69e3bc1..53adb91 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/reflection/ClassInfoTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/reflection/ClassInfoTest.java
@@ -483,12 +483,12 @@ public class ClassInfoTest {
@Test
public void getConstructor() {
- check("E1(int)", e1.getConstructor(x ->
x.isVisible(Visibility.PROTECTED) && x.hasParamTypes(int.class)));
- check("E1(int)", e1.getConstructor(x ->
x.isVisible(Visibility.PRIVATE) && x.hasParamTypes(int.class)));
- check(null, e1.getConstructor(x ->
x.isVisible(Visibility.PUBLIC) && x.hasParamTypes(int.class)));
- check("E3()", e3.getConstructor(x ->
x.isVisible(Visibility.PUBLIC)));
- check("E4(ClassInfoTest)", e4.getConstructor(x ->
x.isVisible(Visibility.PUBLIC)));
- check("E5()", e5.getConstructor(x ->
x.isVisible(Visibility.PUBLIC)));
+ check("E1(int)", e1.getDeclaredConstructor(x ->
x.isVisible(Visibility.PROTECTED) && x.hasParamTypes(int.class)));
+ check("E1(int)", e1.getDeclaredConstructor(x ->
x.isVisible(Visibility.PRIVATE) && x.hasParamTypes(int.class)));
+ check(null, e1.getDeclaredConstructor(x ->
x.isVisible(Visibility.PUBLIC) && x.hasParamTypes(int.class)));
+ check("E3()", e3.getDeclaredConstructor(x ->
x.isVisible(Visibility.PUBLIC)));
+ check("E4(ClassInfoTest)", e4.getDeclaredConstructor(x ->
x.isVisible(Visibility.PUBLIC)));
+ check("E5()", e5.getDeclaredConstructor(x ->
x.isVisible(Visibility.PUBLIC)));
}
//-----------------------------------------------------------------------------------------------------------------
@@ -544,34 +544,14 @@ public class ClassInfoTest {
}
@Test
- public void getAllFields() {
- check("F2.f1a,F2.f2b,F2.f2c,F2.f2d,F1.f1a,F1.f1b",
f2.getAllFields());
- }
-
- @Test
- public void getAllFields_twice() {
- check("F2.f1a,F2.f2b,F2.f2c,F2.f2d,F1.f1a,F1.f1b",
f2.getAllFields());
- check("F2.f1a,F2.f2b,F2.f2c,F2.f2d,F1.f1a,F1.f1b",
f2.getAllFields());
- }
-
- @Test
- public void getAllFields_onType() {
- check("A1.this$0", aTypeInfo.getAllFields());
- check("", pTypeInfo.getAllFields());
- check("", pTypeDimensionalInfo.getAllFields());
- check("AbstractMap.keySet,AbstractMap.values",
pTypeGenericInfo.getAllFields());
- check("", pTypeGenericArgInfo.getAllFields());
- }
-
- @Test
public void getAllFieldsParentFirst() {
- check("F1.f1a,F1.f1b,F2.f1a,F2.f2b,F2.f2c,F2.f2d",
f2.getAllFieldsParentFirst());
+ check("F1.f1a,F1.f1b,F2.f1a,F2.f2b,F2.f2c,F2.f2d",
f2.getAllFields());
}
@Test
public void getAllFieldsParentFirst_twice() {
- check("F1.f1a,F1.f1b,F2.f1a,F2.f2b,F2.f2c,F2.f2d",
f2.getAllFieldsParentFirst());
- check("F1.f1a,F1.f1b,F2.f1a,F2.f2b,F2.f2c,F2.f2d",
f2.getAllFieldsParentFirst());
+ check("F1.f1a,F1.f1b,F2.f1a,F2.f2b,F2.f2c,F2.f2d",
f2.getAllFields());
+ check("F1.f1a,F1.f1b,F2.f1a,F2.f2b,F2.f2c,F2.f2d",
f2.getAllFields());
}
static class F3 {
@@ -672,18 +652,6 @@ public class ClassInfoTest {
}
@Test
- public void getDeclaredAnnotationInfo() {
- check("@A(7)", g3.getDeclaredAnnotationInfo(A.class));
- check(null, g3.getDeclaredAnnotationInfo(B.class));
- }
-
- @Test
- public void getDeclaredAnnotationInfo_twice() {
- check("@A(7)", g3.getDeclaredAnnotationInfo(A.class));
- check("@A(7)", g3.getDeclaredAnnotationInfo(A.class));
- }
-
- @Test
public void getPackageAnnotation() {
check("@PA(10)", g3.getPackageAnnotation(PA.class));
}
@@ -698,11 +666,6 @@ public class ClassInfoTest {
}
@Test
- public void getPackageAnnotationInfo() {
- check("@PA(10)", g3.getPackageAnnotationInfo(PA.class));
- }
-
- @Test
public void getAnnotationsMapParentFirst() {
check("@PA(10),@A(2),@A(1),@A(3),@A(5),@A(6),@A(7)",
g3.getAnnotationList());
check("@PA(10),@A(2),@A(1),@A(3),@A(5),@A(6),@A(7)",
g4.getAnnotationList());