@@ -401,6 +401,7 @@ public static <A extends Annotation> Set<A> getRepeatableAnnotations(AnnotatedEl
401
401
*/
402
402
public static <A extends Annotation > Set <A > getDeclaredRepeatableAnnotations (AnnotatedElement annotatedElement ,
403
403
Class <A > annotationType ) {
404
+
404
405
return getDeclaredRepeatableAnnotations (annotatedElement , annotationType , null );
405
406
}
406
407
@@ -435,6 +436,7 @@ public static <A extends Annotation> Set<A> getDeclaredRepeatableAnnotations(Ann
435
436
*/
436
437
public static <A extends Annotation > Set <A > getDeclaredRepeatableAnnotations (AnnotatedElement annotatedElement ,
437
438
Class <A > annotationType , Class <? extends Annotation > containerAnnotationType ) {
439
+
438
440
return getRepeatableAnnotations (annotatedElement , annotationType , containerAnnotationType , true );
439
441
}
440
442
@@ -496,7 +498,7 @@ public static <A extends Annotation> A findAnnotation(AnnotatedElement annotated
496
498
// Do NOT store result in the findAnnotationCache since doing so could break
497
499
// findAnnotation(Class, Class) and findAnnotation(Method, Class).
498
500
return synthesizeAnnotation (findAnnotation (annotatedElement , annotationType , new HashSet <Annotation >()),
499
- annotatedElement );
501
+ annotatedElement );
500
502
}
501
503
502
504
/**
@@ -957,6 +959,7 @@ public static Map<String, Object> getAnnotationAttributes(Annotation annotation,
957
959
*/
958
960
public static AnnotationAttributes getAnnotationAttributes (Annotation annotation , boolean classValuesAsString ,
959
961
boolean nestedAnnotationsAsMap ) {
962
+
960
963
return getAnnotationAttributes (null , annotation , classValuesAsString , nestedAnnotationsAsMap );
961
964
}
962
965
@@ -1396,7 +1399,6 @@ public static Annotation[] synthesizeAnnotationArray(Annotation[] annotations, A
1396
1399
@ SuppressWarnings ("unchecked" )
1397
1400
static <A extends Annotation > A [] synthesizeAnnotationArray (Map <String , Object >[] maps , Class <A > annotationType ) {
1398
1401
Assert .notNull (annotationType , "annotationType must not be null" );
1399
-
1400
1402
if (maps == null ) {
1401
1403
return null ;
1402
1404
}
@@ -1478,7 +1480,8 @@ private static boolean isSynthesizable(Class<? extends Annotation> annotationTyp
1478
1480
}
1479
1481
Class <?> returnType = attribute .getReturnType ();
1480
1482
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 ();
1482
1485
if (isSynthesizable (nestedAnnotationType )) {
1483
1486
synthesizable = Boolean .TRUE ;
1484
1487
break ;
@@ -1512,7 +1515,6 @@ else if (Annotation.class.isAssignableFrom(returnType)) {
1512
1515
*/
1513
1516
static List <String > getAttributeAliasNames (Method attribute ) {
1514
1517
Assert .notNull (attribute , "attribute must not be null" );
1515
-
1516
1518
AliasDescriptor descriptor = AliasDescriptor .from (attribute );
1517
1519
return (descriptor == null ? Collections .<String > emptyList () : descriptor .getAttributeAliasNames ());
1518
1520
}
@@ -1537,10 +1539,10 @@ static String getAttributeOverrideName(Method attribute, Class<? extends Annotat
1537
1539
Assert .notNull (attribute , "attribute must not be null" );
1538
1540
Assert .notNull (metaAnnotationType , "metaAnnotationType must not be null" );
1539
1541
Assert .isTrue (!Annotation .class .equals (metaAnnotationType ),
1540
- "metaAnnotationType must not be java.lang.annotation.Annotation" );
1542
+ "metaAnnotationType must not be [ java.lang.annotation.Annotation] " );
1541
1543
1542
1544
AliasDescriptor descriptor = AliasDescriptor .from (attribute );
1543
- return (descriptor == null ? null : descriptor .getAttributeOverrideName (metaAnnotationType ));
1545
+ return (descriptor != null ? descriptor .getAttributeOverrideName (metaAnnotationType ) : null );
1544
1546
}
1545
1547
1546
1548
/**
@@ -1668,10 +1670,10 @@ static void postProcessAnnotationAttributes(AnnotatedElement element, Annotation
1668
1670
if (valuePresent && aliasPresent ) {
1669
1671
// Since annotation attributes can be arrays, we must use ObjectUtils.nullSafeEquals().
1670
1672
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 (),
1675
1677
elementAsString , attributeName , aliasedAttributeName ,
1676
1678
ObjectUtils .nullSafeToString (value ), ObjectUtils .nullSafeToString (aliasedValue ));
1677
1679
throw new AnnotationConfigurationException (msg );
@@ -1680,13 +1682,13 @@ static void postProcessAnnotationAttributes(AnnotatedElement element, Annotation
1680
1682
else if (aliasPresent ) {
1681
1683
// Replace value with aliasedValue
1682
1684
attributes .put (attributeName ,
1683
- adaptValue (element , aliasedValue , classValuesAsString , nestedAnnotationsAsMap ));
1685
+ adaptValue (element , aliasedValue , classValuesAsString , nestedAnnotationsAsMap ));
1684
1686
valuesAlreadyReplaced .add (attributeName );
1685
1687
}
1686
1688
else {
1687
1689
// Replace aliasedValue with value
1688
1690
attributes .put (aliasedAttributeName ,
1689
- adaptValue (element , value , classValuesAsString , nestedAnnotationsAsMap ));
1691
+ adaptValue (element , value , classValuesAsString , nestedAnnotationsAsMap ));
1690
1692
valuesAlreadyReplaced .add (aliasedAttributeName );
1691
1693
}
1692
1694
}
@@ -1712,7 +1714,7 @@ else if (aliasPresent) {
1712
1714
* it will be cast to an {@code AnnotationConfigurationException} and thrown,
1713
1715
* allowing it to propagate to the caller.
1714
1716
* <p>Otherwise, this method does nothing.
1715
- * @param t the throwable to inspect
1717
+ * @param ex the throwable to inspect
1716
1718
* @since 4.2
1717
1719
*/
1718
1720
static void rethrowAnnotationConfigurationException (Throwable ex ) {
@@ -1874,6 +1876,7 @@ private List<A> getValue(AnnotatedElement element, Annotation annotation) {
1874
1876
}
1875
1877
}
1876
1878
1879
+
1877
1880
/**
1878
1881
* {@code AliasDescriptor} encapsulates the declaration of {@code @AliasFor}
1879
1882
* on a given annotation attribute and includes support for validating
@@ -1899,7 +1902,6 @@ private static class AliasDescriptor {
1899
1902
1900
1903
private final boolean isAliasPair ;
1901
1904
1902
-
1903
1905
/**
1904
1906
* Create an {@code AliasDescriptor} <em>from</em> the declaration
1905
1907
* of {@code @AliasFor} on the supplied annotation attribute and
@@ -1936,60 +1938,59 @@ private AliasDescriptor(Method sourceAttribute, AliasFor aliasFor) {
1936
1938
this .sourceAnnotationType = (Class <? extends Annotation >) declaringClass ;
1937
1939
this .sourceAttributeName = this .sourceAttribute .getName ();
1938
1940
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 ());
1941
1943
this .aliasedAttributeName = getAliasedAttributeName (aliasFor , this .sourceAttribute );
1942
1944
try {
1943
1945
this .aliasedAttribute = this .aliasedAnnotationType .getDeclaredMethod (this .aliasedAttributeName );
1944
1946
}
1945
1947
catch (NoSuchMethodException ex ) {
1946
1948
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 ());
1950
1952
throw new AnnotationConfigurationException (msg , ex );
1951
1953
}
1952
1954
1953
1955
this .isAliasPair = this .sourceAnnotationType .equals (this .aliasedAnnotationType );
1954
1956
}
1955
1957
1956
1958
private void validate () {
1957
-
1958
1959
// Target annotation is not meta-present?
1959
1960
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 ());
1964
1965
throw new AnnotationConfigurationException (msg );
1965
1966
}
1966
1967
1967
1968
if (this .isAliasPair ) {
1968
1969
AliasFor mirrorAliasFor = this .aliasedAttribute .getAnnotation (AliasFor .class );
1969
1970
if (mirrorAliasFor == null ) {
1970
1971
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 );
1973
1974
throw new AnnotationConfigurationException (msg );
1974
1975
}
1975
1976
1976
1977
String mirrorAliasedAttributeName = getAliasedAttributeName (mirrorAliasFor , this .aliasedAttribute );
1977
1978
if (!this .sourceAttributeName .equals (mirrorAliasedAttributeName )) {
1978
1979
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 );
1982
1983
throw new AnnotationConfigurationException (msg );
1983
1984
}
1984
1985
}
1985
1986
1986
1987
Class <?> returnType = this .sourceAttribute .getReturnType ();
1987
1988
Class <?> aliasedReturnType = this .aliasedAttribute .getReturnType ();
1988
1989
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 ());
1993
1994
throw new AnnotationConfigurationException (msg );
1994
1995
}
1995
1996
@@ -2003,19 +2004,19 @@ private void validateDefaultValueConfiguration(Method aliasedAttribute) {
2003
2004
Object defaultValue = this .sourceAttribute .getDefaultValue ();
2004
2005
Object aliasedDefaultValue = aliasedAttribute .getDefaultValue ();
2005
2006
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 ());
2011
2012
throw new AnnotationConfigurationException (msg );
2012
2013
}
2013
2014
2014
2015
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 ());
2019
2020
throw new AnnotationConfigurationException (msg );
2020
2021
}
2021
2022
}
@@ -2094,7 +2095,7 @@ private List<AliasDescriptor> getOtherDescriptors() {
2094
2095
public String getAttributeOverrideName (Class <? extends Annotation > metaAnnotationType ) {
2095
2096
Assert .notNull (metaAnnotationType , "metaAnnotationType must not be null" );
2096
2097
Assert .isTrue (!Annotation .class .equals (metaAnnotationType ),
2097
- "metaAnnotationType must not be java.lang.annotation.Annotation" );
2098
+ "metaAnnotationType must not be [ java.lang.annotation.Annotation] " );
2098
2099
2099
2100
// Search the attribute override hierarchy, starting with the current attribute
2100
2101
for (AliasDescriptor desc = this ; desc != null ; desc = desc .getAttributeOverrideDescriptor ()) {
@@ -2146,8 +2147,8 @@ private static String getAliasedAttributeName(AliasFor aliasFor, Method attribut
2146
2147
// Ensure user did not declare both 'value' and 'attribute' in @AliasFor
2147
2148
if (attributeDeclared && valueDeclared ) {
2148
2149
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." ,
2151
2152
attribute .getName (), attribute .getDeclaringClass ().getName (), attributeName , value ));
2152
2153
}
2153
2154
@@ -2156,8 +2157,8 @@ private static String getAliasedAttributeName(AliasFor aliasFor, Method attribut
2156
2157
// Ensure user declared either 'value' or 'attribute' in @AliasFor
2157
2158
if (!StringUtils .hasText (attributeName )) {
2158
2159
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 ());
2161
2162
throw new AnnotationConfigurationException (msg );
2162
2163
}
2163
2164
0 commit comments