From 661996471e6c7e07c9409d8579f1bfcff18f095e Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 25 Jun 2022 17:21:33 +0200 Subject: [PATCH 1/3] Polishing --- .../springframework/test/context/BootstrapUtilsTests.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-test/src/test/java/org/springframework/test/context/BootstrapUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/BootstrapUtilsTests.java index 14d45f1b3b3..36035325528 100644 --- a/spring-test/src/test/java/org/springframework/test/context/BootstrapUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/BootstrapUtilsTests.java @@ -61,8 +61,8 @@ class BootstrapUtilsTests { @Test void resolveTestContextBootstrapperWithEmptyBootstrapWithAnnotation() { BootstrapContext bootstrapContext = BootstrapTestUtils.buildBootstrapContext(EmptyBootstrapWithAnnotationClass.class, delegate); - assertThatIllegalStateException().isThrownBy(() -> - resolveTestContextBootstrapper(bootstrapContext)) + assertThatIllegalStateException() + .isThrownBy(() -> resolveTestContextBootstrapper(bootstrapContext)) .withMessageContaining("Specify @BootstrapWith's 'value' attribute"); } @@ -70,8 +70,8 @@ class BootstrapUtilsTests { void resolveTestContextBootstrapperWithDoubleMetaBootstrapWithAnnotations() { BootstrapContext bootstrapContext = BootstrapTestUtils.buildBootstrapContext( DoubleMetaAnnotatedBootstrapWithAnnotationClass.class, delegate); - assertThatIllegalStateException().isThrownBy(() -> - resolveTestContextBootstrapper(bootstrapContext)) + assertThatIllegalStateException() + .isThrownBy(() -> resolveTestContextBootstrapper(bootstrapContext)) .withMessageContaining("Configuration error: found multiple declarations of @BootstrapWith") .withMessageContaining(FooBootstrapper.class.getCanonicalName()) .withMessageContaining(BarBootstrapper.class.getCanonicalName()); From faf20b7a5a496c6381e9a90552ca3ed08fbce230 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 25 Jun 2022 19:02:23 +0200 Subject: [PATCH 2/3] Polish MergedAnnotations Javadoc and internals --- .../annotation/AbstractMergedAnnotation.java | 10 +++++++--- .../core/annotation/MergedAnnotation.java | 16 +++++++++------- .../core/annotation/MissingMergedAnnotation.java | 2 +- .../core/annotation/TypeMappedAnnotation.java | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AbstractMergedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/AbstractMergedAnnotation.java index 45bf025492e..63c7b05a7a2 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AbstractMergedAnnotation.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AbstractMergedAnnotation.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -207,7 +207,7 @@ abstract class AbstractMergedAnnotation implements MergedA } A synthesized = this.synthesizedAnnotation; if (synthesized == null) { - synthesized = createSynthesized(); + synthesized = createSynthesizedAnnotation(); this.synthesizedAnnotation = synthesized; } return synthesized; @@ -237,7 +237,11 @@ abstract class AbstractMergedAnnotation implements MergedA /** * Factory method used to create the synthesized annotation. + *

If the source is an annotation that is not synthesizable, it + * will be returned unmodified. + *

Consult the documentation for {@link MergedAnnotation#synthesize()} + * for an explanation of what is considered synthesizable. */ - protected abstract A createSynthesized(); + protected abstract A createSynthesizedAnnotation(); } 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 ed60e365c3d..68422f7ec0f 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -19,7 +19,6 @@ package org.springframework.core.annotation; import java.lang.annotation.Annotation; import java.lang.annotation.Inherited; import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Proxy; import java.util.EnumSet; import java.util.List; import java.util.Map; @@ -481,12 +480,15 @@ public interface MergedAnnotation { /** * Create a type-safe synthesized version of this merged annotation that can * be used directly in code. - *

The result is synthesized using a JDK {@link Proxy} and as a result may - * incur a computational cost when first invoked. + *

The result is synthesized using a JDK {@link java.lang.reflect.Proxy Proxy} + * and as a result may incur a computational cost when first invoked. + *

If this merged annotation was created {@linkplain #of(AnnotatedElement, Class, Map) + * from} a map of annotation attributes or default attribute values, those + * attributes will always be synthesized into an annotation instance. *

If this merged annotation was created {@linkplain #from(Annotation) from} * an annotation instance, that annotation will be returned unmodified if it is * not synthesizable. An annotation is considered synthesizable if - * one of the following is true. + * it has not already been synthesized and one of the following is true. *