@@ -401,6 +401,7 @@ public static <A extends Annotation> Set<A> getRepeatableAnnotations(AnnotatedEl
401401 */
402402 public static <A extends Annotation > Set <A > getDeclaredRepeatableAnnotations (AnnotatedElement annotatedElement ,
403403 Class <A > annotationType ) {
404+
404405 return getDeclaredRepeatableAnnotations (annotatedElement , annotationType , null );
405406 }
406407
@@ -435,6 +436,7 @@ public static <A extends Annotation> Set<A> getDeclaredRepeatableAnnotations(Ann
435436 */
436437 public static <A extends Annotation > Set <A > getDeclaredRepeatableAnnotations (AnnotatedElement annotatedElement ,
437438 Class <A > annotationType , Class <? extends Annotation > containerAnnotationType ) {
439+
438440 return getRepeatableAnnotations (annotatedElement , annotationType , containerAnnotationType , true );
439441 }
440442
@@ -496,7 +498,7 @@ public static <A extends Annotation> A findAnnotation(AnnotatedElement annotated
496498 // Do NOT store result in the findAnnotationCache since doing so could break
497499 // findAnnotation(Class, Class) and findAnnotation(Method, Class).
498500 return synthesizeAnnotation (findAnnotation (annotatedElement , annotationType , new HashSet <Annotation >()),
499- annotatedElement );
501+ annotatedElement );
500502 }
501503
502504 /**
@@ -957,6 +959,7 @@ public static Map<String, Object> getAnnotationAttributes(Annotation annotation,
957959 */
958960 public static AnnotationAttributes getAnnotationAttributes (Annotation annotation , boolean classValuesAsString ,
959961 boolean nestedAnnotationsAsMap ) {
962+
960963 return getAnnotationAttributes (null , annotation , classValuesAsString , nestedAnnotationsAsMap );
961964 }
962965
@@ -1396,7 +1399,6 @@ public static Annotation[] synthesizeAnnotationArray(Annotation[] annotations, A
13961399 @ SuppressWarnings ("unchecked" )
13971400 static <A extends Annotation > A [] synthesizeAnnotationArray (Map <String , Object >[] maps , Class <A > annotationType ) {
13981401 Assert .notNull (annotationType , "annotationType must not be null" );
1399-
14001402 if (maps == null ) {
14011403 return null ;
14021404 }
@@ -1478,7 +1480,8 @@ private static boolean isSynthesizable(Class<? extends Annotation> annotationTyp
14781480 }
14791481 Class <?> returnType = attribute .getReturnType ();
14801482 if (Annotation [].class .isAssignableFrom (returnType )) {
1481- Class <? extends Annotation > nestedAnnotationType = (Class <? extends Annotation >) returnType .getComponentType ();
1483+ Class <? extends Annotation > nestedAnnotationType =
1484+ (Class <? extends Annotation >) returnType .getComponentType ();
14821485 if (isSynthesizable (nestedAnnotationType )) {
14831486 synthesizable = Boolean .TRUE ;
14841487 break ;
@@ -1512,7 +1515,6 @@ else if (Annotation.class.isAssignableFrom(returnType)) {
15121515 */
15131516 static List <String > getAttributeAliasNames (Method attribute ) {
15141517 Assert .notNull (attribute , "attribute must not be null" );
1515-
15161518 AliasDescriptor descriptor = AliasDescriptor .from (attribute );
15171519 return (descriptor == null ? Collections .<String > emptyList () : descriptor .getAttributeAliasNames ());
15181520 }
@@ -1537,10 +1539,10 @@ static String getAttributeOverrideName(Method attribute, Class<? extends Annotat
15371539 Assert .notNull (attribute , "attribute must not be null" );
15381540 Assert .notNull (metaAnnotationType , "metaAnnotationType must not be null" );
15391541 Assert .isTrue (!Annotation .class .equals (metaAnnotationType ),
1540- "metaAnnotationType must not be java.lang.annotation.Annotation" );
1542+ "metaAnnotationType must not be [ java.lang.annotation.Annotation] " );
15411543
15421544 AliasDescriptor descriptor = AliasDescriptor .from (attribute );
1543- return (descriptor == null ? null : descriptor .getAttributeOverrideName (metaAnnotationType ));
1545+ return (descriptor != null ? descriptor .getAttributeOverrideName (metaAnnotationType ) : null );
15441546 }
15451547
15461548 /**
@@ -1668,10 +1670,10 @@ static void postProcessAnnotationAttributes(AnnotatedElement element, Annotation
16681670 if (valuePresent && aliasPresent ) {
16691671 // Since annotation attributes can be arrays, we must use ObjectUtils.nullSafeEquals().
16701672 if (!ObjectUtils .nullSafeEquals (value , aliasedValue )) {
1671- String elementAsString = (element == null ? "unknown element" : element .toString ());
1672- String msg = String .format ("In AnnotationAttributes for annotation [%s] declared on [%s], "
1673- + "attribute [%s] and its alias [%s] are declared with values of [%s] and [%s], "
1674- + "but only one declaration is permitted." , annotationType .getName (),
1673+ String elementAsString = (element != null ? element .toString () : "unknown element" );
1674+ String msg = String .format ("In AnnotationAttributes for annotation [%s] declared on [%s], " +
1675+ "attribute [%s] and its alias [%s] are declared with values of [%s] and [%s], " +
1676+ "but only one declaration is permitted." , annotationType .getName (),
16751677 elementAsString , attributeName , aliasedAttributeName ,
16761678 ObjectUtils .nullSafeToString (value ), ObjectUtils .nullSafeToString (aliasedValue ));
16771679 throw new AnnotationConfigurationException (msg );
@@ -1680,13 +1682,13 @@ static void postProcessAnnotationAttributes(AnnotatedElement element, Annotation
16801682 else if (aliasPresent ) {
16811683 // Replace value with aliasedValue
16821684 attributes .put (attributeName ,
1683- adaptValue (element , aliasedValue , classValuesAsString , nestedAnnotationsAsMap ));
1685+ adaptValue (element , aliasedValue , classValuesAsString , nestedAnnotationsAsMap ));
16841686 valuesAlreadyReplaced .add (attributeName );
16851687 }
16861688 else {
16871689 // Replace aliasedValue with value
16881690 attributes .put (aliasedAttributeName ,
1689- adaptValue (element , value , classValuesAsString , nestedAnnotationsAsMap ));
1691+ adaptValue (element , value , classValuesAsString , nestedAnnotationsAsMap ));
16901692 valuesAlreadyReplaced .add (aliasedAttributeName );
16911693 }
16921694 }
@@ -1712,7 +1714,7 @@ else if (aliasPresent) {
17121714 * it will be cast to an {@code AnnotationConfigurationException} and thrown,
17131715 * allowing it to propagate to the caller.
17141716 * <p>Otherwise, this method does nothing.
1715- * @param t the throwable to inspect
1717+ * @param ex the throwable to inspect
17161718 * @since 4.2
17171719 */
17181720 static void rethrowAnnotationConfigurationException (Throwable ex ) {
@@ -1874,6 +1876,7 @@ private List<A> getValue(AnnotatedElement element, Annotation annotation) {
18741876 }
18751877 }
18761878
1879+
18771880 /**
18781881 * {@code AliasDescriptor} encapsulates the declaration of {@code @AliasFor}
18791882 * on a given annotation attribute and includes support for validating
@@ -1899,7 +1902,6 @@ private static class AliasDescriptor {
18991902
19001903 private final boolean isAliasPair ;
19011904
1902-
19031905 /**
19041906 * Create an {@code AliasDescriptor} <em>from</em> the declaration
19051907 * of {@code @AliasFor} on the supplied annotation attribute and
@@ -1936,60 +1938,59 @@ private AliasDescriptor(Method sourceAttribute, AliasFor aliasFor) {
19361938 this .sourceAnnotationType = (Class <? extends Annotation >) declaringClass ;
19371939 this .sourceAttributeName = this .sourceAttribute .getName ();
19381940
1939- this .aliasedAnnotationType = (Annotation .class .equals (aliasFor .annotation ()) ? this . sourceAnnotationType
1940- : aliasFor .annotation ());
1941+ this .aliasedAnnotationType = (Annotation .class .equals (aliasFor .annotation ()) ?
1942+ this . sourceAnnotationType : aliasFor .annotation ());
19411943 this .aliasedAttributeName = getAliasedAttributeName (aliasFor , this .sourceAttribute );
19421944 try {
19431945 this .aliasedAttribute = this .aliasedAnnotationType .getDeclaredMethod (this .aliasedAttributeName );
19441946 }
19451947 catch (NoSuchMethodException ex ) {
19461948 String msg = String .format (
1947- "Attribute [%s] in annotation [%s] is declared as an @AliasFor nonexistent attribute [%s] in annotation [%s]." ,
1948- this .sourceAttributeName , this .sourceAnnotationType .getName (), this .aliasedAttributeName ,
1949- this .aliasedAnnotationType .getName ());
1949+ "Attribute [%s] in annotation [%s] is declared as an @AliasFor nonexistent attribute [%s] in annotation [%s]." ,
1950+ this .sourceAttributeName , this .sourceAnnotationType .getName (), this .aliasedAttributeName ,
1951+ this .aliasedAnnotationType .getName ());
19501952 throw new AnnotationConfigurationException (msg , ex );
19511953 }
19521954
19531955 this .isAliasPair = this .sourceAnnotationType .equals (this .aliasedAnnotationType );
19541956 }
19551957
19561958 private void validate () {
1957-
19581959 // Target annotation is not meta-present?
19591960 if (!this .isAliasPair && !isAnnotationMetaPresent (this .sourceAnnotationType , this .aliasedAnnotationType )) {
1960- String msg = String .format ("@AliasFor declaration on attribute [%s] in annotation [%s] declares "
1961- + "an alias for attribute [%s] in meta-annotation [%s] which is not meta-present." ,
1962- this .sourceAttributeName , this .sourceAnnotationType .getName (), this .aliasedAttributeName ,
1963- this .aliasedAnnotationType .getName ());
1961+ String msg = String .format ("@AliasFor declaration on attribute [%s] in annotation [%s] declares " +
1962+ "an alias for attribute [%s] in meta-annotation [%s] which is not meta-present." ,
1963+ this .sourceAttributeName , this .sourceAnnotationType .getName (), this .aliasedAttributeName ,
1964+ this .aliasedAnnotationType .getName ());
19641965 throw new AnnotationConfigurationException (msg );
19651966 }
19661967
19671968 if (this .isAliasPair ) {
19681969 AliasFor mirrorAliasFor = this .aliasedAttribute .getAnnotation (AliasFor .class );
19691970 if (mirrorAliasFor == null ) {
19701971 String msg = String .format (
1971- "Attribute [%s] in annotation [%s] must be declared as an @AliasFor [%s]." ,
1972- this .aliasedAttributeName , this .sourceAnnotationType .getName (), this .sourceAttributeName );
1972+ "Attribute [%s] in annotation [%s] must be declared as an @AliasFor [%s]." ,
1973+ this .aliasedAttributeName , this .sourceAnnotationType .getName (), this .sourceAttributeName );
19731974 throw new AnnotationConfigurationException (msg );
19741975 }
19751976
19761977 String mirrorAliasedAttributeName = getAliasedAttributeName (mirrorAliasFor , this .aliasedAttribute );
19771978 if (!this .sourceAttributeName .equals (mirrorAliasedAttributeName )) {
19781979 String msg = String .format (
1979- "Attribute [%s] in annotation [%s] must be declared as an @AliasFor [%s], not [%s]." ,
1980- this .aliasedAttributeName , this .sourceAnnotationType .getName (), this .sourceAttributeName ,
1981- mirrorAliasedAttributeName );
1980+ "Attribute [%s] in annotation [%s] must be declared as an @AliasFor [%s], not [%s]." ,
1981+ this .aliasedAttributeName , this .sourceAnnotationType .getName (), this .sourceAttributeName ,
1982+ mirrorAliasedAttributeName );
19821983 throw new AnnotationConfigurationException (msg );
19831984 }
19841985 }
19851986
19861987 Class <?> returnType = this .sourceAttribute .getReturnType ();
19871988 Class <?> aliasedReturnType = this .aliasedAttribute .getReturnType ();
19881989 if (!returnType .equals (aliasedReturnType )) {
1989- String msg = String .format ("Misconfigured aliases: attribute [%s] in annotation [%s] "
1990- + "and attribute [%s] in annotation [%s] must declare the same return type." ,
1991- this .sourceAttributeName , this .sourceAnnotationType .getName (), this .aliasedAttributeName ,
1992- this .aliasedAnnotationType .getName ());
1990+ String msg = String .format ("Misconfigured aliases: attribute [%s] in annotation [%s] " +
1991+ "and attribute [%s] in annotation [%s] must declare the same return type." ,
1992+ this .sourceAttributeName , this .sourceAnnotationType .getName (), this .aliasedAttributeName ,
1993+ this .aliasedAnnotationType .getName ());
19931994 throw new AnnotationConfigurationException (msg );
19941995 }
19951996
@@ -2003,19 +2004,19 @@ private void validateDefaultValueConfiguration(Method aliasedAttribute) {
20032004 Object defaultValue = this .sourceAttribute .getDefaultValue ();
20042005 Object aliasedDefaultValue = aliasedAttribute .getDefaultValue ();
20052006
2006- if (( defaultValue == null ) || ( aliasedDefaultValue == null ) ) {
2007- String msg = String .format ("Misconfigured aliases: attribute [%s] in annotation [%s] "
2008- + "and attribute [%s] in annotation [%s] must declare default values." ,
2009- this .sourceAttributeName , this .sourceAnnotationType .getName (), aliasedAttribute .getName (),
2010- aliasedAttribute .getDeclaringClass ().getName ());
2007+ if (defaultValue == null || aliasedDefaultValue == null ) {
2008+ String msg = String .format ("Misconfigured aliases: attribute [%s] in annotation [%s] " +
2009+ "and attribute [%s] in annotation [%s] must declare default values." ,
2010+ this .sourceAttributeName , this .sourceAnnotationType .getName (), aliasedAttribute .getName (),
2011+ aliasedAttribute .getDeclaringClass ().getName ());
20112012 throw new AnnotationConfigurationException (msg );
20122013 }
20132014
20142015 if (!ObjectUtils .nullSafeEquals (defaultValue , aliasedDefaultValue )) {
2015- String msg = String .format ("Misconfigured aliases: attribute [%s] in annotation [%s] "
2016- + "and attribute [%s] in annotation [%s] must declare the same default value." ,
2017- this .sourceAttributeName , this .sourceAnnotationType .getName (), aliasedAttribute .getName (),
2018- aliasedAttribute .getDeclaringClass ().getName ());
2016+ String msg = String .format ("Misconfigured aliases: attribute [%s] in annotation [%s] " +
2017+ "and attribute [%s] in annotation [%s] must declare the same default value." ,
2018+ this .sourceAttributeName , this .sourceAnnotationType .getName (), aliasedAttribute .getName (),
2019+ aliasedAttribute .getDeclaringClass ().getName ());
20192020 throw new AnnotationConfigurationException (msg );
20202021 }
20212022 }
@@ -2094,7 +2095,7 @@ private List<AliasDescriptor> getOtherDescriptors() {
20942095 public String getAttributeOverrideName (Class <? extends Annotation > metaAnnotationType ) {
20952096 Assert .notNull (metaAnnotationType , "metaAnnotationType must not be null" );
20962097 Assert .isTrue (!Annotation .class .equals (metaAnnotationType ),
2097- "metaAnnotationType must not be java.lang.annotation.Annotation" );
2098+ "metaAnnotationType must not be [ java.lang.annotation.Annotation] " );
20982099
20992100 // Search the attribute override hierarchy, starting with the current attribute
21002101 for (AliasDescriptor desc = this ; desc != null ; desc = desc .getAttributeOverrideDescriptor ()) {
@@ -2146,8 +2147,8 @@ private static String getAliasedAttributeName(AliasFor aliasFor, Method attribut
21462147 // Ensure user did not declare both 'value' and 'attribute' in @AliasFor
21472148 if (attributeDeclared && valueDeclared ) {
21482149 throw new AnnotationConfigurationException (String .format (
2149- "In @AliasFor declared on attribute [%s] in annotation [%s], attribute 'attribute' and its alias 'value' "
2150- + " are present with values of [%s] and [%s], but only one is permitted." ,
2150+ "In @AliasFor declared on attribute [%s] in annotation [%s], attribute 'attribute' and its " +
2151+ "alias 'value' are present with values of [%s] and [%s], but only one is permitted." ,
21512152 attribute .getName (), attribute .getDeclaringClass ().getName (), attributeName , value ));
21522153 }
21532154
@@ -2156,8 +2157,8 @@ private static String getAliasedAttributeName(AliasFor aliasFor, Method attribut
21562157 // Ensure user declared either 'value' or 'attribute' in @AliasFor
21572158 if (!StringUtils .hasText (attributeName )) {
21582159 String msg = String .format (
2159- "@AliasFor declaration on attribute [%s] in annotation [%s] is missing required 'attribute' value." ,
2160- attribute .getName (), attribute .getDeclaringClass ().getName ());
2160+ "@AliasFor declaration on attribute [%s] in annotation [%s] is missing required 'attribute' value." ,
2161+ attribute .getName (), attribute .getDeclaringClass ().getName ());
21612162 throw new AnnotationConfigurationException (msg );
21622163 }
21632164
0 commit comments