boolean isFiltered(
+ Class> sourceClass, C context, @Nullable BiPredicate> classFilter) {
+
+ return (classFilter != null && classFilter.test(context, sourceClass));
}
- static boolean isKnownEmpty(AnnotatedElement source,
- SearchStrategy searchStrategy, AnnotationFilter annotationFilter) {
- if (annotationFilter == AnnotationFilter.PLAIN &&
- hasPlainJavaAnnotationsOnly(source)) {
+ static boolean isKnownEmpty(AnnotatedElement source,SearchStrategy searchStrategy, AnnotationFilter annotationFilter) {
+ if (annotationFilter == AnnotationFilter.PLAIN && hasPlainJavaAnnotationsOnly(source)) {
return true;
}
if (searchStrategy == SearchStrategy.DIRECT || isWithoutHierarchy(source)) {
@@ -511,7 +490,7 @@ static boolean isKnownEmpty(AnnotatedElement source,
}
static boolean hasPlainJavaAnnotationsOnly(@Nullable Object annotatedElement) {
- Class> type = null;
+ Class> type;
if (annotatedElement instanceof Class) {
type = (Class>) annotatedElement;
}
@@ -522,11 +501,11 @@ else if (annotatedElement instanceof Member) {
return false;
}
String name = type.getName();
- return type.equals(Ordered.class) ||
+ return (type == Ordered.class ||
name.startsWith("java") ||
name.startsWith("org.springframework.lang.") ||
name.startsWith("org.springframework.util.") ||
- (name.startsWith("com.sun") && !name.contains("Proxy"));
+ (name.startsWith("com.sun") && !name.contains("Proxy")));
}
private static boolean isWithoutHierarchy(AnnotatedElement source) {
@@ -535,13 +514,13 @@ private static boolean isWithoutHierarchy(AnnotatedElement source) {
}
if (source instanceof Class) {
Class> sourceClass = (Class>) source;
- return sourceClass.getSuperclass() == Object.class &&
- sourceClass.getInterfaces().length == 0;
+ return (sourceClass.getSuperclass() == Object.class &&
+ sourceClass.getInterfaces().length == 0);
}
if (source instanceof Method) {
Method sourceMethod = (Method) source;
- return Modifier.isPrivate(sourceMethod.getModifiers()) ||
- isWithoutHierarchy(sourceMethod.getDeclaringClass());
+ return (Modifier.isPrivate(sourceMethod.getModifiers()) ||
+ isWithoutHierarchy(sourceMethod.getDeclaringClass()));
}
return true;
}
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AttributeMethods.java b/spring-core/src/main/java/org/springframework/core/annotation/AttributeMethods.java
index 6f5f9ef53c99..2fd9273eebef 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/AttributeMethods.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/AttributeMethods.java
@@ -48,6 +48,7 @@ final class AttributeMethods {
return m1 != null ? -1 : 1;
};
+
@Nullable
private final Class extends Annotation> annotationType;
@@ -60,8 +61,7 @@ final class AttributeMethods {
private final boolean hasNestedAnnotation;
- private AttributeMethods(@Nullable Class extends Annotation> annotationType,
- Method[] attributeMethods) {
+ private AttributeMethods(@Nullable Class extends Annotation> annotationType, Method[] attributeMethods) {
this.annotationType = annotationType;
this.attributeMethods = attributeMethods;
this.canThrowTypeNotPresentException = new boolean[attributeMethods.length];
@@ -94,8 +94,8 @@ private AttributeMethods(@Nullable Class extends Annotation> annotationType,
* @return {@code true} if this is only a value attribute
*/
boolean isOnlyValueAttribute() {
- return this.attributeMethods.length == 1 &&
- MergedAnnotation.VALUE.equals(this.attributeMethods[0].getName());
+ return (this.attributeMethods.length == 1 &&
+ MergedAnnotation.VALUE.equals(this.attributeMethods[0].getName()));
}
@@ -104,7 +104,7 @@ boolean isOnlyValueAttribute() {
* accessed without causing any {@link TypeNotPresentException
* TypeNotPresentExceptions}.
* @param annotation the annotation to check
- * @return {@true} if all values are present
+ * @return {@code true} if all values are present
* @see #validate(Annotation)
*/
boolean isValid(Annotation annotation) {
@@ -123,14 +123,13 @@ boolean isValid(Annotation annotation) {
}
/**
- * Checks if values from the given annotation can be safely accessed without
- * causing any {@link TypeNotPresentException TypeNotPresentExceptions}. In
- * particular, this method is designed to cover Google App Engine's late
- * arrival of such exceptions for {@code Class} values (instead of the more
- * typical early {@code Class.getAnnotations() failure}.
+ * Checks if values from the given annotation can be safely accessed without causing
+ * any {@link TypeNotPresentException TypeNotPresentExceptions}. In particular,
+ * this method is designed to cover Google App Engine's late arrival of such
+ * exceptions for {@code Class} values (instead of the more typical early
+ * {@code Class.getAnnotations() failure}.
* @param annotation the annotation to validate
- * @throws IllegalStateException if a declared {@code Class} attribute could
- * not be read
+ * @throws IllegalStateException if a declared {@code Class} attribute could not be read
* @see #isValid(Annotation)
*/
void validate(Annotation annotation) {
@@ -141,11 +140,8 @@ void validate(Annotation annotation) {
get(i).invoke(annotation);
}
catch (Throwable ex) {
- throw new IllegalStateException(
- "Could not obtain annotation attribute value for "
- + get(i).getName() + " declared on "
- + annotation.annotationType(),
- ex);
+ throw new IllegalStateException("Could not obtain annotation attribute value for " +
+ get(i).getName() + " declared on " + annotation.annotationType(), ex);
}
}
}
@@ -246,14 +242,13 @@ boolean hasNestedAnnotation() {
return this.hasNestedAnnotation;
}
+
/**
* Return the attribute methods for the given annotation type.
* @param annotationType the annotation type
* @return the attribute methods for the annotation
*/
- static AttributeMethods forAnnotationType(
- @Nullable Class extends Annotation> annotationType) {
-
+ static AttributeMethods forAnnotationType(@Nullable Class extends Annotation> annotationType) {
if (annotationType == null) {
return NONE;
}
@@ -279,7 +274,7 @@ private static AttributeMethods compute(Class extends Annotation> annotationTy
}
private static boolean isAttributeMethod(Method method) {
- return method.getParameterCount() == 0 && method.getReturnType() != void.class;
+ return (method.getParameterCount() == 0 && method.getReturnType() != void.class);
}
/**
@@ -302,14 +297,11 @@ static String describe(@Nullable Method attribute) {
* @param attributeName the attribute name
* @return a description of the attribute
*/
- static String describe(@Nullable Class> annotationType,
- @Nullable String attributeName) {
+ static String describe(@Nullable Class> annotationType, @Nullable String attributeName) {
if (attributeName == null) {
return "(none)";
}
- String in = annotationType != null ?
- " in annotation [" + annotationType.getName() + "]" :
- "";
+ String in = (annotationType != null ? " in annotation [" + annotationType.getName() + "]" : "");
return "attribute '" + attributeName + "'" + in;
}
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/IntrospectionFailureLogger.java b/spring-core/src/main/java/org/springframework/core/annotation/IntrospectionFailureLogger.java
index 08f3f79e4d10..c1c3d4c49072 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/IntrospectionFailureLogger.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/IntrospectionFailureLogger.java
@@ -33,12 +33,10 @@
enum IntrospectionFailureLogger {
DEBUG {
-
@Override
public boolean isEnabled() {
return getLogger().isDebugEnabled();
}
-
@Override
public void log(String message) {
getLogger().debug(message);
@@ -46,12 +44,10 @@ public void log(String message) {
},
INFO {
-
@Override
public boolean isEnabled() {
return getLogger().isInfoEnabled();
}
-
@Override
public void log(String message) {
getLogger().info(message);
@@ -63,15 +59,16 @@ public void log(String message) {
private static Log logger;
- abstract boolean isEnabled();
-
void log(String message, @Nullable Object source, Exception ex) {
- String on = source != null ? " on " + source : "";
+ String on = (source != null ? " on " + source : "");
log(message + on + ": " + ex);
}
+ abstract boolean isEnabled();
+
abstract void log(String message);
+
private static Log getLogger() {
Log logger = IntrospectionFailureLogger.logger;
if (logger == null) {
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java
index 6984b03b846c..7a1265226f56 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java
@@ -40,8 +40,8 @@
* For example, to access an {@code int} attribute the {@link #getInt(String)}
* method would be used.
*
- * Note that attribute values are not converted when accessed. For
- * example, it is not possible to call {@link #getString(String)} if the
+ *
Note that attribute values are not converted when accessed.
+ * For example, it is not possible to call {@link #getString(String)} if the
* underlying attribute is an {@code int}. The only exception to this rule is
* {@code Class} and {@code Class[]} values which may be accessed as
* {@code String} and {@code String[]} respectively to prevent potential early
@@ -63,6 +63,7 @@ public interface MergedAnnotation {
*/
String VALUE = "value";
+
/**
* Return the class name of the actual annotation type.
* @return the annotation type
@@ -342,8 +343,8 @@ > E[] getEnumArray(String attributeName, Class type)
* @return the value as a {@link MergedAnnotation}
* @throws NoSuchElementException if there is no matching attribute
*/
- MergedAnnotation getAnnotation(String attributeName,
- Class type) throws NoSuchElementException;
+ MergedAnnotation getAnnotation(String attributeName, Class type)
+ throws NoSuchElementException;
/**
* Return a required annotation array attribute value from the annotation.
@@ -413,10 +414,9 @@ MergedAnnotation[] getAnnotationArray(String attribute
MergedAnnotation filterAttributes(Predicate predicate);
/**
- * Return a new view of the annotation that exposes non-merged attribute
- * values. Methods from this view will return attribute values with only
- * alias mirroring rules applied. Aliases to parent attributes will not be
- * applied.
+ * Return a new view of the annotation that exposes non-merged attribute values.
+ * Methods from this view will return attribute values with only alias mirroring
+ * rules applied. Aliases to parent attributes will not be applied.
* @return a non-merged view of the annotation
*/
MergedAnnotation withNonMergedAttributes();
@@ -431,9 +431,9 @@ MergedAnnotation[] getAnnotationArray(String attribute
Map asMap(MapValues... options);
/**
- * Return a {@link Map} of the supplied type that contains all the
- * annotation attributes. The {@link MapValues} options may be used to
- * change the way that values are added.
+ * Return a {@link Map} of the supplied type that contains all the annotation
+ * attributes. The {@link MapValues} options may be used to change the way
+ * that values are added.
* @param factory a map factory or {@code null} to return an immutable map.
* @param options map value options
* @return a map containing the attributes and values
@@ -443,22 +443,19 @@ > T asMap(
/**
* Return a type-safe synthesized version of this annotation that can be
- * used directly in code. The result is synthesized using a JDK
- * {@link Proxy} and as a result may incur a computational cost when first
- * invoked.
- * @return a sythesized version of the annotation.
+ * used directly in code. The result is synthesized using a JDK {@link Proxy}
+ * and as a result may incur a computational cost when first invoked.
+ * @return a synthesized version of the annotation.
* @throws NoSuchElementException on a missing annotation
*/
A synthesize() throws NoSuchElementException;
/**
* Optionally return type-safe synthesized version of this annotation based
- * on a condition predicate. The result is synthesized using a JDK
- * {@link Proxy} and as a result may incur a computational cost when first
- * invoked.
- * @param condition the test to determine if the annotation can be
- * sythesized
- * @return a optional containing the sythesized version of the annotation or
+ * on a condition predicate. The result is synthesized using a JDK {@link Proxy}
+ * and as a result may incur a computational cost when first invoked.
+ * @param condition the test to determine if the annotation can be synthesized
+ * @return a optional containing the synthesized version of the annotation or
* an empty optional if the condition doesn't match
* @throws NoSuchElementException on a missing annotation
* @see MergedAnnotationPredicates
@@ -466,6 +463,7 @@ > T asMap(
Optional synthesize(@Nullable Predicate super MergedAnnotation> condition)
throws NoSuchElementException;
+
/**
* Return an {@link MergedAnnotation} that represents a missing annotation
* (i.e. one that is not present).
@@ -494,8 +492,7 @@ static MergedAnnotation from(A annotation) {
* @param annotation the annotation to include
* @return a {@link MergedAnnotation} instance for the annotation
*/
- static MergedAnnotation from(@Nullable Object source,
- A annotation) {
+ static MergedAnnotation from(@Nullable Object source, A annotation) {
return TypeMappedAnnotation.from(source, annotation);
}
@@ -520,8 +517,9 @@ static MergedAnnotation from(Class annotationType)
* attributes
* @see #from(AnnotatedElement, Class, Map)
*/
- static MergedAnnotation from(Class annotationType,
- @Nullable Map attributes) {
+ static MergedAnnotation from(
+ Class annotationType, @Nullable Map attributes) {
+
return from(null, annotationType, attributes);
}
@@ -538,8 +536,8 @@ static MergedAnnotation from(Class annotationType,
* attributes
*/
static MergedAnnotation from(
- @Nullable AnnotatedElement source, Class annotationType,
- @Nullable Map attributes) {
+ @Nullable AnnotatedElement source, Class annotationType, @Nullable Map attributes) {
+
return TypeMappedAnnotation.from(source, annotationType, attributes);
}
@@ -561,7 +559,6 @@ enum MapValues {
*/
ANNOTATION_TO_MAP;
-
protected final boolean isIn(MapValues... options) {
for (MapValues candidate : options) {
if (candidate == this) {
@@ -572,11 +569,9 @@ protected final boolean isIn(MapValues... options) {
}
/**
- * Factory method to create a {@link MapValues} array from a set of
- * boolean flags.
+ * Factory method to create a {@link MapValues} array from a set of boolean flags.
* @param classToString if {@link MapValues#CLASS_TO_STRING} is included
- * @param annotationsToMap if {@link MapValues#ANNOTATION_TO_MAP} is
- * included
+ * @param annotationsToMap if {@link MapValues#ANNOTATION_TO_MAP} is included
* @return a new {@link MapValues} array
*/
public static MapValues[] of(boolean classToString, boolean annotationsToMap) {
@@ -591,7 +586,6 @@ private static void addIfTrue(Set result, T value, boolean test) {
result.add(value);
}
}
-
}
}
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationCollectors.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationCollectors.java
index cf45a40442e5..51d0c09a4e73 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationCollectors.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationCollectors.java
@@ -27,7 +27,6 @@
import java.util.stream.Collector.Characteristics;
import org.springframework.core.annotation.MergedAnnotation.MapValues;
-import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@@ -42,8 +41,7 @@ public abstract class MergedAnnotationCollectors {
private static final Characteristics[] NO_CHARACTERISTICS = {};
- private static final Characteristics[] IDENTITY_FINISH_CHARACTERISTICS = {
- Characteristics.IDENTITY_FINISH };
+ private static final Characteristics[] IDENTITY_FINISH_CHARACTERISTICS = {Characteristics.IDENTITY_FINISH};
private MergedAnnotationCollectors() {
@@ -128,15 +126,14 @@ private MergedAnnotationCollectors() {
Function, MultiValueMap> finisher,
MapValues... options) {
- Assert.notNull(finisher, "Finisher must not be null");
- Characteristics[] characteristics = isSameInstance(finisher, Function.identity()) ?
- IDENTITY_FINISH_CHARACTERISTICS :
- NO_CHARACTERISTICS;
+ Characteristics[] characteristics = (isSameInstance(finisher, Function.identity()) ?
+ IDENTITY_FINISH_CHARACTERISTICS : NO_CHARACTERISTICS);
return Collector.of(LinkedMultiValueMap::new,
(map, annotation) -> annotation.asMap(options).forEach(map::add),
MergedAnnotationCollectors::merge, finisher, characteristics);
}
+
private static boolean isSameInstance(Object instance, Object candidate) {
return instance == candidate;
}
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationPredicates.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationPredicates.java
index 6255729376d0..b341ba31195f 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationPredicates.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationPredicates.java
@@ -49,10 +49,7 @@ private MergedAnnotationPredicates() {
* @param typeNames the names that should be matched
* @return a {@link Predicate} to test the annotation type
*/
- public static Predicate> typeIn(
- String... typeNames) {
-
- Assert.notNull(typeNames, "TypeNames must not be null");
+ public static Predicate> typeIn(String... typeNames) {
return annotation -> ObjectUtils.containsElement(typeNames, annotation.getType());
}
@@ -64,12 +61,8 @@ public static Predicate> ty
* @param types the types that should be matched
* @return a {@link Predicate} to test the annotation type
*/
- public static Predicate> typeIn(
- Class>... types) {
-
- Assert.notNull(types, "Types must not be null");
- return annotation -> Arrays.stream(types)
- .anyMatch(type -> type.getName().equals(annotation.getType()));
+ public static Predicate> typeIn(Class>... types) {
+ return annotation -> Arrays.stream(types).anyMatch(type -> type.getName().equals(annotation.getType()));
}
/**
@@ -80,10 +73,7 @@ public static Predicate> ty
* @param types the type names or classes that should be matched
* @return a {@link Predicate} to test the annotation type
*/
- public static Predicate> typeIn(
- Collection> types) {
-
- Assert.notNull(types, "Types must not be null");
+ public static Predicate> typeIn(Collection> types) {
return annotation -> types.stream()
.map(type -> type instanceof Class ? ((Class>) type).getName() : type.toString())
.anyMatch(typeName -> typeName.equals(annotation.getType()));
@@ -103,7 +93,6 @@ public static Predicate> ty
public static Predicate> firstRunOf(
Function super MergedAnnotation, ?> valueExtractor) {
- Assert.notNull(valueExtractor, "ValueExtractor must not be null");
return new FirstRunOfPredicate<>(valueExtractor);
}
@@ -120,7 +109,6 @@ public static Predicate> firstRunOf(
public static Predicate> unique(
Function super MergedAnnotation, K> keyExtractor) {
- Assert.notNull(keyExtractor, "KeyExtractor must not be null");
return new UniquePredicate<>(keyExtractor);
}
@@ -129,8 +117,7 @@ public static Predicate> unique(
* {@link Predicate} implementation used for
* {@link MergedAnnotationPredicates#firstRunOf(Function)}.
*/
- private static class FirstRunOfPredicate
- implements Predicate> {
+ private static class FirstRunOfPredicate implements Predicate> {
private final Function super MergedAnnotation, ?> valueExtractor;
@@ -139,13 +126,11 @@ private static class FirstRunOfPredicate
@Nullable
private Object lastValue;
-
- FirstRunOfPredicate(
- Function super MergedAnnotation, ?> valueExtractor) {
+ FirstRunOfPredicate(Function super MergedAnnotation, ?> valueExtractor) {
+ Assert.notNull(valueExtractor, "Value extractor must not be null");
this.valueExtractor = valueExtractor;
}
-
@Override
public boolean test(@Nullable MergedAnnotation annotation) {
if (!this.hasLastValue) {
@@ -164,19 +149,17 @@ public boolean test(@Nullable MergedAnnotation annotation) {
* {@link Predicate} implementation used for
* {@link MergedAnnotationPredicates#unique(Function)}.
*/
- private static class UniquePredicate
- implements Predicate> {
+ private static class UniquePredicate implements Predicate> {
private final Function super MergedAnnotation, K> keyExtractor;
private final Set seen = new HashSet<>();
-
UniquePredicate(Function super MergedAnnotation, K> keyExtractor) {
+ Assert.notNull(keyExtractor, "Key extractor must not be null");
this.keyExtractor = keyExtractor;
}
-
@Override
public boolean test(@Nullable MergedAnnotation annotation) {
K key = this.keyExtractor.apply(annotation);
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationSelector.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationSelector.java
index 0aa5c22a4c4f..f3c45c8a379c 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationSelector.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationSelector.java
@@ -47,7 +47,6 @@ default boolean isBestCandidate(MergedAnnotation annotation) {
* @return the most appropriate annotation from the {@code existing} or
* {@code candidate}
*/
- MergedAnnotation select(MergedAnnotation existing,
- MergedAnnotation candidate);
+ MergedAnnotation select(MergedAnnotation existing, MergedAnnotation candidate);
}
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationSelectors.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationSelectors.java
index 8db4efaefdfd..b4fb270714f7 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationSelectors.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationSelectors.java
@@ -70,8 +70,9 @@ public boolean isBestCandidate(MergedAnnotation annotation) {
}
@Override
- public MergedAnnotation select(MergedAnnotation existing,
- MergedAnnotation candidate) {
+ public MergedAnnotation select(
+ MergedAnnotation existing, MergedAnnotation candidate) {
+
if (candidate.getDepth() < existing.getDepth()) {
return candidate;
}
@@ -93,8 +94,9 @@ public boolean isBestCandidate(MergedAnnotation annotation) {
}
@Override
- public MergedAnnotation select(MergedAnnotation existing,
- MergedAnnotation candidate) {
+ public MergedAnnotation select(
+ MergedAnnotation existing, MergedAnnotation candidate) {
+
if (existing.getDepth() > 0 && candidate.getDepth() == 0) {
return candidate;
}
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java
index 8df5091287e6..302aeb201997 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java
@@ -133,7 +133,7 @@ public interface MergedAnnotations extends Iterable
* @param annotationType the annotation type to check
* @return {@code true} if the annotation is present
*/
- boolean isPresent(@Nullable Class annotationType);
+ boolean isPresent(Class annotationType);
/**
* Return if the specified annotation is directly present. Equivalent to
@@ -141,7 +141,7 @@ public interface MergedAnnotations extends Iterable
* @param annotationType the annotation type to check
* @return {@code true} if the annotation is present
*/
- boolean isPresent(@Nullable String annotationType);
+ boolean isPresent(String annotationType);
/**
* Return if the specified annotation is directly present. Equivalent to
@@ -149,7 +149,7 @@ public interface MergedAnnotations extends Iterable
* @param annotationType the annotation type to check
* @return {@code true} if the annotation is present
*/
- boolean isDirectlyPresent(@Nullable Class annotationType);
+ boolean isDirectlyPresent(Class annotationType);
/**
* Return if the specified annotation is either directly present, or
@@ -158,7 +158,7 @@ public interface MergedAnnotations extends Iterable
* @param annotationType the annotation type to check
* @return {@code true} if the annotation is present
*/
- boolean isDirectlyPresent(@Nullable String annotationType);
+ boolean isDirectlyPresent(String annotationType);
/**
* Return the {@link MergedAnnotationSelectors#nearest() nearest} matching
@@ -167,7 +167,7 @@ public interface MergedAnnotations extends Iterable
* @param annotationType the annotation type to get
* @return a {@link MergedAnnotation} instance
*/
- MergedAnnotation get(@Nullable Class annotationType);
+ MergedAnnotation get(Class annotationType);
/**
* Return the {@link MergedAnnotationSelectors#nearest() nearest} matching
@@ -179,7 +179,7 @@ public interface MergedAnnotations extends Iterable
* @return a {@link MergedAnnotation} instance
* @see MergedAnnotationPredicates
*/
- MergedAnnotation get(@Nullable Class annotationType,
+ MergedAnnotation get(Class annotationType,
@Nullable Predicate super MergedAnnotation> predicate);
/**
@@ -195,7 +195,7 @@ MergedAnnotation get(@Nullable Class annotationType
* @see MergedAnnotationPredicates
* @see MergedAnnotationSelectors
*/
- MergedAnnotation get(@Nullable Class annotationType,
+ MergedAnnotation get(Class annotationType,
@Nullable Predicate super MergedAnnotation> predicate,
@Nullable MergedAnnotationSelector selector);
@@ -206,7 +206,7 @@ MergedAnnotation get(@Nullable Class annotationType
* @param annotationType the annotation type to get
* @return a {@link MergedAnnotation} instance
*/
- MergedAnnotation get(@Nullable String annotationType);
+ MergedAnnotation get(String annotationType);
/**
* Return the {@link MergedAnnotationSelectors#nearest() nearest} matching
@@ -218,7 +218,7 @@ MergedAnnotation get(@Nullable Class annotationType
* @return a {@link MergedAnnotation} instance
* @see MergedAnnotationPredicates
*/
- MergedAnnotation get(@Nullable String annotationType,
+ MergedAnnotation get(String annotationType,
@Nullable Predicate super MergedAnnotation> predicate);
/**
@@ -234,7 +234,7 @@ MergedAnnotation get(@Nullable String annotationType,
* @see MergedAnnotationPredicates
* @see MergedAnnotationSelectors
*/
- MergedAnnotation get(@Nullable String annotationType,
+ MergedAnnotation get(String annotationType,
@Nullable Predicate super MergedAnnotation> predicate,
@Nullable MergedAnnotationSelector selector);
@@ -245,8 +245,7 @@ MergedAnnotation get(@Nullable String annotationType,
* @param annotationType the annotation type to match
* @return a stream of matching annotations
*/
- Stream> stream(
- @Nullable Class annotationType);
+ Stream> stream(Class annotationType);
/**
* Stream all annotations and meta-annotations that match the specified
@@ -255,8 +254,7 @@ Stream> stream(
* @param annotationType the annotation type to match
* @return a stream of matching annotations
*/
- Stream> stream(
- @Nullable String annotationType);
+ Stream> stream(String annotationType);
/**
* Stream all contained annotations and meta-annotations contained in this
@@ -269,6 +267,7 @@ Stream> stream(
*/
Stream> stream();
+
/**
* Create a new {@link MergedAnnotations} instance containing all
* annotations and meta-annotations from the specified element. The
@@ -280,7 +279,7 @@ Stream> stream(
* @return a {@link MergedAnnotations} instance containing the element
* annotations
*/
- static MergedAnnotations from(@Nullable AnnotatedElement element) {
+ static MergedAnnotations from(AnnotatedElement element) {
return from(element, SearchStrategy.DIRECT);
}
@@ -293,10 +292,8 @@ static MergedAnnotations from(@Nullable AnnotatedElement element) {
* @return a {@link MergedAnnotations} instance containing the merged
* element annotations
*/
- static MergedAnnotations from(@Nullable AnnotatedElement element,
- SearchStrategy searchStrategy) {
- return from(element, searchStrategy, RepeatableContainers.standardRepeatables(),
- AnnotationFilter.PLAIN);
+ static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStrategy) {
+ return from(element, searchStrategy, RepeatableContainers.standardRepeatables(), AnnotationFilter.PLAIN);
}
/**
@@ -312,11 +309,10 @@ static MergedAnnotations from(@Nullable AnnotatedElement element,
* @return a {@link MergedAnnotations} instance containing the merged
* element annotations
*/
- static MergedAnnotations from(@Nullable AnnotatedElement element,
- SearchStrategy searchStrategy, RepeatableContainers repeatableContainers,
- AnnotationFilter annotationFilter) {
- return TypeMappedAnnotations.from(element, searchStrategy, repeatableContainers,
- annotationFilter);
+ static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStrategy,
+ RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter) {
+
+ return TypeMappedAnnotations.from(element, searchStrategy, repeatableContainers, annotationFilter);
}
/**
@@ -342,8 +338,7 @@ static MergedAnnotations from(Annotation... annotations) {
* @see #from(AnnotatedElement)
*/
static MergedAnnotations from(@Nullable Object source, Annotation... annotations) {
- return from(source, annotations, RepeatableContainers.standardRepeatables(),
- AnnotationFilter.PLAIN);
+ return from(source, annotations, RepeatableContainers.standardRepeatables(), AnnotationFilter.PLAIN);
}
/**
@@ -360,10 +355,9 @@ static MergedAnnotations from(@Nullable Object source, Annotation... annotations
* @return a {@link MergedAnnotations} instance containing the annotations
*/
static MergedAnnotations from(@Nullable Object source, Annotation[] annotations,
- RepeatableContainers repeatableContainers,
- AnnotationFilter annotationFilter) {
- return TypeMappedAnnotations.from(source, annotations, repeatableContainers,
- annotationFilter);
+ RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter) {
+
+ return TypeMappedAnnotations.from(source, annotations, repeatableContainers, annotationFilter);
}
@@ -406,7 +400,6 @@ enum SearchStrategy {
* not need to be meta-annotated with {@link Inherited @Inherited}.
*/
EXHAUSTIVE
-
}
}
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MissingMergedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/MissingMergedAnnotation.java
index 09188b723cf5..255f4434b3b3 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/MissingMergedAnnotation.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/MissingMergedAnnotation.java
@@ -34,8 +34,7 @@
* @since 5.2
* @param the annotation type
*/
-final class MissingMergedAnnotation
- extends AbstractMergedAnnotation {
+final class MissingMergedAnnotation extends AbstractMergedAnnotation {
private static final MissingMergedAnnotation> INSTANCE = new MissingMergedAnnotation<>();
@@ -153,6 +152,7 @@ protected A createSynthesized() {
throw new NoSuchElementException("Unable to synthesize missing annotation");
}
+
@SuppressWarnings("unchecked")
static MergedAnnotation getInstance() {
return (MergedAnnotation) INSTANCE;
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java
index 5064fd386413..000f513d59d7 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java
@@ -92,8 +92,8 @@ public static Integer getOrder(Class> type) {
* @param annotations the annotation to consider
* @return the order value, or {@code null} if none can be found
*/
- static Integer getOrderFromAnnotations(AnnotatedElement element,
- MergedAnnotations annotations) {
+ @Nullable
+ static Integer getOrderFromAnnotations(AnnotatedElement element, MergedAnnotations annotations) {
if (!(element instanceof Class)) {
return findOrder(annotations);
}
@@ -106,6 +106,7 @@ static Integer getOrderFromAnnotations(AnnotatedElement element,
return result;
}
+ @Nullable
private static Integer findOrder(MergedAnnotations annotations) {
MergedAnnotation orderAnnotation = annotations.get(Order.class);
if (orderAnnotation.isPresent()) {
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/PackagesAnnotationFilter.java b/spring-core/src/main/java/org/springframework/core/annotation/PackagesAnnotationFilter.java
index 05f57daf49e9..3b161a6daa9c 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/PackagesAnnotationFilter.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/PackagesAnnotationFilter.java
@@ -29,7 +29,7 @@
* @author Phillip Webb
* @since 5.2
*/
-class PackagesAnnotationFilter implements AnnotationFilter {
+final class PackagesAnnotationFilter implements AnnotationFilter {
private final String[] prefixes;
@@ -40,8 +40,9 @@ class PackagesAnnotationFilter implements AnnotationFilter {
Assert.notNull(packages, "Packages must not be null");
this.prefixes = new String[packages.length];
for (int i = 0; i < packages.length; i++) {
- Assert.hasText(packages[i], "Package must not have empty elements");
- this.prefixes[i] = packages[i] + ".";
+ String pkg = packages[i];
+ Assert.hasText(pkg, "Package must not have empty elements");
+ this.prefixes[i] = pkg + ".";
}
Arrays.sort(this.prefixes);
this.hashCode = Arrays.hashCode(this.prefixes);
@@ -49,27 +50,25 @@ class PackagesAnnotationFilter implements AnnotationFilter {
@Override
- public boolean matches(@Nullable String annotationType) {
- if (annotationType != null) {
- for (String prefix : this.prefixes) {
- if (annotationType.startsWith(prefix)) {
- return true;
- }
+ public boolean matches(String annotationType) {
+ for (String prefix : this.prefixes) {
+ if (annotationType.startsWith(prefix)) {
+ return true;
}
}
return false;
}
+
@Override
- public boolean equals(@Nullable Object obj) {
- if (this == obj) {
+ public boolean equals(@Nullable Object other) {
+ if (this == other) {
return true;
}
- if (obj == null || getClass() != obj.getClass()) {
+ if (other == null || getClass() != other.getClass()) {
return false;
}
- PackagesAnnotationFilter other = (PackagesAnnotationFilter) obj;
- return Arrays.equals(this.prefixes, other.prefixes);
+ return Arrays.equals(this.prefixes, ((PackagesAnnotationFilter) other).prefixes);
}
@Override
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/RepeatableContainers.java b/spring-core/src/main/java/org/springframework/core/annotation/RepeatableContainers.java
index ce4732a62f17..fc609478fc10 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/RepeatableContainers.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/RepeatableContainers.java
@@ -73,16 +73,16 @@ Annotation[] findRepeatedAnnotations(Annotation annotation) {
return this.parent.findRepeatedAnnotations(annotation);
}
+
@Override
- public boolean equals(@Nullable Object obj) {
- if (obj == this) {
+ public boolean equals(@Nullable Object other) {
+ if (other == this) {
return true;
}
- if (obj == null || getClass() != obj.getClass()) {
+ if (other == null || getClass() != other.getClass()) {
return false;
}
- RepeatableContainers other = (RepeatableContainers) obj;
- return Objects.equals(this.parent, other.parent);
+ return Objects.equals(this.parent, ((RepeatableContainers) other).parent);
}
@Override
@@ -90,6 +90,7 @@ public int hashCode() {
return ObjectUtils.nullSafeHashCode(this.parent);
}
+
/**
* Return a {@link RepeatableContainers} instance that searches using Java's
* {@link Repeatable @Repeatable} annotation.
@@ -198,10 +199,8 @@ private static class ExplicitRepeatableContainer extends RepeatableContainers {
private final Method valueMethod;
-
ExplicitRepeatableContainer(@Nullable RepeatableContainers parent,
- Class extends Annotation> repeatable,
- @Nullable Class extends Annotation> container) {
+ Class extends Annotation> repeatable, @Nullable Class extends Annotation> container) {
super(parent);
Assert.notNull(repeatable, "Repeatable must not be null");
@@ -235,11 +234,9 @@ private static class ExplicitRepeatableContainer extends RepeatableContainers {
this.valueMethod = valueMethod;
}
- private Class extends Annotation> deduceContainer(
- Class extends Annotation> repeatable) {
-
+ private Class extends Annotation> deduceContainer(Class extends Annotation> repeatable) {
Repeatable annotation = repeatable.getAnnotation(Repeatable.class);
- Assert.notNull(annotation, "Annotation type must be a repeatable annotation: " +
+ Assert.notNull(annotation, () -> "Annotation type must be a repeatable annotation: " +
"failed to resolve container type for " + repeatable.getName());
return annotation.value();
}
@@ -254,13 +251,12 @@ Annotation[] findRepeatedAnnotations(Annotation annotation) {
}
@Override
- public boolean equals(@Nullable Object obj) {
- if (super.equals(obj)) {
- ExplicitRepeatableContainer other = (ExplicitRepeatableContainer) obj;
- return this.container.equals(other.container) &&
- this.repeatable.equals(other.repeatable);
+ public boolean equals(@Nullable Object other) {
+ if (!super.equals(other)) {
+ return false;
}
- return false;
+ ExplicitRepeatableContainer otherErc = (ExplicitRepeatableContainer) other;
+ return (this.container.equals(otherErc.container) && this.repeatable.equals(otherErc.repeatable));
}
@Override
@@ -270,7 +266,6 @@ public int hashCode() {
hashCode = 31 * hashCode + this.repeatable.hashCode();
return hashCode;
}
-
}
@@ -284,7 +279,6 @@ private static class NoRepeatableContainers extends RepeatableContainers {
NoRepeatableContainers() {
super(null);
}
-
}
}
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java b/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java
index f21b0b32a348..fb6448b5464f 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java
@@ -33,8 +33,8 @@
/**
* {@link InvocationHandler} for an {@link Annotation} that Spring has
- * synthesized (i.e., wrapped in a dynamic proxy) with additional
- * functionality.
+ * synthesized (i.e. wrapped in a dynamic proxy) with additional
+ * functionality such as attribute alias handling.
*
* @author Sam Brannen
* @author Phillip Webb
@@ -44,8 +44,7 @@
* @see AnnotationAttributeExtractor
* @see AnnotationUtils#synthesizeAnnotation(Annotation, AnnotatedElement)
*/
-class SynthesizedMergedAnnotationInvocationHandler
- implements InvocationHandler {
+final class SynthesizedMergedAnnotationInvocationHandler implements InvocationHandler {
private final MergedAnnotation> annotation;
@@ -57,10 +56,8 @@ class SynthesizedMergedAnnotationInvocationHandler
private volatile Integer hashCode;
- private SynthesizedMergedAnnotationInvocationHandler(MergedAnnotation annotation,
- Class type) {
-
- Assert.notNull(annotation, "Annotation must not be null");
+ private SynthesizedMergedAnnotationInvocationHandler(MergedAnnotation annotation, Class type) {
+ Assert.notNull(annotation, "MergedAnnotation must not be null");
Assert.notNull(type, "Type must not be null");
Assert.isTrue(type.isAnnotation(), "Type must be an annotation");
this.annotation = annotation;
@@ -90,18 +87,15 @@ public Object invoke(Object proxy, Method method, Object[] args) {
return getAttributeValue(method);
}
throw new AnnotationConfigurationException(String.format(
- "Method [%s] is unsupported for synthesized annotation type [%s]", method,
- this.type));
+ "Method [%s] is unsupported for synthesized annotation type [%s]", method, this.type));
}
private boolean isAnnotationTypeMethod(Method method) {
- return Objects.equals(method.getName(), "annotationType")
- && method.getParameterCount() == 0;
+ return (Objects.equals(method.getName(), "annotationType") && method.getParameterCount() == 0);
}
/**
- * See {@link Annotation#equals(Object)} for a definition of the required
- * algorithm.
+ * See {@link Annotation#equals(Object)} for a definition of the required algorithm.
* @param other the other object to compare against
*/
private boolean annotationEquals(Object other) {
@@ -123,8 +117,7 @@ private boolean annotationEquals(Object other) {
}
/**
- * See {@link Annotation#hashCode()} for a definition of the required
- * algorithm.
+ * See {@link Annotation#hashCode()} for a definition of the required algorithm.
*/
private int annotationHashCode() {
Integer hashCode = this.hashCode;
@@ -182,26 +175,22 @@ private Object getAttributeValue(Method method) {
String name = method.getName();
Class> type = ClassUtils.resolvePrimitiveIfNecessary(method.getReturnType());
return this.annotation.getValue(name, type).orElseThrow(
- () -> new NoSuchElementException("No value found for attribute named '"
- + name + "' in merged annotation " + this.annotation.getType()));
+ () -> new NoSuchElementException("No value found for attribute named '" + name +
+ "' in merged annotation " + this.annotation.getType()));
}
@SuppressWarnings("unchecked")
- static A createProxy(MergedAnnotation annotation,
- Class type) {
+ static A createProxy(MergedAnnotation annotation, Class type) {
ClassLoader classLoader = type.getClassLoader();
- InvocationHandler handler = new SynthesizedMergedAnnotationInvocationHandler<>(
- annotation, type);
- Class>[] interfaces = isVisible(classLoader, SynthesizedAnnotation.class)
- ? new Class>[] { type, SynthesizedAnnotation.class }
- : new Class>[] { type };
+ InvocationHandler handler = new SynthesizedMergedAnnotationInvocationHandler<>(annotation, type);
+ Class>[] interfaces = isVisible(classLoader, SynthesizedAnnotation.class) ?
+ new Class>[] {type, SynthesizedAnnotation.class} : new Class>[] {type};
return (A) Proxy.newProxyInstance(classLoader, interfaces, handler);
}
private static boolean isVisible(ClassLoader classLoader, Class> interfaceClass) {
try {
- return Class.forName(interfaceClass.getName(), false,
- classLoader) == interfaceClass;
+ return Class.forName(interfaceClass.getName(), false, classLoader) == interfaceClass;
}
catch (ClassNotFoundException ex) {
return false;
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java
index 3eaef51cb72f..c20e89b61c88 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java
@@ -190,13 +190,12 @@ public boolean hasDefaultValue(String attributeName) {
@Override
@SuppressWarnings("unchecked")
- public MergedAnnotation getAnnotation(String attributeName,
- Class type) throws NoSuchElementException {
+ public MergedAnnotation getAnnotation(String attributeName, Class type)
+ throws NoSuchElementException {
- Assert.notNull(attributeName, "AttributeName must not be null");
- Assert.notNull(type, "Type must not be null");
int attributeIndex = getAttributeIndex(attributeName, true);
Method attribute = this.mapping.getAttributes().get(attributeIndex);
+ Assert.notNull(type, "Type must not be null");
Assert.isAssignable(type, attribute.getReturnType(),
"Attribute " + attributeName + " type mismatch:");
return (MergedAnnotation) getRequiredValue(attributeIndex, Object.class);
@@ -207,13 +206,12 @@ public MergedAnnotation getAnnotation(String attribute
public MergedAnnotation[] getAnnotationArray(
String attributeName, Class type) throws NoSuchElementException {
- Assert.notNull(attributeName, "AttributeName must not be null");
- Assert.notNull(type, "Type must not be null");
int attributeIndex = getAttributeIndex(attributeName, true);
Method attribute = this.mapping.getAttributes().get(attributeIndex);
Class> componentType = attribute.getReturnType().getComponentType();
+ Assert.notNull(type, "Type must not be null");
Assert.notNull(componentType, () -> "Attribute " + attributeName + " is not an array");
- Assert.isAssignable(type, componentType, "Attribute " + attributeName + " component type mismatch:");
+ Assert.isAssignable(type, componentType, () -> "Attribute " + attributeName + " component type mismatch:");
return (MergedAnnotation[]) getRequiredValue(attributeIndex, Object.class);
}
@@ -229,7 +227,6 @@ public Optional getDefaultValue(String attributeName, Class type) {
@Override
public MergedAnnotation filterAttributes(Predicate predicate) {
- Assert.notNull(predicate, "Predicate must not be null");
if (this.attributeFilter != null) {
predicate = this.attributeFilter.and(predicate);
}
@@ -250,9 +247,8 @@ public MergedAnnotation withNonMergedAttributes() {
public > T asMap(
@Nullable Function, T> factory, MapValues... options) {
- T map = factory != null ? factory.apply(this) : (T) new LinkedHashMap();
- Assert.state(map != null,
- "Factory used to create MergedAnnotation Map must not return null;");
+ T map = (factory != null ? factory.apply(this) : (T) new LinkedHashMap());
+ Assert.state(map != null, "Factory used to create MergedAnnotation Map must not return null");
AttributeMethods attributes = this.mapping.getAttributes();
for (int i = 0; i < attributes.size(); i++) {
Method attribute = attributes.get(i);
@@ -361,14 +357,13 @@ private Object toString(@Nullable Object value) {
@Nullable
protected T getAttributeValue(String attributeName, Class type) {
int attributeIndex = getAttributeIndex(attributeName, false);
- return attributeIndex != -1 ? getValue(attributeIndex, type) : null;
+ return (attributeIndex != -1 ? getValue(attributeIndex, type) : null);
}
protected final T getRequiredValue(int attributeIndex, Class type) {
T value = getValue(attributeIndex, type);
if (value == null) {
- throw new NoSuchElementException(
- "No element at attribute index " + attributeIndex);
+ throw new NoSuchElementException("No element at attribute index " + attributeIndex);
}
return value;
}
@@ -457,8 +452,7 @@ else if (value instanceof MergedAnnotation && type.isAnnotation()) {
MergedAnnotation> annotation = (MergedAnnotation>) value;
value = annotation.synthesize();
}
- else if (value instanceof MergedAnnotation[] && type.isArray()
- && type.getComponentType().isAnnotation()) {
+ else if (value instanceof MergedAnnotation[] && type.isArray() && type.getComponentType().isAnnotation()) {
MergedAnnotation>[] annotations = (MergedAnnotation>[]) value;
Object array = Array.newInstance(type.getComponentType(), annotations.length);
for (int i = 0; i < annotations.length; i++) {
@@ -484,8 +478,7 @@ private Object adaptForAttribute(Method attribute, Object value) {
if (attributeType.isAnnotation()) {
return adaptToMergedAnnotation(value,(Class extends Annotation>) attributeType);
}
- if (attributeType.isArray() &&
- attributeType.getComponentType().isAnnotation() &&
+ if (attributeType.isArray() && attributeType.getComponentType().isAnnotation() &&
value.getClass().isArray()) {
MergedAnnotation>[] result = new MergedAnnotation>[Array.getLength(value)];
for (int i = 0; i < result.length; i++) {
@@ -539,10 +532,9 @@ private Class> getDefaultAdaptType(Method attribute) {
}
private int getAttributeIndex(String attributeName, boolean required) {
- Assert.hasText(attributeName, "AttributeName must not be null");
- int attributeIndex = isFiltered(attributeName) ?
- -1 :
- this.mapping.getAttributes().indexOf(attributeName);
+ Assert.hasText(attributeName, "Attribute name must not be null");
+ int attributeIndex = (isFiltered(attributeName) ? -1 :
+ this.mapping.getAttributes().indexOf(attributeName));
if (attributeIndex == -1 && required) {
throw new NoSuchElementException("No attribute named '" + attributeName +
"' present in merged annotation " + getType());
@@ -562,20 +554,16 @@ private Class getAnnotationType() {
return (Class) this.mapping.getAnnotationType();
}
- static MergedAnnotation from(@Nullable Object source,
- A annotation) {
-
+ static MergedAnnotation from(@Nullable Object source, A annotation) {
Assert.notNull(annotation, "Annotation must not be null");
- AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(
- annotation.annotationType());
- return new TypeMappedAnnotation<>(mappings.get(0), source, annotation,
- ReflectionUtils::invokeMethod, 0);
+ AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(annotation.annotationType());
+ return new TypeMappedAnnotation<>(mappings.get(0), source, annotation, ReflectionUtils::invokeMethod, 0);
}
static MergedAnnotation from(@Nullable Object source,
Class annotationType, @Nullable Map attributes) {
- Assert.notNull(annotationType, "AnnotationType must not be null");
+ Assert.notNull(annotationType, "Annotation type must not be null");
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(annotationType);
return new TypeMappedAnnotation<>(mappings.get(0), source, attributes,
TypeMappedAnnotation::extractFromMap, 0);
@@ -596,9 +584,8 @@ static TypeMappedAnnotation createIfPossible(
}
if (logger.isEnabled()) {
String type = mapping.getAnnotationType().getName();
- String item = mapping.getDepth() == 0 ?
- "annotation " + type :
- "meta-annotation " + type + " from " + mapping.getRoot().getAnnotationType().getName();
+ String item = (mapping.getDepth() == 0 ? "annotation " + type :
+ "meta-annotation " + type + " from " + mapping.getRoot().getAnnotationType().getName());
logger.log("Failed to introspect " + item, source, ex);
}
return null;
@@ -608,7 +595,7 @@ static TypeMappedAnnotation createIfPossible(
@SuppressWarnings("unchecked")
@Nullable
private static Object extractFromMap(Method attribute, @Nullable Object map) {
- return map != null ? ((Map) map).get(attribute.getName()) : null;
+ return (map != null ? ((Map) map).get(attribute.getName()) : null);
}
}
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotations.java b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotations.java
index 4225edf0a6c4..7b2cddbfca7d 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotations.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotations.java
@@ -36,14 +36,14 @@
* annotations and meta-annotations using {@link AnnotationTypeMappings}.
*
* @author Phillip Webb
- * @since 5.1
+ * @since 5.2
*/
final class TypeMappedAnnotations implements MergedAnnotations {
private static final AnnotationFilter FILTER_ALL = annotationType -> true;
- private static final MergedAnnotations NONE = new TypeMappedAnnotations(null,
- new Annotation[0], RepeatableContainers.none(), FILTER_ALL);
+ private static final MergedAnnotations NONE = new TypeMappedAnnotations(
+ null, new Annotation[0], RepeatableContainers.none(), FILTER_ALL);
@Nullable
@@ -67,8 +67,7 @@ final class TypeMappedAnnotations implements MergedAnnotations {
private TypeMappedAnnotations(AnnotatedElement element, SearchStrategy searchStrategy,
- RepeatableContainers repeatableContainers,
- AnnotationFilter annotationFilter) {
+ RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter) {
this.source = element;
this.element = element;
@@ -79,8 +78,7 @@ private TypeMappedAnnotations(AnnotatedElement element, SearchStrategy searchStr
}
private TypeMappedAnnotations(@Nullable Object source, Annotation[] annotations,
- RepeatableContainers repeatableContainers,
- AnnotationFilter annotationFilter) {
+ RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter) {
this.source = source;
this.element = null;
@@ -92,8 +90,8 @@ private TypeMappedAnnotations(@Nullable Object source, Annotation[] annotations,
@Override
- public boolean isPresent(@Nullable Class annotationType) {
- if (annotationType == null || this.annotationFilter.matches(annotationType)) {
+ public boolean isPresent(Class annotationType) {
+ if (this.annotationFilter.matches(annotationType)) {
return false;
}
return Boolean.TRUE.equals(scan(annotationType,
@@ -101,8 +99,8 @@ public boolean isPresent(@Nullable Class annotationTyp
}
@Override
- public boolean isPresent(@Nullable String annotationType) {
- if (annotationType == null || this.annotationFilter.matches(annotationType)) {
+ public boolean isPresent(String annotationType) {
+ if (this.annotationFilter.matches(annotationType)) {
return false;
}
return Boolean.TRUE.equals(scan(annotationType,
@@ -119,8 +117,8 @@ public boolean isDirectlyPresent(@Nullable Class annot
}
@Override
- public boolean isDirectlyPresent(@Nullable String annotationType) {
- if (annotationType == null || this.annotationFilter.matches(annotationType)) {
+ public boolean isDirectlyPresent(String annotationType) {
+ if (this.annotationFilter.matches(annotationType)) {
return false;
}
return Boolean.TRUE.equals(scan(annotationType,
@@ -128,57 +126,53 @@ public boolean isDirectlyPresent(@Nullable String annotationType) {
}
@Override
- public MergedAnnotation get(
- @Nullable Class annotationType) {
-
+ public MergedAnnotation get(Class annotationType) {
return get(annotationType, null, null);
}
@Override
- public MergedAnnotation get(
- @Nullable Class annotationType,
+ public MergedAnnotation get(Class annotationType,
@Nullable Predicate super MergedAnnotation> predicate) {
return get(annotationType, predicate, null);
}
@Override
- public MergedAnnotation get(
- @Nullable Class annotationType,
+ public MergedAnnotation get(Class annotationType,
@Nullable Predicate super MergedAnnotation> predicate,
@Nullable MergedAnnotationSelector selector) {
- if (annotationType == null || this.annotationFilter.matches(annotationType)) {
+ if (this.annotationFilter.matches(annotationType)) {
return MergedAnnotation.missing();
}
MergedAnnotation result = scan(annotationType,
new MergedAnnotationFinder<>(annotationType, predicate, selector));
- return result != null ? result : MergedAnnotation.missing();
+ return (result != null ? result : MergedAnnotation.missing());
}
@Override
- public MergedAnnotation get(
- @Nullable String annotationType) {
+ public MergedAnnotation get(String annotationType) {
return get(annotationType, null, null);
}
@Override
- public MergedAnnotation get(@Nullable String annotationType,
+ public MergedAnnotation get(String annotationType,
@Nullable Predicate super MergedAnnotation> predicate) {
+
return get(annotationType, predicate, null);
}
@Override
- public MergedAnnotation get(@Nullable String annotationType,
+ public MergedAnnotation get(String annotationType,
@Nullable Predicate super MergedAnnotation> predicate,
@Nullable MergedAnnotationSelector selector) {
- if (annotationType == null || this.annotationFilter.matches(annotationType)) {
+ if (this.annotationFilter.matches(annotationType)) {
return MergedAnnotation.missing();
}
MergedAnnotation result = scan(annotationType,
new MergedAnnotationFinder<>(annotationType, predicate, selector));
- return result != null ? result : MergedAnnotation.missing();
+ return (result != null ? result : MergedAnnotation.missing());
}
@Override
@@ -261,13 +255,11 @@ static MergedAnnotations from(@Nullable AnnotatedElement element,
if (element == null || AnnotationsScanner.isKnownEmpty(element, searchStrategy, annotationFilter)) {
return NONE;
}
- return new TypeMappedAnnotations(element, searchStrategy, repeatableContainers,
- annotationFilter);
+ return new TypeMappedAnnotations(element, searchStrategy, repeatableContainers, annotationFilter);
}
- static MergedAnnotations from(@Nullable Object source,
- Annotation[] annotations, RepeatableContainers repeatableContainers,
- AnnotationFilter annotationFilter) {
+ static MergedAnnotations from(@Nullable Object source, Annotation[] annotations,
+ RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter) {
if (annotations.length == 0) {
return NONE;
@@ -282,8 +274,8 @@ private static boolean isMappingForType(@Nullable AnnotationTypeMapping mapping,
return false;
}
Class extends Annotation> actualType = mapping.getAnnotationType();
- return !annotationFilter.matches(actualType) &&
- (requiredType == null || actualType == requiredType || actualType.getName().equals(requiredType));
+ return (!annotationFilter.matches(actualType) &&
+ (requiredType == null || actualType == requiredType || actualType.getName().equals(requiredType)));
}
@@ -291,8 +283,7 @@ private static boolean isMappingForType(@Nullable AnnotationTypeMapping mapping,
* {@link AnnotationsProcessor} used to detect if an annotation is directly
* or meta-present.
*/
- private static final class IsPresent
- implements AnnotationsProcessor