|
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;
|
@@ -1539,7 +1540,28 @@ void synthesizeShouldNotSynthesizeNonsynthesizableAnnotations() throws Exception
|
1539 | 1540 | assertThat(generatedValue).isSameAs(synthesizedGeneratedValue);
|
1540 | 1541 | }
|
1541 | 1542 |
|
1542 |
| - @Test |
| 1543 | + @Test // gh-28716 |
| 1544 | + void synthesizeWhenUsingMergedAnnotationsFromApi() { |
| 1545 | + Field directlyAnnotatedField = ReflectionUtils.findField(DomainType.class, "directlyAnnotated"); |
| 1546 | + MergedAnnotations mergedAnnotations = MergedAnnotations.from(directlyAnnotatedField); |
| 1547 | + RootAnnotation rootAnnotation = mergedAnnotations.get(RootAnnotation.class).synthesize(); |
| 1548 | + assertThat(rootAnnotation.flag()).isFalse(); |
| 1549 | + assertThat(rootAnnotation).isNotInstanceOf(SynthesizedAnnotation.class); |
| 1550 | + |
| 1551 | + Field metaAnnotatedField = ReflectionUtils.findField(DomainType.class, "metaAnnotated"); |
| 1552 | + mergedAnnotations = MergedAnnotations.from(metaAnnotatedField); |
| 1553 | + rootAnnotation = mergedAnnotations.get(RootAnnotation.class).synthesize(); |
| 1554 | + assertThat(rootAnnotation.flag()).isTrue(); |
| 1555 | + assertThat(rootAnnotation).isInstanceOf(SynthesizedAnnotation.class); |
| 1556 | + |
| 1557 | + Field metaMetaAnnotatedField = ReflectionUtils.findField(DomainType.class, "metaMetaAnnotated"); |
| 1558 | + mergedAnnotations = MergedAnnotations.from(metaMetaAnnotatedField); |
| 1559 | + rootAnnotation = mergedAnnotations.get(RootAnnotation.class).synthesize(); |
| 1560 | + assertThat(rootAnnotation.flag()).isTrue(); |
| 1561 | + assertThat(rootAnnotation).isInstanceOf(SynthesizedAnnotation.class); |
| 1562 | + } |
| 1563 | + |
| 1564 | + @Test // gh-28704 |
1543 | 1565 | void synthesizeShouldNotSynthesizeNonsynthesizableAnnotationsWhenUsingMergedAnnotationsFromApi() {
|
1544 | 1566 | MergedAnnotations mergedAnnotations = MergedAnnotations.from(SecurityConfig.class);
|
1545 | 1567 |
|
@@ -3246,6 +3268,40 @@ private Long getId() {
|
3246 | 3268 | static class SecurityConfig {
|
3247 | 3269 | }
|
3248 | 3270 |
|
| 3271 | + @Retention(RetentionPolicy.RUNTIME) |
| 3272 | + @Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE }) |
| 3273 | + @interface RootAnnotation { |
| 3274 | + String value() default ""; |
| 3275 | + boolean flag() default false; |
| 3276 | + } |
| 3277 | + |
| 3278 | + @RootAnnotation |
| 3279 | + @Retention(RetentionPolicy.RUNTIME) |
| 3280 | + @Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE }) |
| 3281 | + @interface ComposedRootAnnotation { |
| 3282 | + |
| 3283 | + @AliasFor(annotation = RootAnnotation.class, attribute = "flag") |
| 3284 | + boolean enabled() default true; |
| 3285 | + } |
| 3286 | + |
| 3287 | + @Retention(RetentionPolicy.RUNTIME) |
| 3288 | + @Target(ElementType.FIELD) |
| 3289 | + @ComposedRootAnnotation |
| 3290 | + @interface DoublyComposedRootAnnotation { |
| 3291 | + } |
| 3292 | + |
| 3293 | + class DomainType { |
| 3294 | + |
| 3295 | + @RootAnnotation |
| 3296 | + Object directlyAnnotated; |
| 3297 | + |
| 3298 | + @ComposedRootAnnotation |
| 3299 | + Object metaAnnotated; |
| 3300 | + |
| 3301 | + @DoublyComposedRootAnnotation |
| 3302 | + Object metaMetaAnnotated; |
| 3303 | + } |
| 3304 | + |
3249 | 3305 | @Retention(RetentionPolicy.RUNTIME)
|
3250 | 3306 | @interface TestConfiguration {
|
3251 | 3307 |
|
|
0 commit comments