|
24 | 24 | import java.lang.annotation.RetentionPolicy;
|
25 | 25 | import java.lang.annotation.Target;
|
26 | 26 | import java.lang.reflect.AnnotatedElement;
|
| 27 | +import java.lang.reflect.Field; |
27 | 28 | import java.lang.reflect.Method;
|
28 | 29 | import java.util.ArrayList;
|
29 | 30 | import java.util.Arrays;
|
@@ -1420,7 +1421,28 @@ void synthesizeShouldNotSynthesizeNonsynthesizableAnnotations() throws Exception
|
1420 | 1421 | assertThat(generatedValue).isSameAs(synthesizedGeneratedValue);
|
1421 | 1422 | }
|
1422 | 1423 |
|
1423 |
| - @Test |
| 1424 | + @Test // gh-28716 |
| 1425 | + void synthesizeWhenUsingMergedAnnotationsFromApi() { |
| 1426 | + Field directlyAnnotatedField = ReflectionUtils.findField(DomainType.class, "directlyAnnotated"); |
| 1427 | + MergedAnnotations mergedAnnotations = MergedAnnotations.from(directlyAnnotatedField); |
| 1428 | + RootAnnotation rootAnnotation = mergedAnnotations.get(RootAnnotation.class).synthesize(); |
| 1429 | + assertThat(rootAnnotation.flag()).isFalse(); |
| 1430 | + assertThat(rootAnnotation).isNotInstanceOf(SynthesizedAnnotation.class); |
| 1431 | + |
| 1432 | + Field metaAnnotatedField = ReflectionUtils.findField(DomainType.class, "metaAnnotated"); |
| 1433 | + mergedAnnotations = MergedAnnotations.from(metaAnnotatedField); |
| 1434 | + rootAnnotation = mergedAnnotations.get(RootAnnotation.class).synthesize(); |
| 1435 | + assertThat(rootAnnotation.flag()).isTrue(); |
| 1436 | + assertThat(rootAnnotation).isInstanceOf(SynthesizedAnnotation.class); |
| 1437 | + |
| 1438 | + Field metaMetaAnnotatedField = ReflectionUtils.findField(DomainType.class, "metaMetaAnnotated"); |
| 1439 | + mergedAnnotations = MergedAnnotations.from(metaMetaAnnotatedField); |
| 1440 | + rootAnnotation = mergedAnnotations.get(RootAnnotation.class).synthesize(); |
| 1441 | + assertThat(rootAnnotation.flag()).isTrue(); |
| 1442 | + assertThat(rootAnnotation).isInstanceOf(SynthesizedAnnotation.class); |
| 1443 | + } |
| 1444 | + |
| 1445 | + @Test // gh-28704 |
1424 | 1446 | void synthesizeShouldNotSynthesizeNonsynthesizableAnnotationsWhenUsingMergedAnnotationsFromApi() {
|
1425 | 1447 | MergedAnnotations mergedAnnotations = MergedAnnotations.from(SecurityConfig.class);
|
1426 | 1448 |
|
@@ -3127,6 +3149,40 @@ private Long getId() {
|
3127 | 3149 | static class SecurityConfig {
|
3128 | 3150 | }
|
3129 | 3151 |
|
| 3152 | + @Retention(RetentionPolicy.RUNTIME) |
| 3153 | + @Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE }) |
| 3154 | + @interface RootAnnotation { |
| 3155 | + String value() default ""; |
| 3156 | + boolean flag() default false; |
| 3157 | + } |
| 3158 | + |
| 3159 | + @RootAnnotation |
| 3160 | + @Retention(RetentionPolicy.RUNTIME) |
| 3161 | + @Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE }) |
| 3162 | + @interface ComposedRootAnnotation { |
| 3163 | + |
| 3164 | + @AliasFor(annotation = RootAnnotation.class, attribute = "flag") |
| 3165 | + boolean enabled() default true; |
| 3166 | + } |
| 3167 | + |
| 3168 | + @Retention(RetentionPolicy.RUNTIME) |
| 3169 | + @Target(ElementType.FIELD) |
| 3170 | + @ComposedRootAnnotation |
| 3171 | + @interface DoublyComposedRootAnnotation { |
| 3172 | + } |
| 3173 | + |
| 3174 | + class DomainType { |
| 3175 | + |
| 3176 | + @RootAnnotation |
| 3177 | + Object directlyAnnotated; |
| 3178 | + |
| 3179 | + @ComposedRootAnnotation |
| 3180 | + Object metaAnnotated; |
| 3181 | + |
| 3182 | + @DoublyComposedRootAnnotation |
| 3183 | + Object metaMetaAnnotated; |
| 3184 | + } |
| 3185 | + |
3130 | 3186 | @Retention(RetentionPolicy.RUNTIME)
|
3131 | 3187 | @interface TestConfiguration {
|
3132 | 3188 |
|
|
0 commit comments