From c88877f1c4547c692bee372cd487c22c54ce42e1 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 5 Nov 2015 16:35:20 +0100 Subject: [PATCH] Polishing --- ...liasAwareAnnotationAttributeExtractor.java | 8 +++---- .../MapAnnotationAttributeExtractor.java | 24 +++++++++---------- .../core/type/AnnotationMetadataTests.java | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AbstractAliasAwareAnnotationAttributeExtractor.java b/spring-core/src/main/java/org/springframework/core/annotation/AbstractAliasAwareAnnotationAttributeExtractor.java index 76fc8b6bd31..0febd916c24 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AbstractAliasAwareAnnotationAttributeExtractor.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AbstractAliasAwareAnnotationAttributeExtractor.java @@ -55,8 +55,8 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor implements Anno * of the supplied type; may be {@code null} if unknown * @param source the underlying source of annotation attributes; never {@code null} */ - AbstractAliasAwareAnnotationAttributeExtractor(Class annotationType, - AnnotatedElement annotatedElement, S source) { + AbstractAliasAwareAnnotationAttributeExtractor( + Class annotationType, AnnotatedElement annotatedElement, S source) { Assert.notNull(annotationType, "annotationType must not be null"); Assert.notNull(source, "source must not be null"); @@ -84,12 +84,12 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor implements Anno @Override public final Object getAttributeValue(Method attributeMethod) { - final String attributeName = attributeMethod.getName(); + String attributeName = attributeMethod.getName(); Object attributeValue = getRawAttributeValue(attributeMethod); List aliasNames = this.attributeAliasMap.get(attributeName); if (aliasNames != null) { - final Object defaultValue = AnnotationUtils.getDefaultValue(getAnnotationType(), attributeName); + Object defaultValue = AnnotationUtils.getDefaultValue(getAnnotationType(), attributeName); for (String aliasName : aliasNames) { Object aliasValue = getRawAttributeValue(aliasName); diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MapAnnotationAttributeExtractor.java b/spring-core/src/main/java/org/springframework/core/annotation/MapAnnotationAttributeExtractor.java index aeb2407f5aa..005ae431b3e 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/MapAnnotationAttributeExtractor.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/MapAnnotationAttributeExtractor.java @@ -121,33 +121,33 @@ class MapAnnotationAttributeExtractor extends AbstractAliasAwareAnnotationAttrib // if still null if (attributeValue == null) { throw new IllegalArgumentException(String.format( - "Attributes map [%s] returned null for required attribute [%s] defined by annotation type [%s].", - attributes, attributeName, annotationType.getName())); + "Attributes map [%s] returned null for required attribute [%s] defined by annotation type [%s].", + attributes, attributeName, annotationType.getName())); } // finally, ensure correct type Class requiredReturnType = attributeMethod.getReturnType(); Class actualReturnType = attributeValue.getClass(); + if (!ClassUtils.isAssignable(requiredReturnType, actualReturnType)) { boolean converted = false; // Nested map representing a single annotation? - if (Annotation.class.isAssignableFrom(requiredReturnType) - && Map.class.isAssignableFrom(actualReturnType)) { - - Class nestedAnnotationType = (Class) requiredReturnType; + if (Annotation.class.isAssignableFrom(requiredReturnType) && + Map.class.isAssignableFrom(actualReturnType)) { + Class nestedAnnotationType = + (Class) requiredReturnType; Map map = (Map) attributeValue; attributes.put(attributeName, synthesizeAnnotation(map, nestedAnnotationType, null)); converted = true; } // Nested array of maps representing an array of annotations? - else if (requiredReturnType.isArray() - && Annotation.class.isAssignableFrom(requiredReturnType.getComponentType()) - && actualReturnType.isArray() - && Map.class.isAssignableFrom(actualReturnType.getComponentType())) { - - Class nestedAnnotationType = (Class) requiredReturnType.getComponentType(); + else if (requiredReturnType.isArray() && actualReturnType.isArray() && + Annotation.class.isAssignableFrom(requiredReturnType.getComponentType()) && + Map.class.isAssignableFrom(actualReturnType.getComponentType())) { + Class nestedAnnotationType = + (Class) requiredReturnType.getComponentType(); Map[] maps = (Map[]) attributeValue; attributes.put(attributeName, synthesizeAnnotationArray(maps, nestedAnnotationType)); converted = true; diff --git a/spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java b/spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java index fd59b59f119..5e4083e0fff 100644 --- a/spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java +++ b/spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java @@ -194,7 +194,7 @@ public class AnnotationMetadataTests { private void assertMetaAnnotationOverrides(AnnotationMetadata metadata) { AnnotationAttributes attributes = (AnnotationAttributes) metadata.getAnnotationAttributes( - TestComponentScan.class.getName(), false); + TestComponentScan.class.getName(), false); String[] basePackages = attributes.getStringArray("basePackages"); assertThat("length of basePackages[]", basePackages.length, is(1)); assertThat("basePackages[0]", basePackages[0], is("org.example.componentscan"));