提交 42e7ade1 编写于 作者: J Juergen Hoeller

Tolerate unidirectional alias declaration for annotation attribute pair

Closes gh-23834
上级 dba7bf7e
...@@ -27,7 +27,6 @@ import java.util.HashSet; ...@@ -27,7 +27,6 @@ import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.function.BiFunction; import java.util.function.BiFunction;
...@@ -179,30 +178,25 @@ final class AnnotationTypeMapping { ...@@ -179,30 +178,25 @@ final class AnnotationTypeMapping {
} }
if (isAliasPair(target) && checkAliasPair) { if (isAliasPair(target) && checkAliasPair) {
AliasFor targetAliasFor = target.getAnnotation(AliasFor.class); AliasFor targetAliasFor = target.getAnnotation(AliasFor.class);
if (targetAliasFor == null) { if (targetAliasFor != null) {
throw new AnnotationConfigurationException(String.format( Method mirror = resolveAliasTarget(target, targetAliasFor, false);
"%s must be declared as an @AliasFor '%s'.", if (!mirror.equals(attribute)) {
StringUtils.capitalize(AttributeMethods.describe(target)), throw new AnnotationConfigurationException(String.format(
attribute.getName())); "%s must be declared as an @AliasFor '%s', not '%s'.",
} StringUtils.capitalize(AttributeMethods.describe(target)),
Method mirror = resolveAliasTarget(target, targetAliasFor, false); attribute.getName(), mirror.getName()));
if (!mirror.equals(attribute)) { }
throw new AnnotationConfigurationException(String.format(
"%s must be declared as an @AliasFor '%s', not '%s'.",
StringUtils.capitalize(AttributeMethods.describe(target)),
attribute.getName(), mirror.getName()));
} }
} }
return target; return target;
} }
private boolean isAliasPair(Method target) { private boolean isAliasPair(Method target) {
return target.getDeclaringClass().equals(this.annotationType); return (this.annotationType == target.getDeclaringClass());
} }
private boolean isCompatibleReturnType(Class<?> attributeType, Class<?> targetType) { private boolean isCompatibleReturnType(Class<?> attributeType, Class<?> targetType) {
return Objects.equals(attributeType, targetType) || return (attributeType == targetType || attributeType == targetType.getComponentType());
Objects.equals(attributeType, targetType.getComponentType());
} }
private void processAliases() { private void processAliases() {
......
...@@ -1200,7 +1200,7 @@ class AnnotatedElementUtilsTests { ...@@ -1200,7 +1200,7 @@ class AnnotatedElementUtilsTests {
@AliasFor("basePackages") @AliasFor("basePackages")
String[] value() default {}; String[] value() default {};
@AliasFor("value") // Intentionally no alias declaration for "value"
String[] basePackages() default {}; String[] basePackages() default {};
Filter[] excludeFilters() default {}; Filter[] excludeFilters() default {};
...@@ -1485,7 +1485,7 @@ class AnnotatedElementUtilsTests { ...@@ -1485,7 +1485,7 @@ class AnnotatedElementUtilsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface ValueAttribute { @interface ValueAttribute {
String[] value(); String[] value();
...@@ -1493,7 +1493,7 @@ class AnnotatedElementUtilsTests { ...@@ -1493,7 +1493,7 @@ class AnnotatedElementUtilsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ValueAttribute("FromValueAttributeMeta") @ValueAttribute("FromValueAttributeMeta")
static @interface ValueAttributeMeta { @interface ValueAttributeMeta {
@AliasFor("alias") @AliasFor("alias")
String[] value() default {}; String[] value() default {};
...@@ -1505,7 +1505,7 @@ class AnnotatedElementUtilsTests { ...@@ -1505,7 +1505,7 @@ class AnnotatedElementUtilsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ValueAttributeMeta("FromValueAttributeMetaMeta") @ValueAttributeMeta("FromValueAttributeMetaMeta")
static @interface ValueAttributeMetaMeta { @interface ValueAttributeMetaMeta {
} }
@ValueAttributeMetaMeta @ValueAttributeMetaMeta
......
...@@ -158,15 +158,6 @@ class AnnotationTypeMappingsTests { ...@@ -158,15 +158,6 @@ class AnnotationTypeMappingsTests {
+ "] must declare the same return type."); + "] must declare the same return type.");
} }
@Test
void forAnnotationTypeWhenAliasForToSelfNonAnnotatedAttribute() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForToSelfNonAnnotatedAttribute.class))
.withMessage("Attribute 'other' in annotation ["
+ AliasForToSelfNonAnnotatedAttribute.class.getName()
+ "] must be declared as an @AliasFor 'test'.");
}
@Test @Test
void forAnnotationTypeWhenAliasForToSelfAnnotatedToOtherAttribute() { void forAnnotationTypeWhenAliasForToSelfAnnotatedToOtherAttribute() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
...@@ -554,67 +545,67 @@ class AnnotationTypeMappingsTests { ...@@ -554,67 +545,67 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface SimpleAnnotation { @interface SimpleAnnotation {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Inherited @Inherited
@UsesSunMisc @UsesSunMisc
static @interface WithSpringLangAnnotation { @interface WithSpringLangAnnotation {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@A @A
@B @B
static @interface MetaAnnotated { @interface MetaAnnotated {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@AA @AA
@AB @AB
static @interface A { @interface A {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AA { @interface AA {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ABC @ABC
static @interface AB { @interface AB {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface ABC { @interface ABC {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface B { @interface B {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Repeating @Repeating
@Repeating @Repeating
static @interface WithRepeatedMetaAnnotations { @interface WithRepeatedMetaAnnotations {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Repeatable(Repeatings.class) @Repeatable(Repeatings.class)
static @interface Repeating { @interface Repeating {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface Repeatings { @interface Repeatings {
Repeating[] value(); Repeating[] value();
...@@ -622,24 +613,24 @@ class AnnotationTypeMappingsTests { ...@@ -622,24 +613,24 @@ class AnnotationTypeMappingsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@SelfAnnotated @SelfAnnotated
static @interface SelfAnnotated { @interface SelfAnnotated {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@LoopB @LoopB
static @interface LoopA { @interface LoopA {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@LoopA @LoopA
static @interface LoopB { @interface LoopB {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasForWithBothValueAndAttribute { @interface AliasForWithBothValueAndAttribute {
@AliasFor(value = "bar", attribute = "foo") @AliasFor(value = "bar", attribute = "foo")
String test(); String test();
...@@ -647,7 +638,7 @@ class AnnotationTypeMappingsTests { ...@@ -647,7 +638,7 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasForToSelfNonExistingAttribute { @interface AliasForToSelfNonExistingAttribute {
@AliasFor("missing") @AliasFor("missing")
String test() default ""; String test() default "";
...@@ -658,7 +649,7 @@ class AnnotationTypeMappingsTests { ...@@ -658,7 +649,7 @@ class AnnotationTypeMappingsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@AliasForToOtherNonExistingAttributeTarget @AliasForToOtherNonExistingAttributeTarget
static @interface AliasForToOtherNonExistingAttribute { @interface AliasForToOtherNonExistingAttribute {
@AliasFor(annotation = AliasForToOtherNonExistingAttributeTarget.class, attribute = "missing") @AliasFor(annotation = AliasForToOtherNonExistingAttributeTarget.class, attribute = "missing")
String test() default ""; String test() default "";
...@@ -666,14 +657,14 @@ class AnnotationTypeMappingsTests { ...@@ -666,14 +657,14 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasForToOtherNonExistingAttributeTarget { @interface AliasForToOtherNonExistingAttributeTarget {
String other() default ""; String other() default "";
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasForToSelf { @interface AliasForToSelf {
@AliasFor("test") @AliasFor("test")
String test() default ""; String test() default "";
...@@ -682,7 +673,7 @@ class AnnotationTypeMappingsTests { ...@@ -682,7 +673,7 @@ class AnnotationTypeMappingsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@AliasForWithArrayCompatibleReturnTypesTarget @AliasForWithArrayCompatibleReturnTypesTarget
static @interface AliasForWithArrayCompatibleReturnTypes { @interface AliasForWithArrayCompatibleReturnTypes {
@AliasFor(annotation = AliasForWithArrayCompatibleReturnTypesTarget.class) @AliasFor(annotation = AliasForWithArrayCompatibleReturnTypesTarget.class)
String test() default ""; String test() default "";
...@@ -690,14 +681,14 @@ class AnnotationTypeMappingsTests { ...@@ -690,14 +681,14 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasForWithArrayCompatibleReturnTypesTarget { @interface AliasForWithArrayCompatibleReturnTypesTarget {
String[] test() default {}; String[] test() default {};
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasForWithIncompatibleReturnTypes { @interface AliasForWithIncompatibleReturnTypes {
@AliasFor(annotation = AliasForWithIncompatibleReturnTypesTarget.class) @AliasFor(annotation = AliasForWithIncompatibleReturnTypesTarget.class)
String[] test() default {}; String[] test() default {};
...@@ -705,24 +696,14 @@ class AnnotationTypeMappingsTests { ...@@ -705,24 +696,14 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasForWithIncompatibleReturnTypesTarget { @interface AliasForWithIncompatibleReturnTypesTarget {
String test() default "";
}
@Retention(RetentionPolicy.RUNTIME)
static @interface AliasForToSelfNonAnnotatedAttribute {
@AliasFor("other")
String test() default ""; String test() default "";
String other() default "";
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasForToSelfAnnotatedToOtherAttribute { @interface AliasForToSelfAnnotatedToOtherAttribute {
@AliasFor("b") @AliasFor("b")
String a() default ""; String a() default "";
...@@ -736,7 +717,7 @@ class AnnotationTypeMappingsTests { ...@@ -736,7 +717,7 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasForNonMetaAnnotated { @interface AliasForNonMetaAnnotated {
@AliasFor(annotation = AliasForNonMetaAnnotatedTarget.class) @AliasFor(annotation = AliasForNonMetaAnnotatedTarget.class)
String test() default ""; String test() default "";
...@@ -744,14 +725,14 @@ class AnnotationTypeMappingsTests { ...@@ -744,14 +725,14 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasForNonMetaAnnotatedTarget { @interface AliasForNonMetaAnnotatedTarget {
String test() default ""; String test() default "";
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasForSelfWithDifferentDefaults { @interface AliasForSelfWithDifferentDefaults {
@AliasFor("b") @AliasFor("b")
String a() default "a"; String a() default "a";
...@@ -762,7 +743,7 @@ class AnnotationTypeMappingsTests { ...@@ -762,7 +743,7 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasForSelfWithMissingDefault { @interface AliasForSelfWithMissingDefault {
@AliasFor("b") @AliasFor("b")
String a() default "a"; String a() default "a";
...@@ -774,7 +755,7 @@ class AnnotationTypeMappingsTests { ...@@ -774,7 +755,7 @@ class AnnotationTypeMappingsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@AliasWithExplicitMirrorAndDifferentDefaultsTarget @AliasWithExplicitMirrorAndDifferentDefaultsTarget
static @interface AliasWithExplicitMirrorAndDifferentDefaults { @interface AliasWithExplicitMirrorAndDifferentDefaults {
@AliasFor(annotation = AliasWithExplicitMirrorAndDifferentDefaultsTarget.class, attribute = "a") @AliasFor(annotation = AliasWithExplicitMirrorAndDifferentDefaultsTarget.class, attribute = "a")
String a() default "x"; String a() default "x";
...@@ -788,7 +769,7 @@ class AnnotationTypeMappingsTests { ...@@ -788,7 +769,7 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasWithExplicitMirrorAndDifferentDefaultsTarget { @interface AliasWithExplicitMirrorAndDifferentDefaultsTarget {
String a() default ""; String a() default "";
...@@ -796,7 +777,7 @@ class AnnotationTypeMappingsTests { ...@@ -796,7 +777,7 @@ class AnnotationTypeMappingsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@MappedTarget @MappedTarget
static @interface Mapped { @interface Mapped {
String convention() default ""; String convention() default "";
...@@ -806,7 +787,7 @@ class AnnotationTypeMappingsTests { ...@@ -806,7 +787,7 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface MappedTarget { @interface MappedTarget {
String convention() default ""; String convention() default "";
...@@ -815,7 +796,7 @@ class AnnotationTypeMappingsTests { ...@@ -815,7 +796,7 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface AliasPair { @interface AliasPair {
@AliasFor("b") @AliasFor("b")
String a() default ""; String a() default "";
...@@ -827,7 +808,7 @@ class AnnotationTypeMappingsTests { ...@@ -827,7 +808,7 @@ class AnnotationTypeMappingsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ImplicitMirrorsTarget @ImplicitMirrorsTarget
static @interface ImplicitMirrors { @interface ImplicitMirrors {
@AliasFor(annotation = ImplicitMirrorsTarget.class, attribute = "c") @AliasFor(annotation = ImplicitMirrorsTarget.class, attribute = "c")
String a() default ""; String a() default "";
...@@ -838,7 +819,7 @@ class AnnotationTypeMappingsTests { ...@@ -838,7 +819,7 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface ImplicitMirrorsTarget { @interface ImplicitMirrorsTarget {
@AliasFor("d") @AliasFor("d")
String c() default ""; String c() default "";
...@@ -850,7 +831,7 @@ class AnnotationTypeMappingsTests { ...@@ -850,7 +831,7 @@ class AnnotationTypeMappingsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ThreeDeepB @ThreeDeepB
static @interface ThreeDeepA { @interface ThreeDeepA {
@AliasFor(annotation = ThreeDeepB.class, attribute = "b1") @AliasFor(annotation = ThreeDeepB.class, attribute = "b1")
String a1() default ""; String a1() default "";
...@@ -871,7 +852,7 @@ class AnnotationTypeMappingsTests { ...@@ -871,7 +852,7 @@ class AnnotationTypeMappingsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ThreeDeepC @ThreeDeepC
static @interface ThreeDeepB { @interface ThreeDeepB {
@AliasFor(annotation = ThreeDeepC.class, attribute = "c1") @AliasFor(annotation = ThreeDeepC.class, attribute = "c1")
String b1() default ""; String b1() default "";
...@@ -882,7 +863,7 @@ class AnnotationTypeMappingsTests { ...@@ -882,7 +863,7 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface ThreeDeepC { @interface ThreeDeepC {
String c1() default ""; String c1() default "";
...@@ -892,7 +873,7 @@ class AnnotationTypeMappingsTests { ...@@ -892,7 +873,7 @@ class AnnotationTypeMappingsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@DefinedAttributesTarget(a = "test") @DefinedAttributesTarget(a = "test")
static @interface DefinedAttributes { @interface DefinedAttributes {
@AliasFor(annotation = DefinedAttributesTarget.class, attribute = "b") @AliasFor(annotation = DefinedAttributesTarget.class, attribute = "b")
String value(); String value();
...@@ -900,7 +881,7 @@ class AnnotationTypeMappingsTests { ...@@ -900,7 +881,7 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface DefinedAttributesTarget { @interface DefinedAttributesTarget {
String a(); String a();
...@@ -935,7 +916,7 @@ class AnnotationTypeMappingsTests { ...@@ -935,7 +916,7 @@ class AnnotationTypeMappingsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@MulipleRoutesToAliasB @MulipleRoutesToAliasB
static @interface MulipleRoutesToAliasA { @interface MulipleRoutesToAliasA {
@AliasFor(annotation = MulipleRoutesToAliasB.class, attribute = "b2") @AliasFor(annotation = MulipleRoutesToAliasB.class, attribute = "b2")
String a1() default ""; String a1() default "";
...@@ -944,7 +925,7 @@ class AnnotationTypeMappingsTests { ...@@ -944,7 +925,7 @@ class AnnotationTypeMappingsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@MulipleRoutesToAliasC @MulipleRoutesToAliasC
static @interface MulipleRoutesToAliasB { @interface MulipleRoutesToAliasB {
@AliasFor(annotation = MulipleRoutesToAliasC.class, attribute = "c2") @AliasFor(annotation = MulipleRoutesToAliasC.class, attribute = "c2")
String b1() default ""; String b1() default "";
...@@ -958,7 +939,7 @@ class AnnotationTypeMappingsTests { ...@@ -958,7 +939,7 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface MulipleRoutesToAliasC { @interface MulipleRoutesToAliasC {
@AliasFor("c2") @AliasFor("c2")
String c1() default ""; String c1() default "";
...@@ -970,14 +951,14 @@ class AnnotationTypeMappingsTests { ...@@ -970,14 +951,14 @@ class AnnotationTypeMappingsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ConventionToExplicitAliasesTarget @ConventionToExplicitAliasesTarget
static @interface ConventionToExplicitAliases { @interface ConventionToExplicitAliases {
String test() default ""; String test() default "";
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface ConventionToExplicitAliasesTarget { @interface ConventionToExplicitAliasesTarget {
@AliasFor("test") @AliasFor("test")
String value() default ""; String value() default "";
...@@ -988,28 +969,28 @@ class AnnotationTypeMappingsTests { ...@@ -988,28 +969,28 @@ class AnnotationTypeMappingsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface ClassValue { @interface ClassValue {
Class<?> value(); Class<?> value();
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface ClassValueWithDefault { @interface ClassValueWithDefault {
Class<?> value() default InputStream.class; Class<?> value() default InputStream.class;
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface ClassArrayValueWithDefault { @interface ClassArrayValueWithDefault {
Class<?>[] value() default { InputStream.class, OutputStream.class }; Class<?>[] value() default { InputStream.class, OutputStream.class };
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface NestedValue { @interface NestedValue {
ClassValue value() default @ClassValue(InputStream.class); ClassValue value() default @ClassValue(InputStream.class);
......
...@@ -556,16 +556,6 @@ class AnnotationUtilsTests { ...@@ -556,16 +556,6 @@ class AnnotationUtilsTests {
assertThat(values).isEqualTo(asList("A", "B", "C", "meta1")); assertThat(values).isEqualTo(asList("A", "B", "C", "meta1"));
} }
@Test
void getRepeatableAnnotationsDeclaredOnClassWithMissingAttributeAliasDeclaration() throws Exception {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
getRepeatableAnnotations(BrokenConfigHierarchyTestCase.class, BrokenContextConfig.class, BrokenHierarchy.class))
.withMessageStartingWith("Attribute 'value' in")
.withMessageContaining(BrokenContextConfig.class.getName())
.withMessageContaining("@AliasFor 'location'");
}
@Test @Test
void getRepeatableAnnotationsDeclaredOnClassWithAttributeAliases() { void getRepeatableAnnotationsDeclaredOnClassWithAttributeAliases() {
final List<String> expectedLocations = asList("A", "B"); final List<String> expectedLocations = asList("A", "B");
...@@ -1415,17 +1405,6 @@ class AnnotationUtilsTests { ...@@ -1415,17 +1405,6 @@ class AnnotationUtilsTests {
Class<?> klass() default Object.class; Class<?> klass() default Object.class;
} }
@Retention(RetentionPolicy.RUNTIME)
@interface BrokenContextConfig {
// Intentionally missing:
// @AliasFor("location")
String value() default "";
@AliasFor("value")
String location() default "";
}
/** /**
* Mock of {@code org.springframework.test.context.ContextHierarchy}. * Mock of {@code org.springframework.test.context.ContextHierarchy}.
*/ */
...@@ -1434,19 +1413,10 @@ class AnnotationUtilsTests { ...@@ -1434,19 +1413,10 @@ class AnnotationUtilsTests {
ContextConfig[] value(); ContextConfig[] value();
} }
@Retention(RetentionPolicy.RUNTIME)
@interface BrokenHierarchy {
BrokenContextConfig[] value();
}
@Hierarchy({@ContextConfig("A"), @ContextConfig(location = "B")}) @Hierarchy({@ContextConfig("A"), @ContextConfig(location = "B")})
static class ConfigHierarchyTestCase { static class ConfigHierarchyTestCase {
} }
@BrokenHierarchy(@BrokenContextConfig)
static class BrokenConfigHierarchyTestCase {
}
@ContextConfig("simple.xml") @ContextConfig("simple.xml")
static class SimpleConfigTestCase { static class SimpleConfigTestCase {
} }
...@@ -1825,13 +1795,13 @@ class AnnotationUtilsTests { ...@@ -1825,13 +1795,13 @@ class AnnotationUtilsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Repeatable(TestRepeatableContainer.class) @Repeatable(TestRepeatableContainer.class)
static @interface TestRepeatable { @interface TestRepeatable {
String value(); String value();
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface TestRepeatableContainer { @interface TestRepeatableContainer {
TestRepeatable[] value(); TestRepeatable[] value();
} }
......
...@@ -1308,18 +1308,6 @@ class MergedAnnotationsTests { ...@@ -1308,18 +1308,6 @@ class MergedAnnotationsTests {
assertThat(values).containsExactly("A", "B", "C", "meta1"); assertThat(values).containsExactly("A", "B", "C", "meta1");
} }
@Test
void getRepeatableDeclaredOnClassWithMissingAttributeAliasDeclaration() {
RepeatableContainers containers = RepeatableContainers.of(
BrokenContextConfiguration.class, BrokenHierarchy.class);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotations.from(BrokenHierarchyClass.class, SearchStrategy.TYPE_HIERARCHY, containers,
AnnotationFilter.PLAIN).get(BrokenHierarchy.class))
.withMessageStartingWith("Attribute 'value' in")
.withMessageContaining(BrokenContextConfiguration.class.getName())
.withMessageContaining("@AliasFor 'location'");
}
@Test @Test
void getRepeatableDeclaredOnClassWithAttributeAliases() { void getRepeatableDeclaredOnClassWithAttributeAliases() {
assertThat(MergedAnnotations.from(HierarchyClass.class).stream( assertThat(MergedAnnotations.from(HierarchyClass.class).stream(
...@@ -1329,8 +1317,7 @@ class MergedAnnotationsTests { ...@@ -1329,8 +1317,7 @@ class MergedAnnotationsTests {
MergedAnnotations annotations = MergedAnnotations.from(HierarchyClass.class, MergedAnnotations annotations = MergedAnnotations.from(HierarchyClass.class,
SearchStrategy.DIRECT, containers, AnnotationFilter.NONE); SearchStrategy.DIRECT, containers, AnnotationFilter.NONE);
assertThat(annotations.stream(TestConfiguration.class).map( assertThat(annotations.stream(TestConfiguration.class).map(
annotation -> annotation.getString("location"))).containsExactly("A", annotation -> annotation.getString("location"))).containsExactly("A", "B");
"B");
assertThat(annotations.stream(TestConfiguration.class).map( assertThat(annotations.stream(TestConfiguration.class).map(
annotation -> annotation.getString("value"))).containsExactly("A", "B"); annotation -> annotation.getString("value"))).containsExactly("A", "B");
} }
...@@ -1488,17 +1475,6 @@ class MergedAnnotationsTests { ...@@ -1488,17 +1475,6 @@ class MergedAnnotationsTests {
.withMessageContaining("declares an alias for 'bar' which is not present"); .withMessageContaining("declares an alias for 'bar' which is not present");
} }
@Test
void synthesizeWhenAttributeAliasWithoutMirroredAliasFor() throws Exception {
AliasForWithoutMirroredAliasFor annotation = AliasForWithoutMirroredAliasForClass.class.getAnnotation(
AliasForWithoutMirroredAliasFor.class);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(annotation))
.withMessageStartingWith("Attribute 'bar' in")
.withMessageContaining(AliasForWithoutMirroredAliasFor.class.getName())
.withMessageContaining("@AliasFor 'foo'");
}
@Test @Test
void synthesizeWhenAttributeAliasWithMirroredAliasForWrongAttribute() void synthesizeWhenAttributeAliasWithMirroredAliasForWrongAttribute()
throws Exception { throws Exception {
...@@ -3055,15 +3031,6 @@ class MergedAnnotationsTests { ...@@ -3055,15 +3031,6 @@ class MergedAnnotationsTests {
} }
} }
@Retention(RetentionPolicy.RUNTIME)
@interface BrokenContextConfiguration {
String value() default "";
@AliasFor("value")
String location() default "";
}
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@interface TestConfiguration { @interface TestConfiguration {
...@@ -3082,20 +3049,10 @@ class MergedAnnotationsTests { ...@@ -3082,20 +3049,10 @@ class MergedAnnotationsTests {
TestConfiguration[] value(); TestConfiguration[] value();
} }
@Retention(RetentionPolicy.RUNTIME)
@interface BrokenHierarchy {
BrokenContextConfiguration[] value();
}
@Hierarchy({ @TestConfiguration("A"), @TestConfiguration(location = "B") }) @Hierarchy({ @TestConfiguration("A"), @TestConfiguration(location = "B") })
static class HierarchyClass { static class HierarchyClass {
} }
@BrokenHierarchy(@BrokenContextConfiguration)
static class BrokenHierarchyClass {
}
@TestConfiguration("simple.xml") @TestConfiguration("simple.xml")
static class TestConfigurationClass { static class TestConfigurationClass {
} }
...@@ -3544,7 +3501,7 @@ class MergedAnnotationsTests { ...@@ -3544,7 +3501,7 @@ class MergedAnnotationsTests {
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
static @interface ValueAttribute { @interface ValueAttribute {
String[] value(); String[] value();
...@@ -3552,7 +3509,7 @@ class MergedAnnotationsTests { ...@@ -3552,7 +3509,7 @@ class MergedAnnotationsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ValueAttribute("FromValueAttributeMeta") @ValueAttribute("FromValueAttributeMeta")
static @interface ValueAttributeMeta { @interface ValueAttributeMeta {
String[] value() default {}; String[] value() default {};
...@@ -3560,7 +3517,7 @@ class MergedAnnotationsTests { ...@@ -3560,7 +3517,7 @@ class MergedAnnotationsTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ValueAttributeMeta("FromValueAttributeMetaMeta") @ValueAttributeMeta("FromValueAttributeMetaMeta")
static @interface ValueAttributeMetaMeta { @interface ValueAttributeMetaMeta {
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册