Skip to content

Commit 8a0e196

Browse files
committed
Revert "Introduce isSynthesizable in MergedAnnotation"
This reverts commit 32346b8. Closes gh-29093
1 parent 75dfd47 commit 8a0e196

File tree

5 files changed

+14
-55
lines changed

5 files changed

+14
-55
lines changed

spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,6 @@ <T extends Annotation> MergedAnnotation<T>[] getAnnotationArray(String attribute
477477
*/
478478
<T extends Map<String, Object>> T asMap(Function<MergedAnnotation<?>, T> factory, Adapt... adaptations);
479479

480-
/**
481-
* Determine if this merged annotation is <em>synthesizable</em>.
482-
* <p>Consult the documentation for {@link #synthesize()} for an explanation
483-
* of what is considered synthesizable.
484-
* @return {@code true} if the mapped annotation is synthesizable
485-
* @since 6.0
486-
*/
487-
boolean isSynthesizable();
488-
489480
/**
490481
* Create a type-safe synthesized version of this merged annotation that can
491482
* be used directly in code.

spring-core/src/main/java/org/springframework/core/annotation/MissingMergedAnnotation.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -134,11 +134,6 @@ public <T extends Map<String, Object>> T asMap(Function<MergedAnnotation<?>, T>
134134
return factory.apply(this);
135135
}
136136

137-
@Override
138-
public boolean isSynthesizable() {
139-
return false;
140-
}
141-
142137
@Override
143138
public String toString() {
144139
return "(missing)";

spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -319,17 +319,6 @@ private <T extends Map<String, Object>> Object adaptValueForMapOptions(Method at
319319
return value;
320320
}
321321

322-
@Override
323-
public boolean isSynthesizable() {
324-
// Is this a mapped annotation for a composed annotation, and are there
325-
// annotation attributes (mirrors) that need to be merged?
326-
if (getDistance() > 0 && this.resolvedMirrors.length > 0) {
327-
return true;
328-
}
329-
// Is the mapped annotation itself synthesizable?
330-
return this.mapping.isSynthesizable();
331-
}
332-
333322
@Override
334323
@SuppressWarnings("unchecked")
335324
protected A createSynthesizedAnnotation() {
@@ -358,15 +347,22 @@ private boolean isTargetAnnotation(@Nullable Object obj) {
358347
* Determine if the supplied annotation has not already been synthesized
359348
* <strong>and</strong> whether the mapped annotation is a composed annotation
360349
* that needs to have its attributes merged or the mapped annotation is
361-
* {@linkplain #isSynthesizable() synthesizable} in general.
350+
* {@linkplain AnnotationTypeMapping#isSynthesizable() synthesizable} in general.
362351
* @param annotation the annotation to check
363352
* @since 5.3.22
364353
*/
365354
private boolean isSynthesizable(Annotation annotation) {
355+
// Already synthesized?
366356
if (AnnotationUtils.isSynthesizedAnnotation(annotation)) {
367357
return false;
368358
}
369-
return isSynthesizable();
359+
// Is this a mapped annotation for a composed annotation, and are there
360+
// annotation attributes (mirrors) that need to be merged?
361+
if (getDistance() > 0 && this.resolvedMirrors.length > 0) {
362+
return true;
363+
}
364+
// Is the mapped annotation itself synthesizable?
365+
return this.mapping.isSynthesizable();
370366
}
371367

372368
@Override

spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,13 +1504,6 @@ void synthesizeWithoutAttributeAliases() throws Exception {
15041504
assertThat(synthesizedComponent.value()).isEqualTo("webController");
15051505
}
15061506

1507-
@Test
1508-
void isSynthesizableWithoutAttributeAliases() throws Exception {
1509-
Component component = WebController.class.getAnnotation(Component.class);
1510-
assertThat(component).isNotNull();
1511-
assertThat(MergedAnnotation.from(component).isSynthesizable()).isFalse();
1512-
}
1513-
15141507
/**
15151508
* @since 6.0
15161509
*/
@@ -1595,16 +1588,10 @@ void synthesizeWhenUsingMergedAnnotationsFromApi() {
15951588
void synthesizeShouldNotSynthesizeNonsynthesizableAnnotationsWhenUsingMergedAnnotationsFromApi() {
15961589
MergedAnnotations mergedAnnotations = MergedAnnotations.from(SecurityConfig.class);
15971590

1598-
MergedAnnotation<EnableWebSecurity> enableWebSecurityAnnotation =
1599-
mergedAnnotations.get(EnableWebSecurity.class);
1600-
assertThat(enableWebSecurityAnnotation.isSynthesizable()).isFalse();
1601-
EnableWebSecurity enableWebSecurity = enableWebSecurityAnnotation.synthesize();
1591+
EnableWebSecurity enableWebSecurity = mergedAnnotations.get(EnableWebSecurity.class).synthesize();
16021592
assertNotSynthesized(enableWebSecurity);
16031593

1604-
MergedAnnotation<EnableGlobalAuthentication> enableGlobalAuthenticationMergedAnnotation =
1605-
mergedAnnotations.get(EnableGlobalAuthentication.class);
1606-
assertThat(enableGlobalAuthenticationMergedAnnotation.isSynthesizable()).isFalse();
1607-
EnableGlobalAuthentication enableGlobalAuthentication = enableGlobalAuthenticationMergedAnnotation.synthesize();
1594+
EnableGlobalAuthentication enableGlobalAuthentication = mergedAnnotations.get(EnableGlobalAuthentication.class).synthesize();
16081595
assertNotSynthesized(enableGlobalAuthentication);
16091596
}
16101597

@@ -1750,9 +1737,7 @@ void synthesizeWithImplicitAliases() throws Exception {
17501737
private void testSynthesisWithImplicitAliases(Class<?> clazz, String expected) throws Exception {
17511738
ImplicitAliasesTestConfiguration config = clazz.getAnnotation(ImplicitAliasesTestConfiguration.class);
17521739
assertThat(config).isNotNull();
1753-
MergedAnnotation<ImplicitAliasesTestConfiguration> mergedAnnotation = MergedAnnotation.from(config);
1754-
assertThat(mergedAnnotation.isSynthesizable()).isTrue();
1755-
ImplicitAliasesTestConfiguration synthesized = mergedAnnotation.synthesize();
1740+
ImplicitAliasesTestConfiguration synthesized = MergedAnnotation.from(config).synthesize();
17561741
assertSynthesized(synthesized);
17571742
assertThat(synthesized.value()).isEqualTo(expected);
17581743
assertThat(synthesized.location1()).isEqualTo(expected);
@@ -1779,11 +1764,8 @@ private void testSynthesisWithImplicitAliasesWithImpliedAliasNamesOmitted(
17791764
ImplicitAliasesWithImpliedAliasNamesOmittedTestConfiguration config = clazz.getAnnotation(
17801765
ImplicitAliasesWithImpliedAliasNamesOmittedTestConfiguration.class);
17811766
assertThat(config).isNotNull();
1782-
MergedAnnotation<ImplicitAliasesWithImpliedAliasNamesOmittedTestConfiguration> mergedAnnotation =
1783-
MergedAnnotation.from(config);
1784-
assertThat(mergedAnnotation.isSynthesizable()).isTrue();
17851767
ImplicitAliasesWithImpliedAliasNamesOmittedTestConfiguration synthesized =
1786-
mergedAnnotation.synthesize();
1768+
MergedAnnotation.from(config).synthesize();
17871769
assertSynthesized(synthesized);
17881770
assertThat(synthesized.value()).isEqualTo(expected);
17891771
assertThat(synthesized.location()).isEqualTo(expected);

spring-core/src/test/java/org/springframework/core/annotation/MissingMergedAnnotationTests.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,6 @@ void getDefaultValueReturnsEmpty() {
255255
assertThat(this.missing.getDefaultValue("value", Integer.class)).isEmpty();
256256
}
257257

258-
@Test
259-
void isSynthesizableReturnsFalse() {
260-
assertThat(this.missing.isSynthesizable()).isFalse();
261-
}
262-
263258
@Test
264259
void synthesizeThrowsNoSuchElementException() {
265260
assertThatNoSuchElementException().isThrownBy(this.missing::synthesize);

0 commit comments

Comments
 (0)