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 31f30bd ClassInfo refactoring.
31f30bd is described below
commit 31f30bd476c35f7732641529332859ee07c0cc1b
Author: JamesBognar <[email protected]>
AuthorDate: Tue Feb 1 10:25:46 2022 -0500
ClassInfo refactoring.
---
.../java/org/apache/juneau/AnnotationProvider.java | 157 ++++++++++-----------
.../src/main/java/org/apache/juneau/ClassMeta.java | 20 +--
.../src/main/java/org/apache/juneau/Context.java | 151 ++++++++++----------
.../annotation/InvalidAnnotationException.java | 12 +-
.../juneau/assertions/FluentAnyAssertion.java | 3 +-
.../assertions/FluentThrowableAssertion.java | 6 +-
.../org/apache/juneau/cp/ContextBeanCreator.java | 6 +-
.../org/apache/juneau/internal/ConsumerUtils.java | 69 +++++++++
.../org/apache/juneau/internal/ListBuilder.java | 3 +-
.../org/apache/juneau/internal/ObjectUtils.java | 6 +-
.../org/apache/juneau/internal/SetBuilder.java | 3 +-
.../org/apache/juneau/internal/ThrowableUtils.java | 3 +-
.../java/org/apache/juneau/parser/ParserSet.java | 3 +-
.../org/apache/juneau/reflect/AnnotationInfo.java | 10 +-
.../org/apache/juneau/reflect/AnnotationList.java | 9 +-
.../java/org/apache/juneau/reflect/ClassInfo.java | 51 +++----
.../org/apache/juneau/reflect/ConstructorInfo.java | 4 +-
.../org/apache/juneau/reflect/ExecutableInfo.java | 32 ++++-
.../java/org/apache/juneau/reflect/FieldInfo.java | 3 +-
.../java/org/apache/juneau/reflect/MethodInfo.java | 56 ++++----
.../java/org/apache/juneau/reflect/ParamInfo.java | 54 +++----
.../apache/juneau/serializer/SerializerSet.java | 3 +-
.../java/org/apache/juneau/utils/PojoQuery.java | 2 +-
.../java/org/apache/juneau/rest/RestContext.java | 7 +-
.../apache/juneau/reflect/ExecutableInfoTest.java | 12 +-
.../org/apache/juneau/reflect/MethodInfoTest.java | 2 +-
26 files changed, 370 insertions(+), 317 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationProvider.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationProvider.java
index d8abcd8..946fecf 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationProvider.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationProvider.java
@@ -12,6 +12,8 @@
//
***************************************************************************************************************************
package org.apache.juneau;
+import static org.apache.juneau.internal.ConsumerUtils.*;
+
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.function.*;
@@ -45,87 +47,82 @@ public interface AnnotationProvider {
private final TwoKeyConcurrentCache<Constructor<?>,Class<?
extends Annotation>,Annotation[]> constructorAnnotationCache = new
TwoKeyConcurrentCache<>(DISABLE_ANNOTATION_CACHING, (k1,k2) ->
k1.getAnnotationsByType(k2));
@Override /* MetaProvider */
- 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 : (A[])classAnnotationCache.get(c,a))
- if (predicate.test(aa))
- consumer.accept(aa);
+ public <A extends Annotation> void getAnnotations(Class<A>
type, Class<?> onClass, Predicate<A> predicate, Consumer<A> consumer) {
+ if (type != null && onClass != null)
+ for (A a :
(A[])classAnnotationCache.get(onClass,type))
+ consume(predicate, consumer, a);
}
@Override /* MetaProvider */
- public <A extends Annotation> A getAnnotation(Class<A> a,
Class<?> c, Predicate<A> predicate) {
- if (a != null && c != null)
- for (A aa : (A[])classAnnotationCache.get(c,a))
- if (predicate.test(aa))
- return aa;
+ public <A extends Annotation> A getAnnotation(Class<A> type,
Class<?> onClass, Predicate<A> predicate) {
+ if (type != null && onClass != null)
+ for (A a :
(A[])classAnnotationCache.get(onClass,type))
+ if (passes(predicate, a))
+ return a;
return null;
}
@Override /* MetaProvider */
- 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 :
(A[])declaredClassAnnotationCache.get(c,a))
- if (predicate.test(aa))
- consumer.accept(aa);
+ public <A extends Annotation> void
getDeclaredAnnotations(Class<A> type, Class<?> onClass, Predicate<A> predicate,
Consumer<A> consumer) {
+ if (type != null && onClass != null)
+ for (A a :
(A[])declaredClassAnnotationCache.get(onClass,type))
+ consume(predicate, consumer, a);
}
@Override /* MetaProvider */
- public <A extends Annotation> A getDeclaredAnnotation(Class<A>
a, Class<?> c, Predicate<A> predicate) {
- if (a != null && c != null)
- for (A aa :
(A[])declaredClassAnnotationCache.get(c,a))
- if (predicate.test(aa))
- return aa;
+ public <A extends Annotation> A getDeclaredAnnotation(Class<A>
type, Class<?> onClass, Predicate<A> predicate) {
+ if (type != null && onClass != null)
+ for (A a :
(A[])declaredClassAnnotationCache.get(onClass,type))
+ if (passes(predicate, a))
+ return a;
return null;
}
@Override /* MetaProvider */
- 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 : (A[])methodAnnotationCache.get(m,a))
- if (predicate.test(aa))
- consumer.accept(aa);
+ public <A extends Annotation> void getAnnotations(Class<A>
type, Method onMethod, Predicate<A> predicate, Consumer<A> consumer) {
+ if (type != null && onMethod != null)
+ for (A a :
(A[])methodAnnotationCache.get(onMethod,type))
+ consume(predicate, consumer, a);
}
@Override /* MetaProvider */
- public <A extends Annotation> A getAnnotation(Class<A> a,
Method m, Predicate<A> predicate) {
- if (a != null && m != null)
- for (A aa : (A[])methodAnnotationCache.get(m,a))
- if (predicate.test(aa))
- return aa;
+ public <A extends Annotation> A getAnnotation(Class<A> type,
Method onMethod, Predicate<A> predicate) {
+ if (type != null && onMethod != null)
+ for (A a :
(A[])methodAnnotationCache.get(onMethod,type))
+ if (passes(predicate, a))
+ return a;
return null;
}
@Override /* MetaProvider */
- 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 : (A[])fieldAnnotationCache.get(f,a))
- if (predicate.test(aa))
- consumer.accept(aa);
+ public <A extends Annotation> void getAnnotations(Class<A>
type, Field onField, Predicate<A> predicate, Consumer<A> consumer) {
+ if (type != null && onField != null)
+ for (A a :
(A[])fieldAnnotationCache.get(onField,type))
+ consume(predicate, consumer, a);
}
@Override /* MetaProvider */
- public <A extends Annotation> A getAnnotation(Class<A> a, Field
f, Predicate<A> predicate) {
- if (a != null && f != null)
- for (A aa : (A[])fieldAnnotationCache.get(f,a))
- if (predicate.test(aa))
- return aa;
+ public <A extends Annotation> A getAnnotation(Class<A> type,
Field onField, Predicate<A> predicate) {
+ if (type != null && onField != null)
+ for (A a :
(A[])fieldAnnotationCache.get(onField,type))
+ if (passes(predicate, a))
+ return a;
return null;
}
@Override /* MetaProvider */
- 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 :
(A[])constructorAnnotationCache.get(c,a))
- if (predicate.test(aa))
- consumer.accept(aa);
+ public <A extends Annotation> void getAnnotations(Class<A>
type, Constructor<?> onConstructor, Predicate<A> predicate, Consumer<A>
consumer) {
+ if (type != null && onConstructor != null)
+ for (A a :
(A[])constructorAnnotationCache.get(onConstructor,type))
+ consume(predicate, consumer, a);
}
@Override /* MetaProvider */
- public <A extends Annotation> A getAnnotation(Class<A> a,
Constructor<?> c, Predicate<A> predicate) {
- if (a != null && c != null)
- for (A aa :
(A[])constructorAnnotationCache.get(c,a))
- if (predicate.test(aa))
- return aa;
+ public <A extends Annotation> A getAnnotation(Class<A> type,
Constructor<?> onConstructor, Predicate<A> predicate) {
+ if (type != null && onConstructor != null)
+ for (A a :
(A[])constructorAnnotationCache.get(onConstructor,type))
+ if (passes(predicate, a))
+ return a;
return null;
}
};
@@ -133,106 +130,106 @@ public interface AnnotationProvider {
/**
* Finds the specified annotations on the specified class.
*
- * @param a The annotation type to find.
- * @param c The class to search on.
+ * @param type The annotation type to find.
+ * @param onClass The class to search on.
* @param predicate The predicate.
* @param consumer The consumer.
*/
- <A extends Annotation> void getAnnotations(Class<A> a, Class<?> c,
Predicate<A> predicate, Consumer<A> consumer);
+ <A extends Annotation> void getAnnotations(Class<A> type, Class<?>
onClass, 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 type The annotation type to find.
+ * @param onClass The class to search on.
* @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);
+ <A extends Annotation> A getAnnotation(Class<A> type, Class<?> onClass,
Predicate<A> predicate);
/**
* Finds the specified declared annotations on the specified class.
*
- * @param a The annotation type to find.
- * @param c The class to search on.
+ * @param type The annotation type to find.
+ * @param onClass The class to search on.
* @param predicate The predicate.
* @param consumer The consumer.
*/
- <A extends Annotation> void getDeclaredAnnotations(Class<A> a, Class<?>
c, Predicate<A> predicate, Consumer<A> consumer);
+ <A extends Annotation> void getDeclaredAnnotations(Class<A> type,
Class<?> onClass, 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 type The annotation type to find.
+ * @param onClass The class to search on.
* @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);
+ <A extends Annotation> A getDeclaredAnnotation(Class<A> type, Class<?>
onClass, Predicate<A> predicate);
/**
* Finds the 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.
+ * @param type The annotation type to find.
+ * @param onMethod The method to search on.
* @param predicate The predicate.
* @param consumer The consumer.
*/
- <A extends Annotation> void getAnnotations(Class<A> a, Method m,
Predicate<A> predicate, Consumer<A> consumer);
+ <A extends Annotation> void getAnnotations(Class<A> type, Method
onMethod, Predicate<A> predicate, Consumer<A> consumer);
/**
* Finds the 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.
+ * @param type The annotation type to find.
+ * @param onMethod The method to search on.
* @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);
+ <A extends Annotation> A getAnnotation(Class<A> type, Method onMethod,
Predicate<A> predicate);
/**
* Finds the 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.
+ * @param type The annotation type to find.
+ * @param onField The field to search on.
* @param predicate The predicate.
* @param consumer The consumer.
*/
- <A extends Annotation> void getAnnotations(Class<A> a, Field f,
Predicate<A> predicate, Consumer<A> consumer);
+ <A extends Annotation> void getAnnotations(Class<A> type, Field
onField, Predicate<A> predicate, Consumer<A> consumer);
/**
* Finds the 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.
+ * @param type The annotation type to find.
+ * @param onField The field to search on.
* @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);
+ <A extends Annotation> A getAnnotation(Class<A> type, Field onField,
Predicate<A> predicate);
/**
* Finds the specified annotations on the specified constructor.
*
* @param <A> The annotation type to find.
- * @param a The annotation type to find.
- * @param c The constructor to search on.
+ * @param type The annotation type to find.
+ * @param onConstructor The constructor to search on.
* @param predicate The predicate.
* @param consumer The consumer.
*/
- <A extends Annotation> void getAnnotations(Class<A> a, Constructor<?>
c, Predicate<A> predicate, Consumer<A> consumer);
+ <A extends Annotation> void getAnnotations(Class<A> type,
Constructor<?> onConstructor, Predicate<A> predicate, Consumer<A> consumer);
/**
* Finds the specified annotations on the specified constructor.
*
* @param <A> The annotation type to find.
- * @param a The annotation type to find.
- * @param c The constructor to search on.
+ * @param type The annotation type to find.
+ * @param onConstructor The constructor to search on.
* @param predicate The predicate to match the annotation against.
* @return The matched annotation, or <jk>null</jk> if no annotations
matched.
*/
- <A extends Annotation> A getAnnotation(Class<A> a, Constructor<?> c,
Predicate<A> predicate);
+ <A extends Annotation> A getAnnotation(Class<A> type, Constructor<?>
onConstructor, Predicate<A> predicate);
}
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 394f057..308d592 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
@@ -14,6 +14,7 @@ package org.apache.juneau;
import static org.apache.juneau.ClassMeta.ClassCategory.*;
import static org.apache.juneau.internal.ThrowableUtils.*;
+import static org.apache.juneau.internal.ConsumerUtils.*;
import static org.apache.juneau.internal.ObjectUtils.*;
import static java.util.Optional.*;
@@ -2093,29 +2094,28 @@ public final class ClassMeta<T> implements Type {
/**
* Consumes all matching 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.
+ * @param type The annotation to search for.
* @param predicate The predicate.
* @param consumer The consumer of the annotations.
* @return This object.
*/
@SuppressWarnings("unchecked")
- public <A extends Annotation> ClassMeta<T> getAnnotations(Class<A> a,
Predicate<A> predicate, Consumer<A> consumer) {
- A[] array = (A[])annotationArrayMap.get(a);
+ public <A extends Annotation> ClassMeta<T> getAnnotations(Class<A>
type, Predicate<A> predicate, Consumer<A> consumer) {
+ A[] array = (A[])annotationArrayMap.get(type);
if (array == null) {
if (beanContext == null) {
- info.getAnnotations(BeanContext.DEFAULT, a,
predicate, consumer);
+ info.getAnnotations(BeanContext.DEFAULT, type,
predicate, consumer);
return this;
}
List<A> l = new ArrayList<>();
- info.getAnnotations(beanContext, a, x-> true, x ->
l.add(x));
- array = (A[])Array.newInstance(a, l.size());
+ info.getAnnotations(beanContext, type, x-> true, x ->
l.add(x));
+ array = (A[])Array.newInstance(type, l.size());
for (int i = 0; i < l.size(); i++)
Array.set(array, i, l.get(i));
- annotationArrayMap.put(a, array);
+ annotationArrayMap.put(type, array);
}
- for (A aa : array)
- if (predicate.test(aa))
- consumer.accept(aa);
+ for (A a : array)
+ consume(predicate, consumer, a);
return this;
}
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 124e8e1..64a3449 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
@@ -14,6 +14,7 @@ package org.apache.juneau;
import static org.apache.juneau.internal.ClassUtils.*;
import static org.apache.juneau.internal.CollectionUtils.*;
+import static org.apache.juneau.internal.ConsumerUtils.*;
import static org.apache.juneau.internal.ThrowableUtils.*;
import static java.util.Optional.*;
import static org.apache.juneau.collections.OMap.*;
@@ -270,10 +271,9 @@ public abstract class Context implements
AnnotationProvider {
* @param consumer The consumer.
* @return This object.
*/
- @SuppressWarnings("unchecked")
public <T extends Builder> Builder apply(Class<T> subtype,
Consumer<T> consumer) {
if (subtype.isInstance(this))
- consumer.accept((T)this);
+ consumer.accept(subtype.cast(this));
return this;
}
@@ -940,157 +940,152 @@ public abstract class Context implements
AnnotationProvider {
//-----------------------------------------------------------------------------------------------------------------
@Override /* MetaProvider */
- 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))
- if (predicate.test(aa))
- consumer.accept(aa);
+ public <A extends Annotation> void getAnnotations(Class<A> type,
Class<?> onClass, Predicate<A> predicate, Consumer<A> consumer) {
+ if (type != null && onClass != null)
+ for (A a : annotations(type, onClass))
+ consume(predicate, consumer, a);
}
@Override /* MetaProvider */
- public <A extends Annotation> A getAnnotation(Class<A> a, Class<?> c,
Predicate<A> predicate) {
- if (a != null && c != null)
- for (A aa : annotations(a, c))
- if (predicate.test(aa))
- return aa;
+ public <A extends Annotation> A getAnnotation(Class<A> type, Class<?>
onClass, Predicate<A> predicate) {
+ if (type != null && onClass != null)
+ for (A a : annotations(type, onClass))
+ if (passes(predicate, a))
+ return a;
return null;
}
@Override /* MetaProvider */
- 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))
- if (predicate.test(aa))
- consumer.accept(aa);
+ public <A extends Annotation> void getDeclaredAnnotations(Class<A>
type, Class<?> onClass, Predicate<A> predicate, Consumer<A> consumer) {
+ if (type != null && onClass != null)
+ for (A a : declaredAnnotations(type, onClass))
+ consume(predicate, consumer, a);
}
@Override /* MetaProvider */
- public <A extends Annotation> A getDeclaredAnnotation(Class<A> a,
Class<?> c, Predicate<A> predicate) {
- if (a != null && c != null)
- for (A aa : declaredAnnotations(a, c))
- if (predicate.test(aa))
- return aa;
+ public <A extends Annotation> A getDeclaredAnnotation(Class<A> type,
Class<?> onClass, Predicate<A> predicate) {
+ if (type != null && onClass != null)
+ for (A a : declaredAnnotations(type, onClass))
+ if (passes(predicate, a))
+ return a;
return null;
}
@Override /* MetaProvider */
- 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))
- if (predicate.test(aa))
- consumer.accept(aa);
+ public <A extends Annotation> void getAnnotations(Class<A> type, Method
onMethod, Predicate<A> predicate, Consumer<A> consumer) {
+ if (type != null && onMethod != null)
+ for (A a : annotations(type, onMethod))
+ consume(predicate, consumer, a);
}
@Override /* MetaProvider */
- public <A extends Annotation> A getAnnotation(Class<A> a, Method m,
Predicate<A> predicate) {
- if (a != null && m != null)
- for (A aa : annotations(a, m))
- if (predicate.test(aa))
- return aa;
+ public <A extends Annotation> A getAnnotation(Class<A> type, Method
onMethod, Predicate<A> predicate) {
+ if (type != null && onMethod != null)
+ for (A a : annotations(type, onMethod))
+ if (passes(predicate, a))
+ return a;
return null;
}
@Override /* MetaProvider */
- 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))
- if (predicate.test(aa))
- consumer.accept(aa);
+ public <A extends Annotation> void getAnnotations(Class<A> type, Field
onField, Predicate<A> predicate, Consumer<A> consumer) {
+ if (type != null && onField != null)
+ for (A a : annotations(type, onField))
+ consume(predicate, consumer, a);
}
@Override /* MetaProvider */
- public <A extends Annotation> A getAnnotation(Class<A> a, Field f,
Predicate<A> predicate) {
- if (a != null && f != null)
- for (A aa : annotations(a, f))
- if (predicate.test(aa))
- return aa;
+ public <A extends Annotation> A getAnnotation(Class<A> type, Field
onField, Predicate<A> predicate) {
+ if (type != null && onField != null)
+ for (A a : annotations(type, onField))
+ if (passes(predicate, a))
+ return a;
return null;
}
@Override /* MetaProvider */
- 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))
- if (predicate.test(aa))
- consumer.accept(aa);
+ public <A extends Annotation> void getAnnotations(Class<A> type,
Constructor<?> onConstructor, Predicate<A> predicate, Consumer<A> consumer) {
+ if (type != null && onConstructor != null)
+ for (A a : annotations(type, onConstructor))
+ consume(predicate, consumer, a);
}
@Override /* MetaProvider */
- public <A extends Annotation> A getAnnotation(Class<A> a,
Constructor<?> c, Predicate<A> predicate) {
- if (a != null && c != null)
- for (A aa : annotations(a, c))
- if (predicate.test(aa))
- return aa;
+ public <A extends Annotation> A getAnnotation(Class<A> type,
Constructor<?> onConstructor, Predicate<A> predicate) {
+ if (type != null && onConstructor != null)
+ for (A a : annotations(type, onConstructor))
+ if (passes(predicate, a))
+ return a;
return null;
}
/**
* 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.
+ * @param type The annotation being checked for.
+ * @param onClass The class being checked on.
* @return <jk>true</jk> if the annotation exists on the specified
class.
*/
- public <A extends Annotation> boolean hasAnnotation(Class<A> a,
Class<?> c) {
- return annotations(a, c).length > 0;
+ public <A extends Annotation> boolean hasAnnotation(Class<A> type,
Class<?> onClass) {
+ return annotations(type, onClass).length > 0;
}
/**
* 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.
+ * @param type The annotation being checked for.
+ * @param onMethod The method being checked on.
* @return <jk>true</jk> if the annotation exists on the specified
method.
*/
- public <A extends Annotation> boolean hasAnnotation(Class<A> a, Method
m) {
- return annotations(a, m).length > 0;
+ public <A extends Annotation> boolean hasAnnotation(Class<A> type,
Method onMethod) {
+ return annotations(type, onMethod).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.
+ * @param type The annotation being checked for.
+ * @param onField The field being checked on.
* @return <jk>true</jk> if the annotation exists on the specified
field.
*/
- public <A extends Annotation> boolean hasAnnotation(Class<A> a, Field
f) {
- return annotations(a, f).length > 0;
+ public <A extends Annotation> boolean hasAnnotation(Class<A> type,
Field onField) {
+ return annotations(type, onField).length > 0;
}
/**
* 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 constructor being checked on.
+ * @param type The annotation being checked for.
+ * @param onConstructor The constructor being checked on.
* @return <jk>true</jk> if the annotation exists on the specified
field.
*/
- public <A extends Annotation> boolean hasAnnotation(Class<A> a,
Constructor<?> c) {
- return annotations(a, c).length > 0;
+ public <A extends Annotation> boolean hasAnnotation(Class<A> type,
Constructor<?> onConstructor) {
+ return annotations(type, onConstructor).length > 0;
}
@SuppressWarnings("unchecked")
- private <A extends Annotation> A[] annotations(Class<A> a, Class<?> c) {
- return (A[])classAnnotationCache.get(c, a);
+ private <A extends Annotation> A[] annotations(Class<A> type, Class<?>
onClass) {
+ return (A[])classAnnotationCache.get(onClass, type);
}
@SuppressWarnings("unchecked")
- private <A extends Annotation> A[] declaredAnnotations(Class<A> a,
Class<?> c) {
- return (A[])declaredClassAnnotationCache.get(c, a);
+ private <A extends Annotation> A[] declaredAnnotations(Class<A> type,
Class<?> onClass) {
+ return (A[])declaredClassAnnotationCache.get(onClass, type);
}
@SuppressWarnings("unchecked")
- private <A extends Annotation> A[] annotations(Class<A> a, Method m) {
- return (A[])methodAnnotationCache.get(m, a);
+ private <A extends Annotation> A[] annotations(Class<A> type, Method
onMethod) {
+ return (A[])methodAnnotationCache.get(onMethod, type);
}
@SuppressWarnings("unchecked")
- private <A extends Annotation> A[] annotations(Class<A> a, Field f) {
- return (A[])fieldAnnotationCache.get(f, a);
+ private <A extends Annotation> A[] annotations(Class<A> type, Field
onField) {
+ return (A[])fieldAnnotationCache.get(onField, type);
}
@SuppressWarnings("unchecked")
- private <A extends Annotation> A[] annotations(Class<A> a,
Constructor<?> c) {
- return (A[])constructorAnnotationCache.get(c, a);
+ private <A extends Annotation> A[] annotations(Class<A> type,
Constructor<?> onConstructor) {
+ return (A[])constructorAnnotationCache.get(onConstructor, type);
}
//-----------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/InvalidAnnotationException.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/InvalidAnnotationException.java
index 0e58b5b..da23cf9 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/InvalidAnnotationException.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/InvalidAnnotationException.java
@@ -43,14 +43,14 @@ public class InvalidAnnotationException extends
BasicRuntimeException {
/**
* Throws an {@link InvalidAnnotationException} if the specified method
contains any of the specified annotations.
*
- * @param m The method to check.
- * @param a The annotations to check for.
+ * @param onMethod The method to check.
+ * @param types The annotations to check for.
* @throws InvalidAnnotationException Annotation was used in an invalid
location.
*/
@SafeVarargs
- public static void assertNoInvalidAnnotations(MethodInfo m, Class<?
extends Annotation>...a) throws InvalidAnnotationException {
- Annotation aa = m.getAnyAnnotation(a);
- if (aa != null)
- throw new InvalidAnnotationException("@{0} annotation
cannot be used in a @{1} bean. Method=''{2}''", aa.getClass().getSimpleName(),
m.getDeclaringClass().getSimpleName(), m);
+ public static void assertNoInvalidAnnotations(MethodInfo onMethod,
Class<? extends Annotation>...types) throws InvalidAnnotationException {
+ Annotation a = onMethod.getAnyAnnotation(types);
+ if (a != null)
+ throw new InvalidAnnotationException("@{0} annotation
cannot be used in a @{1} bean. Method=''{2}''", a.getClass().getSimpleName(),
onMethod.getDeclaringClass().getSimpleName(), onMethod);
}
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentAnyAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentAnyAssertion.java
index 51d6cdb..3e44c05 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentAnyAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentAnyAssertion.java
@@ -499,11 +499,10 @@ public class FluentAnyAssertion<T,R> extends
FluentObjectAssertion<T,R> {
// Utility methods
//-----------------------------------------------------------------------------------------------------------------
- @SuppressWarnings("unchecked")
private <T2> T2 cast(Class<T2> c) throws AssertionError {
Object o = orElse(null);
if (o == null || c.isInstance(o))
- return (T2)o;
+ return c.cast(o);
throw new BasicAssertionError(MSG_objectWasNotType,
ClassInfo.of(c).getFullName(), o.getClass());
}
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
index 4b99277..d5845e5 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
@@ -275,11 +275,10 @@ public class FluentThrowableAssertion<T extends
Throwable,R> extends FluentObjec
* @param type The expected exception type.
* @return An assertion against the caused-by. Never <jk>null</jk>.
*/
- @SuppressWarnings("unchecked")
public <E extends Throwable> FluentThrowableAssertion<E,R>
causedBy(Class<E> type) {
Throwable t = map(Throwable::getCause).orElse(null);
if (t == null || type.isInstance(t))
- return new FluentThrowableAssertion<>(this, (E)t,
returns());
+ return new FluentThrowableAssertion<>(this,
type.cast(t), returns());
throw error(MSG_causedByExceptionNotExpectedType, type,
t.getClass());
}
@@ -295,12 +294,11 @@ public class FluentThrowableAssertion<T extends
Throwable,R> extends FluentObjec
* @param throwableClass The class type to search for in the caused-by
chain.
* @return An assertion against the caused-by throwable. Never
<jk>null</jk>.
*/
- @SuppressWarnings("unchecked")
public <E extends Throwable> FluentThrowableAssertion<E,R>
find(Class<E> throwableClass) {
Throwable t = orElse(null);
while (t != null) {
if (throwableClass.isInstance(t))
- return new FluentThrowableAssertion<>(this,
(E)t, returns());
+ return new FluentThrowableAssertion<>(this,
throwableClass.cast(t), returns());
t = t.getCause();
}
return new FluentThrowableAssertion<>(this, (E)null, returns());
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/ContextBeanCreator.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/ContextBeanCreator.java
index 5e3f3f1..c680069 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/ContextBeanCreator.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/ContextBeanCreator.java
@@ -104,9 +104,8 @@ public class ContextBeanCreator<T> {
* @param c The builder class type.
* @return An optional containing the builder if it exists.
*/
- @SuppressWarnings("unchecked")
public <T2 extends Context.Builder> Optional<T2> builder(Class<T2> c) {
- return ofNullable(c.isInstance(builder) ? (T2)builder : null);
+ return ofNullable(c.isInstance(builder) ? c.cast(builder) :
null);
}
/**
@@ -120,10 +119,9 @@ public class ContextBeanCreator<T> {
* @param operation The operation to apply.
* @return This object.
*/
- @SuppressWarnings("unchecked")
public <T2 extends Context.Builder> ContextBeanCreator<T>
builder(Class<T2> c, Consumer<T2> operation) {
if (c.isInstance(builder))
- operation.accept((T2)builder);
+ operation.accept(c.cast(builder));
return this;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ConsumerUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ConsumerUtils.java
new file mode 100644
index 0000000..b6f0397
--- /dev/null
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ConsumerUtils.java
@@ -0,0 +1,69 @@
+//
***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file *
+// * distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance *
+// * with the License. You may obtain a copy of the License at
*
+// *
*
+// * http://www.apache.org/licenses/LICENSE-2.0
*
+// *
*
+// * Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
+// * specific language governing permissions and limitations under the
License. *
+//
***************************************************************************************************************************
+package org.apache.juneau.internal;
+
+import java.util.function.*;
+
+/**
+ * Utilities when working with {@link Predicate Predicates} and {@link
Consumer Consumers}.
+ */
+public final class ConsumerUtils {
+
+ /**
+ * Returns <jk>true</jk> if the specified predicate is <jk>null</jk> or
matches the specified value.
+
+ * @param predicate The predicate.
+ * @param value The value to test.
+ * @return <jk>true</jk> if the specified predicate is <jk>null</jk> or
matches the specified value.
+ */
+ public static <T> boolean passes(Predicate<T> predicate, T value) {
+ return (predicate == null || predicate.test(value));
+ }
+
+ /**
+ * Returns <jk>true</jk> if the specified object is the specified type
and the specified predicate is <jk>null</jk> or matches the specified value.
+ *
+ * @param type The expected type.
+ * @param predicate The predicate.
+ * @param value The value.
+ * @return <jk>true</jk> if the specified predicate is <jk>null</jk> or
matches the specified value.
+ */
+ public static <T> boolean passes(Class<T> type, Predicate<T> predicate,
Object value) {
+ return type.isInstance(value) && (predicate == null ||
predicate.test(type.cast(value)));
+ }
+
+ /**
+ * Consumes the specified value if the predicate is <jk>null</jk> or
matches the specified value.
+ *
+ * @param predicate The predicate.
+ * @param consumer The consumer.
+ * @param value The value.
+ */
+ public static <T> void consume(Predicate<T> predicate, Consumer<T>
consumer, T value) {
+ if (passes(predicate, value))
+ consumer.accept(value);
+ }
+
+ /**
+ * Consumes the specified value if it's the specified type and the
predicate is <jk>null</jk> or matches the specified value.
+ *
+ * @param type The expected type.
+ * @param predicate The predicate.
+ * @param consumer The consumer.
+ * @param value The value.
+ */
+ public static <T> void consume(Class<T> type, Predicate<T> predicate,
Consumer<T> consumer, Object value) {
+ if (passes(type, predicate, value))
+ consumer.accept(type.cast(value));
+ }
+}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ListBuilder.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ListBuilder.java
index 316846b..9cc674b 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ListBuilder.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ListBuilder.java
@@ -206,7 +206,6 @@ public class ListBuilder<E> {
* @param values The values to add.
* @return This object.
*/
- @SuppressWarnings("unchecked")
public ListBuilder<E> addAny(Object...values) {
if (elementType == null)
throw runtimeException("Unknown element type. Cannot
use this method.");
@@ -224,7 +223,7 @@ public class ListBuilder<E> {
for (Object o2 : new
OList(o.toString()))
addAny(o2);
} else if
(elementType.isInstance(o)) {
- add((E)o);
+
add(elementType.cast(o));
} else {
add(toType(o,
elementType, elementTypeArgs));
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
index 54d83f9..35fd9df 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
@@ -37,10 +37,9 @@ public class ObjectUtils {
* @param c The class to cast to.
* @return The cast object, or <jk>null</jk> if the object wasn't an
instance of the specified class.
*/
- @SuppressWarnings("unchecked")
public static <T> T castOrNull(Object o, Class<T> c) {
if (c.isInstance(o))
- return (T)o;
+ return c.cast(o);
return null;
}
@@ -227,9 +226,8 @@ public class ObjectUtils {
* @param o The object to cast to.
* @return The cast object, or <jk>null</jk> if the object wasn't the
specified type.
*/
- @SuppressWarnings("unchecked")
public static <T> T cast(Class<T> c, Object o) {
- return o != null && c.isInstance(o) ? (T)o : null;
+ return o != null && c.isInstance(o) ? c.cast(o) : null;
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/SetBuilder.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/SetBuilder.java
index 91f4682..4268df0 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/SetBuilder.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/SetBuilder.java
@@ -209,7 +209,6 @@ public class SetBuilder<E> {
* @param values The values to add.
* @return This object.
*/
- @SuppressWarnings("unchecked")
public SetBuilder<E> addAny(Object...values) {
if (elementType == null)
throw runtimeException("Unknown element type. Cannot
use this method.");
@@ -227,7 +226,7 @@ public class SetBuilder<E> {
for (Object o2 : new
OList(o.toString()))
addAny(o2);
} else if
(elementType.isInstance(o)) {
- add((E)o);
+
add(elementType.cast(o));
} else {
add(toType(o,
elementType, elementTypeArgs));
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ThrowableUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ThrowableUtils.java
index a8209f9..2d37f7f 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ThrowableUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ThrowableUtils.java
@@ -161,12 +161,11 @@ public class ThrowableUtils {
* @param t The throwable to search.
* @return The exception, or <jk>null</jk> if not found.
*/
- @SuppressWarnings("unchecked")
public static <T extends Throwable> T getCause(Class<T> c, Throwable t)
{
while (t != null) {
t = t.getCause();
if (c.isInstance(t))
- return (T)t;
+ return c.cast(t);
}
return null;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserSet.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserSet.java
index 8154ee4..3f407eb 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserSet.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserSet.java
@@ -444,9 +444,8 @@ public final class ParserSet {
return entries;
}
- @SuppressWarnings("unchecked")
private <T extends Parser.Builder> Stream<T> builders(Class<T>
type) {
- return entries.stream().filter(x ->
type.isInstance(x)).map(x -> (T)x);
+ return entries.stream().filter(x ->
type.isInstance(x)).map(x -> type.cast(x));
}
// <FluentSetters>
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationInfo.java
index abd331e..0592726 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationInfo.java
@@ -12,6 +12,8 @@
//
***************************************************************************************************************************
package org.apache.juneau.reflect;
+import static org.apache.juneau.internal.ConsumerUtils.*;
+
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.*;
@@ -253,7 +255,7 @@ public class AnnotationInfo<T extends Annotation> {
* @return <jk>true</jk> if this object passes the specified predicate
test.
*/
public boolean matches(Predicate<AnnotationInfo<?>> predicate) {
- return predicate.test(this);
+ return passes(predicate, this);
}
/**
@@ -288,9 +290,7 @@ public class AnnotationInfo<T extends Annotation> {
for (Method m : a.annotationType().getMethods())
if (m.getName().equals(name) &&
m.getReturnType().equals(type)) {
try {
- V v = (V)m.invoke(a);
- if (predicate.test(v))
- consumer.accept(v);
+ consume(predicate, consumer,
(V)m.invoke(a));
} catch (Exception e) {
e.printStackTrace(); // Shouldn't
happen.
}
@@ -312,7 +312,7 @@ public class AnnotationInfo<T extends Annotation> {
if (m.getName().equals(name) &&
m.getReturnType().equals(type)) {
try {
V v = (V)m.invoke(a);
- if (predicate.test(v))
+ if (passes(predicate, v))
return Optional.of(v);
} catch (Exception e) {
e.printStackTrace(); // Shouldn't
happen.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationList.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationList.java
index 5b6457a..7124c32 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationList.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationList.java
@@ -12,6 +12,8 @@
//
***************************************************************************************************************************
package org.apache.juneau.reflect;
+import static org.apache.juneau.internal.ConsumerUtils.*;
+
import java.lang.annotation.*;
import java.util.*;
import java.util.function.*;
@@ -71,8 +73,8 @@ public class AnnotationList extends
ArrayList<AnnotationInfo<?>> {
@SuppressWarnings("unchecked")
public <A extends Annotation> AnnotationList forEach(Class<A> a,
Predicate<AnnotationInfo<A>> predicate, Consumer<AnnotationInfo<A>> consumer) {
for (AnnotationInfo<?> ai : this)
- if (ai.isType(a) &&
predicate.test((AnnotationInfo<A>)ai))
- consumer.accept((AnnotationInfo<A>)ai);
+ if (ai.isType(a))
+ consume(predicate, consumer,
(AnnotationInfo<A>)ai);
return this;
}
@@ -85,8 +87,7 @@ public class AnnotationList extends
ArrayList<AnnotationInfo<?>> {
*/
public <A extends Annotation> AnnotationList
forEach(Predicate<AnnotationInfo<?>> predicate, Consumer<AnnotationInfo<?>>
consumer) {
for (AnnotationInfo<?> ai : this)
- if (predicate.test(ai))
- consumer.accept(ai);
+ consume(predicate, consumer, ai);
return this;
}
}
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 687e035..bedd423 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
@@ -16,6 +16,8 @@ import static org.apache.juneau.internal.StringUtils.*;
import static org.apache.juneau.assertions.Assertions.*;
import static org.apache.juneau.internal.ThrowableUtils.*;
import static org.apache.juneau.internal.ObjectUtils.*;
+import static org.apache.juneau.internal.ConsumerUtils.*;
+
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.*;
@@ -355,7 +357,7 @@ public final class ClassInfo {
*/
public ClassInfo getAnyParent(Predicate<ClassInfo> predicate) {
for (ClassInfo ci : _getAllParents())
- if (predicate.test(ci))
+ if (passes(predicate, ci))
return ci;
return null;
}
@@ -442,8 +444,7 @@ public final class ClassInfo {
*/
public final ClassInfo getPublicMethods(Predicate<MethodInfo>
predicate, Consumer<MethodInfo> consumer) {
for (MethodInfo mi : _getPublicMethods())
- if (predicate.test(mi))
- consumer.accept(mi);
+ consume(predicate, consumer, mi);
return this;
}
@@ -455,7 +456,7 @@ public final class ClassInfo {
*/
public final MethodInfo getPublicMethod(Predicate<MethodInfo>
predicate) {
for (MethodInfo mi : _getPublicMethods())
- if (predicate.test(mi))
+ if (passes(predicate, mi))
return mi;
return null;
}
@@ -480,8 +481,7 @@ public final class ClassInfo {
*/
public final ClassInfo getDeclaredMethods(Predicate<MethodInfo>
predicate, Consumer<MethodInfo> consumer) {
for (MethodInfo mi : _getDeclaredMethods())
- if (predicate.test(mi))
- consumer.accept(mi);
+ consume(predicate, consumer, mi);
return this;
}
@@ -493,7 +493,7 @@ public final class ClassInfo {
*/
public MethodInfo getDeclaredMethod(Predicate<MethodInfo> predicate) {
for (MethodInfo mi : _getDeclaredMethods())
- if (predicate.test(mi))
+ if (passes(predicate, mi))
return mi;
return null;
}
@@ -518,8 +518,7 @@ public final class ClassInfo {
*/
public final ClassInfo getMethods(Predicate<MethodInfo> predicate,
Consumer<MethodInfo> consumer) {
for (MethodInfo mi : _getAllMethods())
- if (predicate.test(mi))
- consumer.accept(mi);
+ consume(predicate, consumer, mi);
return this;
}
@@ -531,7 +530,7 @@ public final class ClassInfo {
*/
public MethodInfo getMethod(Predicate<MethodInfo> predicate) {
for (MethodInfo mi : _getAllMethods())
- if (predicate.test(mi))
+ if (passes(predicate, mi))
return mi;
return null;
}
@@ -557,8 +556,7 @@ public final class ClassInfo {
*/
public final ClassInfo getAllMethodsParentFirst(Predicate<MethodInfo>
predicate, Consumer<MethodInfo> consumer) {
for (MethodInfo mi : _getAllMethodsParentFirst())
- if (predicate.test(mi))
- consumer.accept(mi);
+ consume(predicate, consumer, mi);
return this;
}
@@ -645,8 +643,7 @@ public final class ClassInfo {
*/
public final ClassInfo getPublicConstructors(Predicate<ConstructorInfo>
predicate, Consumer<ConstructorInfo> consumer) {
for (ConstructorInfo mi : _getPublicConstructors())
- if (predicate.test(mi))
- consumer.accept(mi);
+ consume(predicate, consumer, mi);
return this;
}
@@ -658,7 +655,7 @@ public final class ClassInfo {
*/
public ConstructorInfo getPublicConstructor(Predicate<ConstructorInfo>
predicate) {
for (ConstructorInfo ci : _getPublicConstructors())
- if (predicate.test(ci))
+ if (passes(predicate, ci))
return ci;
return null;
}
@@ -681,8 +678,7 @@ public final class ClassInfo {
*/
public final ClassInfo
getDeclaredConstructors(Predicate<ConstructorInfo> predicate,
Consumer<ConstructorInfo> consumer) {
for (ConstructorInfo mi : _getDeclaredConstructors())
- if (predicate.test(mi))
- consumer.accept(mi);
+ consume(predicate, consumer, mi);
return this;
}
@@ -694,7 +690,7 @@ public final class ClassInfo {
*/
public ConstructorInfo
getDeclaredConstructor(Predicate<ConstructorInfo> predicate) {
for (ConstructorInfo ci : _getDeclaredConstructors())
- if (predicate.test(ci))
+ if (passes(predicate, ci))
return ci;
return null;
}
@@ -779,8 +775,7 @@ public final class ClassInfo {
*/
public final ClassInfo getPublicFields(Predicate<FieldInfo> predicate,
Consumer<FieldInfo> consumer) {
for (FieldInfo mi : _getPublicFields())
- if (predicate.test(mi))
- consumer.accept(mi);
+ consume(predicate, consumer, mi);
return this;
}
@@ -792,7 +787,7 @@ public final class ClassInfo {
*/
public FieldInfo getPublicField(Predicate<FieldInfo> predicate) {
for (FieldInfo f : _getPublicFields())
- if (predicate.test(f))
+ if (passes(predicate, f))
return f;
return null;
}
@@ -817,8 +812,7 @@ public final class ClassInfo {
*/
public ClassInfo getDeclaredFields(Predicate<FieldInfo> predicate,
Consumer<FieldInfo> consumer) {
for (FieldInfo fi : _getDeclaredFields())
- if (predicate.test(fi))
- consumer.accept(fi);
+ consume(predicate, consumer, fi);
return this;
}
@@ -830,7 +824,7 @@ public final class ClassInfo {
*/
public FieldInfo getDeclaredField(Predicate<FieldInfo> predicate) {
for (FieldInfo f : _getDeclaredFields())
- if (predicate.test(f))
+ if (passes(predicate, f))
return f;
return null;
}
@@ -859,8 +853,7 @@ public final class ClassInfo {
*/
public ClassInfo getAllFields(Predicate<FieldInfo> predicate,
Consumer<FieldInfo> consumer) {
for (FieldInfo fi : _getAllFields())
- if (predicate.test(fi))
- consumer.accept(fi);
+ consume(predicate, consumer, fi);
return this;
}
@@ -976,8 +969,8 @@ public final class ClassInfo {
if (predicate == null) predicate = x->true;
if (annotationProvider == null) annotationProvider =
AnnotationProvider.DEFAULT;
A t2 = getPackageAnnotation(type);
- if (t2 != null && predicate.test(t2))
- consumer.accept(t2);
+ if (t2 != null)
+ consume(predicate, consumer, t2);
ClassInfo[] interfaces = _getInterfaces();
for (int i = interfaces.length-1; i >= 0; i--)
annotationProvider.getDeclaredAnnotations(type,
interfaces[i].inner(), predicate, consumer);
@@ -2289,7 +2282,7 @@ public final class ClassInfo {
* @return <jk>true</jk> if this object passes the specified predicate
test.
*/
public boolean matches(Predicate<ClassInfo> predicate) {
- return predicate.test(this);
+ return passes(predicate, this);
}
/**
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 0712061..ecd8b2b 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
@@ -12,6 +12,8 @@
//
***************************************************************************************************************************
package org.apache.juneau.reflect;
+import static org.apache.juneau.internal.ConsumerUtils.*;
+
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.function.*;
@@ -144,7 +146,7 @@ public final class ConstructorInfo extends ExecutableInfo
implements Comparable<
* @return <jk>true</jk> if this object passes the specified predicate
test.
*/
public boolean matches(Predicate<ConstructorInfo> predicate) {
- return predicate.test(this);
+ return passes(predicate, this);
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
index d2a9ca4..96ada52 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
@@ -13,11 +13,13 @@
package org.apache.juneau.reflect;
import static org.apache.juneau.internal.ThrowableUtils.*;
+import static org.apache.juneau.internal.ConsumerUtils.*;
import static org.apache.juneau.internal.StringUtils.*;
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.*;
+import java.util.function.*;
import org.apache.juneau.*;
import org.apache.juneau.internal.*;
@@ -42,6 +44,7 @@ public abstract class ExecutableInfo {
private volatile Type[] rawGenericParamTypes;
private volatile Parameter[] rawParameters;
private volatile Annotation[][] parameterAnnotations;
+ private volatile Annotation[] declaredAnnotations;
/**
* Constructor.
@@ -314,7 +317,23 @@ public abstract class ExecutableInfo {
// Annotations
//-----------------------------------------------------------------------------------------------------------------
- final Annotation[][] getParameterAnnotations() {
+ /**
+ * Consumes the matching parameter annotations of the specified type at
the specified parameter index.
+ *
+ * @param index The parameter index.
+ * @param type The annotation type.
+ * @param predicate The predicate.
+ * @param consumer The consumer.
+ * @return This object.
+ */
+ public <A extends Annotation> ExecutableInfo
getParameterAnnotations(int index, Class<A> type, Predicate<A> predicate,
Consumer<A> consumer) {
+ for (Annotation a : getParameterAnnotations(index))
+ if (type.isInstance(a))
+ consume(predicate, consumer, type.cast(a));
+ return this;
+ }
+
+ final Annotation[][] _getParameterAnnotations() {
if (parameterAnnotations == null) {
synchronized(this) {
parameterAnnotations =
e.getParameterAnnotations();
@@ -325,7 +344,7 @@ public abstract class ExecutableInfo {
final Annotation[] getParameterAnnotations(int index) {
checkIndex(index);
- Annotation[][] x = getParameterAnnotations();
+ Annotation[][] x = _getParameterAnnotations();
int c = e.getParameterCount();
if (c != x.length) {
// Seems to be a JVM bug where
getParameterAnnotations() don't take mandated parameters into account.
@@ -340,6 +359,15 @@ public abstract class ExecutableInfo {
return x[index];
}
+ final Annotation[] getDeclaredAnnotations() {
+ if (declaredAnnotations == null) {
+ synchronized(this) {
+ declaredAnnotations =
e.getDeclaredAnnotations();
+ }
+ }
+ return declaredAnnotations;
+ }
+
//-----------------------------------------------------------------------------------------------------------------
// Exceptions
//-----------------------------------------------------------------------------------------------------------------
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 d94d38f..a7fac52 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
@@ -12,6 +12,7 @@
//
***************************************************************************************************************************
package org.apache.juneau.reflect;
+import static org.apache.juneau.internal.ConsumerUtils.*;
import static org.apache.juneau.internal.ThrowableUtils.*;
import java.lang.annotation.*;
@@ -406,7 +407,7 @@ public final class FieldInfo implements
Comparable<FieldInfo> {
* @return <jk>true</jk> if this object passes the specified predicate
test.
*/
public boolean matches(Predicate<FieldInfo> predicate) {
- return predicate.test(this);
+ return passes(predicate, this);
}
/**
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 3f1ae46..b10afbb 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
@@ -12,6 +12,8 @@
//
***************************************************************************************************************************
package org.apache.juneau.reflect;
+import static org.apache.juneau.internal.ConsumerUtils.*;
+
import java.beans.*;
import java.lang.annotation.*;
import java.lang.reflect.*;
@@ -79,7 +81,7 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
private final Method m;
private volatile ClassInfo returnType;
- private volatile Method[] matching;
+ private volatile MethodInfo[] matching;
/**
* Constructor.
@@ -151,10 +153,9 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
* @param consumer The consumer.
* @return This object.
*/
- public MethodInfo getMatching(Predicate<Method> predicate,
Consumer<Method> consumer) {
- for (Method m : _getMatching())
- if (predicate.test(m))
- consumer.accept(m);
+ public MethodInfo getMatching(Predicate<MethodInfo> predicate,
Consumer<MethodInfo> consumer) {
+ for (MethodInfo m : _getMatching())
+ consume(predicate, consumer, m);
return this;
}
@@ -168,18 +169,17 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
* @param consumer The consumer.
* @return This object.
*/
- public MethodInfo getMatchingParentFirst(Predicate<Method> predicate,
Consumer<Method> consumer) {
- Method[] m = _getMatching();
+ public MethodInfo getMatchingParentFirst(Predicate<MethodInfo>
predicate, Consumer<MethodInfo> consumer) {
+ MethodInfo[] m = _getMatching();
for (int i = m.length-1; i >= 0; i--)
- if (predicate.test(m[i]))
- consumer.accept(m[i]);
+ consume(predicate, consumer, m[i]);
return this;
}
- private static List<Method> findMatching(List<Method> l, Method m,
Class<?> c) {
+ private static List<MethodInfo> findMatching(List<MethodInfo> l, Method
m, Class<?> c) {
for (Method m2 : c.getDeclaredMethods())
if (m.getName().equals(m2.getName()) &&
Arrays.equals(m.getParameterTypes(), m2.getParameterTypes()))
- l.add(m2);
+ l.add(MethodInfo.of(m2));
Class<?> pc = c.getSuperclass();
if (pc != null)
findMatching(l, m, pc);
@@ -188,18 +188,18 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
return l;
}
- private Method findMatchingOnClass(ClassInfo c) {
+ private MethodInfo findMatchingOnClass(ClassInfo c) {
for (Method m2 : c.inner().getDeclaredMethods())
if (m.getName().equals(m2.getName()) &&
Arrays.equals(m.getParameterTypes(), m2.getParameterTypes()))
- return m2;
+ return MethodInfo.of(m2);
return null;
}
- private Method[] _getMatching() {
+ private MethodInfo[] _getMatching() {
if (matching == null) {
synchronized(this) {
- List<Method> l = findMatching(new
ArrayList<>(), m, m.getDeclaringClass());
- matching = l.toArray(new Method[l.size()]);
+ List<MethodInfo> l = findMatching(new
ArrayList<>(), m, m.getDeclaringClass());
+ matching = l.toArray(new MethodInfo[l.size()]);
}
}
return matching;
@@ -239,8 +239,8 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
if (type == null)
return null;
Value<A> t = Value.empty();
- for (Method m2 : _getMatching()) {
- annotationProvider.getAnnotations(type, m2, x -> true,
x -> t.set(x));
+ for (MethodInfo m2 : _getMatching()) {
+ annotationProvider.getAnnotations(type, m2.inner(), x
-> true, x -> t.set(x));
if (t.isPresent())
return t.get();
}
@@ -265,8 +265,8 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
* @return <jk>true</jk> if the specified annotation is present on this
method.
*/
public final <A extends Annotation> boolean
hasAnnotation(AnnotationProvider annotationProvider, Class<A> type) {
- for (Method m2 : _getMatching())
- if (annotationProvider.getAnnotation(type, m2, x ->
true) != null)
+ for (MethodInfo m2 : _getMatching())
+ if (annotationProvider.getAnnotation(type, m2.inner(),
x -> true) != null)
return true;
return false;
}
@@ -289,8 +289,8 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
*/
@SafeVarargs
public final boolean hasAnyAnnotations(Class<? extends
Annotation>...types) {
- for (Class<? extends Annotation> aa : types)
- if (hasAnnotation(aa))
+ for (Class<? extends Annotation> a : types)
+ if (hasAnnotation(a))
return true;
return false;
}
@@ -326,14 +326,12 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
* @param consumer The consumer.
* @return This object.
*/
- @SuppressWarnings("unchecked")
public <A extends Annotation> MethodInfo
getAnnotations(AnnotationProvider annotationProvider, Class<A> type,
Predicate<A> predicate, Consumer<A> consumer) {
declaringClass.getAnnotations(annotationProvider, type,
predicate, consumer);
- Method[] m = _getMatching();
+ MethodInfo[] m = _getMatching();
for (int i = m.length-1; i >= 0; i--)
for (Annotation a2 : m[i].getDeclaredAnnotations())
- if (type.isInstance(a2) &&
predicate.test((A)a2))
- consumer.accept((A)a2);
+ consume(type, predicate, consumer, a2);
getReturnType().unwrap(Value.class,Optional.class).getAnnotations(annotationProvider,
type, predicate, consumer);
return this;
}
@@ -453,10 +451,10 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
}
private void getDeclaredMethodAnnotationInfos(ClassInfo ci,
Predicate<AnnotationInfo<?>> predicate, Consumer<AnnotationInfo<?>> consumer) {
- Method m = findMatchingOnClass(ci);
+ MethodInfo m = findMatchingOnClass(ci);
if (m != null)
for (Annotation a : m.getDeclaredAnnotations())
- AnnotationInfo.of(MethodInfo.of(m),
a).accept(predicate, consumer);
+ AnnotationInfo.of(m, a).accept(predicate,
consumer);
}
//-----------------------------------------------------------------------------------------------------------------
@@ -528,7 +526,7 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
* @return <jk>true</jk> if this object passes the specified predicate
test.
*/
public boolean matches(Predicate<MethodInfo> predicate) {
- return predicate.test(this);
+ return passes(predicate, this);
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ParamInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ParamInfo.java
index 7d80912..121f80e 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ParamInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ParamInfo.java
@@ -12,6 +12,8 @@
//
***************************************************************************************************************************
package org.apache.juneau.reflect;
+import static org.apache.juneau.internal.ConsumerUtils.*;
+
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.*;
@@ -100,11 +102,9 @@ public final class ParamInfo {
* @param consumer The consumer.
* @return This object.
*/
- @SuppressWarnings("unchecked")
public <A extends Annotation> ParamInfo getDeclaredAnnotations(Class<A>
type, Predicate<A> predicate, Consumer<A> consumer) {
for (Annotation a : eInfo.getParameterAnnotations(index))
- if (type.isInstance(a) && predicate.test((A)a))
- consumer.accept((A)a);
+ consume(type, predicate, consumer, a);
return this;
}
@@ -117,12 +117,11 @@ public final class ParamInfo {
* The annotation type.
* @return The specified parameter annotation declared on this
parameter, or <jk>null</jk> if not found.
*/
- @SuppressWarnings("unchecked")
public <A extends Annotation> A getDeclaredAnnotation(Class<A> type) {
if (type != null)
- for (Annotation aa :
eInfo.getParameterAnnotations(index))
- if (type.isInstance(aa))
- return (A)aa;
+ for (Annotation a :
eInfo.getParameterAnnotations(index))
+ if (type.isInstance(a))
+ return type.cast(a);
return null;
}
@@ -164,23 +163,17 @@ public final class ParamInfo {
return getAnnotation(type) != null;
}
- @SuppressWarnings("unchecked")
- private <T extends Annotation> T findAnnotation(Class<T> a) {
+ private <A extends Annotation> A findAnnotation(Class<A> type) {
if (eInfo.isConstructor()) {
for (Annotation a2 :
eInfo.getParameterAnnotations(index))
- if (a.isInstance(a2))
- return (T)a2;
- return
eInfo.getParamType(index).unwrap(Value.class,Optional.class).getAnnotation(a);
+ if (type.isInstance(a2))
+ return type.cast(a2);
+ return
eInfo.getParamType(index).unwrap(Value.class,Optional.class).getAnnotation(type);
}
MethodInfo mi = (MethodInfo)eInfo;
- Value<T> v = Value.empty();
- mi.getMatchingParentFirst(x -> true, x -> {
- for (Annotation a2 :
x.getParameterAnnotations()[index])
- if (a.isInstance(a2))
- v.set((T)a2);
-
- });
- return v.orElseGet(() ->
eInfo.getParamType(index).unwrap(Value.class,Optional.class).getAnnotation(a));
+ Value<A> v = Value.empty();
+ mi.getMatchingParentFirst(x -> true, x ->
x.getParameterAnnotations(index, type, y -> true, y -> v.set(y)));
+ return v.orElseGet(() ->
eInfo.getParamType(index).unwrap(Value.class,Optional.class).getAnnotation(type));
}
/**
@@ -222,7 +215,7 @@ public final class ParamInfo {
if (o != null)
return o;
for (Annotation a2 :
eInfo.getParameterAnnotations(index))
- if (type.isInstance(a2) &&
predicate.test((A)a2))
+ if (passes(type, predicate, a2))
return (A)a2;
} else {
MethodInfo mi = (MethodInfo)eInfo;
@@ -231,35 +224,24 @@ public final class ParamInfo {
if (o != null)
return o;
Value<A> v = Value.empty();
- mi.getMatchingParentFirst(x -> true, x -> {
- for (Annotation a2 :
x.getParameterAnnotations()[index])
- if (type.isInstance(a2) &&
predicate.test((A)a2))
- v.set((A)a2);
- });
+ mi.getMatchingParentFirst(x -> true, x ->
x.getParameterAnnotations(index, type, predicate, y -> v.set(y)));
return v.orElse(null);
}
return null;
}
- @SuppressWarnings("unchecked")
private <A extends Annotation> ParamInfo
getAnnotations(AnnotationProvider ap, Class<A> a, Predicate<A> predicate,
Consumer<A> consumer) {
if (eInfo.isConstructor) {
ClassInfo ci =
eInfo.getParamType(index).unwrap(Value.class,Optional.class);
Annotation[] annotations =
eInfo.getParameterAnnotations(index);
ci.getAnnotations(ap, a, predicate, consumer);
for (Annotation a2 : annotations)
- if (a.isInstance(a2) && predicate.test((A)a2))
- consumer.accept((A)a2);
+ consume(a, predicate, consumer, a2);
} else {
MethodInfo mi = (MethodInfo)eInfo;
ClassInfo ci =
eInfo.getParamType(index).unwrap(Value.class,Optional.class);
ci.getAnnotations(ap, a, predicate, consumer);
- mi.getMatchingParentFirst(x -> true, x -> {
- for (Annotation a2 :
x.getParameterAnnotations()[index])
- if (a.isInstance(a2) &&
predicate.test((A)a2))
- consumer.accept((A)a2);
-
- });
+ mi.getMatchingParentFirst(x -> true, x ->
x.getParameterAnnotations(index, a, predicate, consumer));
}
return this;
}
@@ -284,7 +266,7 @@ public final class ParamInfo {
* @return <jk>true</jk> if this object passes the specified predicate
test.
*/
public boolean matches(Predicate<ParamInfo> predicate) {
- return predicate.test(this);
+ return passes(predicate, this);
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSet.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSet.java
index 9e03ccc..6fe12b8 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSet.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/SerializerSet.java
@@ -440,9 +440,8 @@ public final class SerializerSet {
return entries;
}
- @SuppressWarnings("unchecked")
private <T extends Serializer.Builder> Stream<T>
builders(Class<T> type) {
- return entries.stream().filter(x ->
type.isInstance(x)).map(x -> (T)x);
+ return entries.stream().filter(x ->
type.isInstance(x)).map(x -> type.cast(x));
}
// <FluentSetters>
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/PojoQuery.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/PojoQuery.java
index 9a53a3a..717aff8 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/PojoQuery.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/PojoQuery.java
@@ -510,7 +510,7 @@ public final class PojoQuery {
/**
* Construct a number matcher for the given search pattern.
*
- * @param searchPattern A date search paattern. See class
usage for a description.
+ * @param searchPattern A date search pattern. See class usage
for a description.
*/
public NumberMatcher(String searchPattern) {
numberPatterns = new NumberPattern[1];
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 b2a6c09..9560802 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
@@ -407,10 +407,9 @@ public class RestContext extends Context {
* @param type The expected type of the resource bean.
* @return The bean cast to that instance, or {@link
Optional#empty()} if it's not the specified type.
*/
- @SuppressWarnings("unchecked")
public final <T> Optional<T> resourceAs(Class<T> type) {
Object r = resource().get();
- return Optional.ofNullable(type.isInstance(r) ? (T)r :
null);
+ return Optional.ofNullable(type.isInstance(r) ?
type.cast(r) : null);
}
//-----------------------------------------------------------------------------------------------------------------
@@ -4050,8 +4049,8 @@ public class RestContext extends Context {
// Also include methods on @Rest-annotated
interfaces.
if (al.size() == 0) {
- Predicate<Method>
isRestAnnotatedInterface = x -> x.getDeclaringClass().isInterface() &&
x.getDeclaringClass().getAnnotation(Rest.class) != null;
-
mi.getMatching(isRestAnnotatedInterface, x ->
al.add(AnnotationInfo.of(MethodInfo.of(x), RestOpAnnotation.DEFAULT)));
+ Predicate<MethodInfo>
isRestAnnotatedInterface = x -> x.getDeclaringClass().isInterface() &&
x.getDeclaringClass().getAnnotation(Rest.class) != null;
+
mi.getMatching(isRestAnnotatedInterface, x -> al.add(AnnotationInfo.of(x,
RestOpAnnotation.DEFAULT)));
}
if (al.size() > 0) {
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/reflect/ExecutableInfoTest.java
b/juneau-utest/src/test/java/org/apache/juneau/reflect/ExecutableInfoTest.java
index 987fe2a..50f058d 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/reflect/ExecutableInfoTest.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/reflect/ExecutableInfoTest.java
@@ -279,12 +279,12 @@ public class ExecutableInfoTest {
@Test
public void getParameterAnnotations() {
- check("", c_c1.getParameterAnnotations());
- check("@CA()", c_c2.getParameterAnnotations());
- check("", c_c3.getParameterAnnotations());
- check("", c_m1.getParameterAnnotations());
- check("@CA()", c_m2.getParameterAnnotations());
- check("", c_m3.getParameterAnnotations());
+ check("", c_c1._getParameterAnnotations());
+ check("@CA()", c_c2._getParameterAnnotations());
+ check("", c_c3._getParameterAnnotations());
+ check("", c_m1._getParameterAnnotations());
+ check("@CA()", c_m2._getParameterAnnotations());
+ check("", c_m3._getParameterAnnotations());
}
@Test
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/reflect/MethodInfoTest.java
b/juneau-utest/src/test/java/org/apache/juneau/reflect/MethodInfoTest.java
index 5cd0651..f82bcf6 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/reflect/MethodInfoTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/reflect/MethodInfoTest.java
@@ -163,7 +163,7 @@ public class MethodInfoTest {
@Test
public void findMatchingMethods() throws Exception {
MethodInfo mi = MethodInfo.of(B3.class.getMethod("foo",
int.class));
- List<Method> l = new ArrayList<>();
+ List<MethodInfo> l = new ArrayList<>();
mi.getMatching(x -> true, x -> l.add(x));
check("B3.foo(int),B2.foo(int),B1.foo(int)", l);
}