From 8a0e1969b03555b452a1198b15b079ff3525ed52 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 7 Sep 2022 14:09:09 +0200 Subject: [PATCH] Revert "Introduce isSynthesizable in MergedAnnotation" This reverts commit 32346b838261215b984e38895e90e532eb63f050. Closes gh-29093 --- .../core/annotation/MergedAnnotation.java | 9 ------- .../annotation/MissingMergedAnnotation.java | 7 +---- .../core/annotation/TypeMappedAnnotation.java | 22 +++++++--------- .../annotation/MergedAnnotationsTests.java | 26 +++---------------- .../MissingMergedAnnotationTests.java | 5 ---- 5 files changed, 14 insertions(+), 55 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java index 8c909a8a5bb..6d9c1bcf5de 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java @@ -477,15 +477,6 @@ public interface MergedAnnotation { */ > T asMap(Function, T> factory, Adapt... adaptations); - /** - * Determine if this merged annotation is synthesizable. - *

Consult the documentation for {@link #synthesize()} for an explanation - * of what is considered synthesizable. - * @return {@code true} if the mapped annotation is synthesizable - * @since 6.0 - */ - boolean isSynthesizable(); - /** * Create a type-safe synthesized version of this merged annotation that can * be used directly in code. diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MissingMergedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/MissingMergedAnnotation.java index 75966992a44..0c7c9abad61 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/MissingMergedAnnotation.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/MissingMergedAnnotation.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -134,11 +134,6 @@ final class MissingMergedAnnotation extends AbstractMerged return factory.apply(this); } - @Override - public boolean isSynthesizable() { - return false; - } - @Override public String toString() { return "(missing)"; diff --git a/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java index c2ae3a5dc7b..b776c40f390 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java @@ -319,17 +319,6 @@ final class TypeMappedAnnotation extends AbstractMergedAnn return value; } - @Override - public boolean isSynthesizable() { - // Is this a mapped annotation for a composed annotation, and are there - // annotation attributes (mirrors) that need to be merged? - if (getDistance() > 0 && this.resolvedMirrors.length > 0) { - return true; - } - // Is the mapped annotation itself synthesizable? - return this.mapping.isSynthesizable(); - } - @Override @SuppressWarnings("unchecked") protected A createSynthesizedAnnotation() { @@ -358,15 +347,22 @@ final class TypeMappedAnnotation extends AbstractMergedAnn * Determine if the supplied annotation has not already been synthesized * and whether the mapped annotation is a composed annotation * that needs to have its attributes merged or the mapped annotation is - * {@linkplain #isSynthesizable() synthesizable} in general. + * {@linkplain AnnotationTypeMapping#isSynthesizable() synthesizable} in general. * @param annotation the annotation to check * @since 5.3.22 */ private boolean isSynthesizable(Annotation annotation) { + // Already synthesized? if (AnnotationUtils.isSynthesizedAnnotation(annotation)) { return false; } - return isSynthesizable(); + // Is this a mapped annotation for a composed annotation, and are there + // annotation attributes (mirrors) that need to be merged? + if (getDistance() > 0 && this.resolvedMirrors.length > 0) { + return true; + } + // Is the mapped annotation itself synthesizable? + return this.mapping.isSynthesizable(); } @Override diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java index d97e10050bd..086f0369ee4 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java @@ -1504,13 +1504,6 @@ class MergedAnnotationsTests { assertThat(synthesizedComponent.value()).isEqualTo("webController"); } - @Test - void isSynthesizableWithoutAttributeAliases() throws Exception { - Component component = WebController.class.getAnnotation(Component.class); - assertThat(component).isNotNull(); - assertThat(MergedAnnotation.from(component).isSynthesizable()).isFalse(); - } - /** * @since 6.0 */ @@ -1595,16 +1588,10 @@ class MergedAnnotationsTests { void synthesizeShouldNotSynthesizeNonsynthesizableAnnotationsWhenUsingMergedAnnotationsFromApi() { MergedAnnotations mergedAnnotations = MergedAnnotations.from(SecurityConfig.class); - MergedAnnotation enableWebSecurityAnnotation = - mergedAnnotations.get(EnableWebSecurity.class); - assertThat(enableWebSecurityAnnotation.isSynthesizable()).isFalse(); - EnableWebSecurity enableWebSecurity = enableWebSecurityAnnotation.synthesize(); + EnableWebSecurity enableWebSecurity = mergedAnnotations.get(EnableWebSecurity.class).synthesize(); assertNotSynthesized(enableWebSecurity); - MergedAnnotation enableGlobalAuthenticationMergedAnnotation = - mergedAnnotations.get(EnableGlobalAuthentication.class); - assertThat(enableGlobalAuthenticationMergedAnnotation.isSynthesizable()).isFalse(); - EnableGlobalAuthentication enableGlobalAuthentication = enableGlobalAuthenticationMergedAnnotation.synthesize(); + EnableGlobalAuthentication enableGlobalAuthentication = mergedAnnotations.get(EnableGlobalAuthentication.class).synthesize(); assertNotSynthesized(enableGlobalAuthentication); } @@ -1750,9 +1737,7 @@ class MergedAnnotationsTests { private void testSynthesisWithImplicitAliases(Class clazz, String expected) throws Exception { ImplicitAliasesTestConfiguration config = clazz.getAnnotation(ImplicitAliasesTestConfiguration.class); assertThat(config).isNotNull(); - MergedAnnotation mergedAnnotation = MergedAnnotation.from(config); - assertThat(mergedAnnotation.isSynthesizable()).isTrue(); - ImplicitAliasesTestConfiguration synthesized = mergedAnnotation.synthesize(); + ImplicitAliasesTestConfiguration synthesized = MergedAnnotation.from(config).synthesize(); assertSynthesized(synthesized); assertThat(synthesized.value()).isEqualTo(expected); assertThat(synthesized.location1()).isEqualTo(expected); @@ -1779,11 +1764,8 @@ class MergedAnnotationsTests { ImplicitAliasesWithImpliedAliasNamesOmittedTestConfiguration config = clazz.getAnnotation( ImplicitAliasesWithImpliedAliasNamesOmittedTestConfiguration.class); assertThat(config).isNotNull(); - MergedAnnotation mergedAnnotation = - MergedAnnotation.from(config); - assertThat(mergedAnnotation.isSynthesizable()).isTrue(); ImplicitAliasesWithImpliedAliasNamesOmittedTestConfiguration synthesized = - mergedAnnotation.synthesize(); + MergedAnnotation.from(config).synthesize(); assertSynthesized(synthesized); assertThat(synthesized.value()).isEqualTo(expected); assertThat(synthesized.location()).isEqualTo(expected); diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MissingMergedAnnotationTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MissingMergedAnnotationTests.java index eb391f4c1c9..151b31f3ae0 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MissingMergedAnnotationTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MissingMergedAnnotationTests.java @@ -255,11 +255,6 @@ class MissingMergedAnnotationTests { assertThat(this.missing.getDefaultValue("value", Integer.class)).isEmpty(); } - @Test - void isSynthesizableReturnsFalse() { - assertThat(this.missing.isSynthesizable()).isFalse(); - } - @Test void synthesizeThrowsNoSuchElementException() { assertThatNoSuchElementException().isThrownBy(this.missing::synthesize);