From d5974a18abb8ee62b05833f3bff45c5bee468e65 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 24 May 2015 15:53:50 +0200 Subject: [PATCH] Polish AnnotationUtils --- .../core/annotation/AnnotationUtils.java | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 2dc5947c0bc..419d6ddbe79 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -118,7 +118,7 @@ public abstract class AnnotationUtils { private static final Map, Boolean> synthesizableCache = new ConcurrentReferenceHashMap, Boolean>(256); - private static final Map, Map> attributeAliasCache = + private static final Map, Map> attributeAliasesCache = new ConcurrentReferenceHashMap, Map>(256); private static transient Log logger; @@ -437,11 +437,11 @@ public abstract class AnnotationUtils { } static boolean isInterfaceWithAnnotatedMethods(Class iface) { - Boolean flag = annotatedInterfaceCache.get(iface); - if (flag != null) { - return flag.booleanValue(); + Boolean found = annotatedInterfaceCache.get(iface); + if (found != null) { + return found.booleanValue(); } - Boolean found = Boolean.FALSE; + found = Boolean.FALSE; for (Method ifcMethod : iface.getMethods()) { try { if (ifcMethod.getAnnotations().length > 0) { @@ -831,14 +831,12 @@ public abstract class AnnotationUtils { for (Method method : getAttributeMethods(annotationType)) { try { Object value = method.invoke(annotation); - Object defaultValue = method.getDefaultValue(); if (defaultValuesAsPlaceholder && (defaultValue != null)) { if (ObjectUtils.nullSafeEquals(value, defaultValue)) { value = DEFAULT_VALUE_PLACEHOLDER; } } - attrs.put(method.getName(), adaptValue(annotatedElement, value, classValuesAsString, nestedAnnotationsAsMap)); } @@ -1090,12 +1088,12 @@ public abstract class AnnotationUtils { return Collections.emptyMap(); } - Map cachedMap = attributeAliasCache.get(annotationType); - if (cachedMap != null) { - return cachedMap; + Map map = attributeAliasesCache.get(annotationType); + if (map != null) { + return map; } - Map map = new HashMap(); + map = new HashMap(); for (Method attribute : getAttributeMethods(annotationType)) { String attributeName = attribute.getName(); String aliasedAttributeName = getAliasedAttributeName(attribute); @@ -1104,7 +1102,7 @@ public abstract class AnnotationUtils { } } - attributeAliasCache.put(annotationType, map); + attributeAliasesCache.put(annotationType, map); return map; } @@ -1127,12 +1125,12 @@ public abstract class AnnotationUtils { @SuppressWarnings("unchecked") private static boolean isSynthesizable(Class annotationType) { - Boolean flag = synthesizableCache.get(annotationType); - if (flag != null) { - return flag.booleanValue(); + Boolean synthesizable = synthesizableCache.get(annotationType); + if (synthesizable != null) { + return synthesizable.booleanValue(); } - Boolean synthesizable = Boolean.FALSE; + synthesizable = Boolean.FALSE; for (Method attribute : getAttributeMethods(annotationType)) { if (getAliasedAttributeName(attribute) != null) { @@ -1306,7 +1304,8 @@ public abstract class AnnotationUtils { *

All methods in the returned list will be * {@linkplain ReflectionUtils#makeAccessible(Method) made accessible}. * - * @param annotationType the type in which to search for attribute methods + * @param annotationType the type in which to search for attribute methods; + * never {@code null} * @return all annotation attribute methods in the specified annotation * type; never {@code null}, though potentially empty * @since 4.2