diff --git a/framework-docs/src/docs/asciidoc/core/core-aop.adoc b/framework-docs/src/docs/asciidoc/core/core-aop.adoc index 91cb552669..301fd17b61 100644 --- a/framework-docs/src/docs/asciidoc/core/core-aop.adoc +++ b/framework-docs/src/docs/asciidoc/core/core-aop.adoc @@ -295,11 +295,11 @@ which is annotated with the `org.aspectj.lang.annotation.Aspect` annotation; .Java ---- package org.xyz; + import org.aspectj.lang.annotation.Aspect; @Aspect public class NotVeryUsefulAspect { - } ---- [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] @@ -307,7 +307,7 @@ which is annotated with the `org.aspectj.lang.annotation.Aspect` annotation; ---- package org.xyz - import org.aspectj.lang.annotation.Aspect; + import org.aspectj.lang.annotation.Aspect @Aspect class NotVeryUsefulAspect @@ -2491,6 +2491,8 @@ proceed with the method call. The presence of this parameter is an indication th [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] .Kotlin ---- + package x.y + import org.aspectj.lang.ProceedingJoinPoint import org.springframework.util.StopWatch diff --git a/framework-docs/src/docs/asciidoc/core/core-appendix.adoc b/framework-docs/src/docs/asciidoc/core/core-appendix.adoc index 488765bd02..1872ec9084 100644 --- a/framework-docs/src/docs/asciidoc/core/core-appendix.adoc +++ b/framework-docs/src/docs/asciidoc/core/core-appendix.adoc @@ -1410,7 +1410,7 @@ JCache-initializing `BeanDefinition`. The following listing shows our `JCacheIni public class JCacheInitializer { - private String name; + private final String name; public JCacheInitializer(String name) { this.name = name; diff --git a/framework-docs/src/docs/asciidoc/core/core-beans.adoc b/framework-docs/src/docs/asciidoc/core/core-beans.adoc index c387eb7760..8915341bc2 100644 --- a/framework-docs/src/docs/asciidoc/core/core-beans.adoc +++ b/framework-docs/src/docs/asciidoc/core/core-beans.adoc @@ -2279,7 +2279,6 @@ shows this approach: [source,java,indent=0,subs="verbatim,quotes",role="primary"] .Java ---- - // a class that uses a stateful Command-style class to perform some processing package fiona.apple; // Spring-API imports @@ -2287,6 +2286,10 @@ shows this approach: import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; + /** + * A class that uses a stateful Command-style class to perform + * some processing. + */ public class CommandManager implements ApplicationContextAware { private ApplicationContext applicationContext; @@ -2313,13 +2316,14 @@ shows this approach: [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] .Kotlin ---- - // a class that uses a stateful Command-style class to perform some processing package fiona.apple // Spring-API imports import org.springframework.context.ApplicationContext import org.springframework.context.ApplicationContextAware + // A class that uses a stateful Command-style class to perform + // some processing. class CommandManager : ApplicationContextAware { private lateinit var applicationContext: ApplicationContext @@ -4237,6 +4241,8 @@ The following listing shows the custom `BeanPostProcessor` implementation class [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] .Kotlin ---- + package scripting + import org.springframework.beans.factory.config.BeanPostProcessor class InstantiationTracingBeanPostProcessor : BeanPostProcessor { diff --git a/framework-docs/src/docs/asciidoc/core/core-expressions.adoc b/framework-docs/src/docs/asciidoc/core/core-expressions.adoc index d813cd2b37..4ec179ac87 100644 --- a/framework-docs/src/docs/asciidoc/core/core-expressions.adoc +++ b/framework-docs/src/docs/asciidoc/core/core-expressions.adoc @@ -2054,12 +2054,14 @@ This section lists the classes used in the examples throughout this chapter. [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] .Inventor.kt ---- -class Inventor( - var name: String, - var nationality: String, - var inventions: Array? = null, - var birthdate: Date = GregorianCalendar().time, - var placeOfBirth: PlaceOfBirth? = null) + package org.spring.samples.spel.inventor + + class Inventor( + var name: String, + var nationality: String, + var inventions: Array? = null, + var birthdate: Date = GregorianCalendar().time, + var placeOfBirth: PlaceOfBirth? = null) ---- [source,java,indent=0,subs="verbatim,quotes",role="primary"] @@ -2101,6 +2103,8 @@ class Inventor( [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] .PlaceOfBirth.kt ---- + package org.spring.samples.spel.inventor + class PlaceOfBirth(var city: String, var country: String? = null) { ---- diff --git a/framework-docs/src/docs/asciidoc/core/core-validation.adoc b/framework-docs/src/docs/asciidoc/core/core-validation.adoc index 0b9d3f9c24..e1b91144bd 100644 --- a/framework-docs/src/docs/asciidoc/core/core-validation.adoc +++ b/framework-docs/src/docs/asciidoc/core/core-validation.adoc @@ -692,9 +692,11 @@ The `PropertyEditor` implementation could look similar to the following: [source,java,indent=0,subs="verbatim,quotes",role="primary"] .Java ---- - // converts string representation to ExoticType object package example; + import java.beans.PropertyEditorSupport; + + // converts string representation to ExoticType object public class ExoticTypeEditor extends PropertyEditorSupport { public void setAsText(String text) { @@ -705,11 +707,11 @@ The `PropertyEditor` implementation could look similar to the following: [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] .Kotlin ---- - // converts string representation to ExoticType object package example import java.beans.PropertyEditorSupport + // converts string representation to ExoticType object class ExoticTypeEditor : PropertyEditorSupport() { override fun setAsText(text: String) { @@ -1350,15 +1352,14 @@ listing shows the definition of the `AnnotationFormatterFactory` interface: To create an implementation: -. Parameterize A to be the field `annotationType` with which you wish to associate +. Parameterize `A` to be the field `annotationType` with which you wish to associate formatting logic -- for example `org.springframework.format.annotation.DateTimeFormat`. . Have `getFieldTypes()` return the types of fields on which the annotation can be used. . Have `getPrinter()` return a `Printer` to print the value of an annotated field. . Have `getParser()` return a `Parser` to parse a `clientValue` for an annotated field. The following example `AnnotationFormatterFactory` implementation binds the `@NumberFormat` -annotation to a formatter to let a number style or pattern be -specified: +annotation to a formatter to let a number style or pattern be specified: [source,java,indent=0,subs="verbatim,quotes",role="primary"] .Java @@ -1366,10 +1367,12 @@ specified: public final class NumberFormatAnnotationFormatterFactory implements AnnotationFormatterFactory { + private static final Set> FIELD_TYPES = Set.of(Short.class, + Integer.class, Long.class, Float.class, Double.class, + BigDecimal.class, BigInteger.class); + public Set> getFieldTypes() { - return new HashSet>(asList(new Class[] { - Short.class, Integer.class, Long.class, Float.class, - Double.class, BigDecimal.class, BigInteger.class })); + return FIELD_TYPES; } public Printer getPrinter(NumberFormat annotation, Class fieldType) { @@ -1383,16 +1386,13 @@ specified: private Formatter configureFormatterFrom(NumberFormat annotation, Class fieldType) { if (!annotation.pattern().isEmpty()) { return new NumberStyleFormatter(annotation.pattern()); - } else { - Style style = annotation.style(); - if (style == Style.PERCENT) { - return new PercentStyleFormatter(); - } else if (style == Style.CURRENCY) { - return new CurrencyStyleFormatter(); - } else { - return new NumberStyleFormatter(); - } } + // else + return switch(annotation.style()) { + case Style.PERCENT -> new PercentStyleFormatter(); + case Style.CURRENCY -> new CurrencyStyleFormatter(); + default -> new NumberStyleFormatter(); + }; } } ---- @@ -1428,7 +1428,7 @@ specified: } ---- -To trigger formatting, you can annotate fields with @NumberFormat, as the following +To trigger formatting, you can annotate fields with `@NumberFormat`, as the following example shows: [source,java,indent=0,subs="verbatim,quotes",role="primary"] diff --git a/framework-docs/src/docs/asciidoc/data-access.adoc b/framework-docs/src/docs/asciidoc/data-access.adoc index 49f0f2ce55..cbb0ef3bb3 100644 --- a/framework-docs/src/docs/asciidoc/data-access.adoc +++ b/framework-docs/src/docs/asciidoc/data-access.adoc @@ -2068,6 +2068,12 @@ The following code shows the simple profiling aspect discussed earlier: [source,kotlin,indent=0,subs="verbatim",role="secondary"] .Kotlin ---- + package x.y + + import org.aspectj.lang.ProceedingJoinPoint + import org.springframework.util.StopWatch + import org.springframework.core.Ordered + class SimpleProfiler : Ordered { private var order: Int = 0 diff --git a/framework-docs/src/docs/asciidoc/integration/scheduling.adoc b/framework-docs/src/docs/asciidoc/integration/scheduling.adoc index 014430065b..da3769b4ba 100644 --- a/framework-docs/src/docs/asciidoc/integration/scheduling.adoc +++ b/framework-docs/src/docs/asciidoc/integration/scheduling.adoc @@ -827,7 +827,7 @@ has it applied automatically: /** * Setter called after the ExampleJob is instantiated - * with the value from the JobDetailFactoryBean (5) + * with the value from the JobDetailFactoryBean. */ public void setTimeout(int timeout) { this.timeout = timeout; diff --git a/framework-docs/src/docs/asciidoc/languages/dynamic-languages.adoc b/framework-docs/src/docs/asciidoc/languages/dynamic-languages.adoc index 7362adaa7e..69d6c0ab0b 100644 --- a/framework-docs/src/docs/asciidoc/languages/dynamic-languages.adoc +++ b/framework-docs/src/docs/asciidoc/languages/dynamic-languages.adoc @@ -67,13 +67,12 @@ The following example implements the `Messenger` interface in Groovy: [source,groovy,indent=0,subs="verbatim,quotes"] ---- - // from the file 'Messenger.groovy' - package org.springframework.scripting.groovy; + package org.springframework.scripting.groovy - // import the Messenger interface (written in Java) that is to be implemented + // Import the Messenger interface (written in Java) that is to be implemented import org.springframework.scripting.Messenger - // define the implementation in Groovy + // Define the implementation in Groovy in file 'Messenger.groovy' class GroovyMessenger implements Messenger { String message @@ -331,13 +330,13 @@ feature works: - package org.springframework.scripting.groovy; + package org.springframework.scripting.groovy - import org.springframework.scripting.Messenger + import org.springframework.scripting.Messenger - class GroovyMessenger implements Messenger { - String message - } + class GroovyMessenger implements Messenger { + String message + } @@ -365,11 +364,11 @@ does not work: .An approach that cannot work [source,groovy,indent=0,subs="verbatim,quotes"] ---- - // from the file 'Messenger.groovy' - package org.springframework.scripting.groovy; + package org.springframework.scripting.groovy import org.springframework.scripting.Messenger + // from the file 'Messenger.groovy' class GroovyMessenger implements Messenger { GroovyMessenger() {} @@ -434,9 +433,9 @@ The following example implements the `Calculator` interface in Groovy: [source,groovy,indent=0,subs="verbatim,quotes"] ---- - // from the file 'calculator.groovy' package org.springframework.scripting.groovy + // from the file 'calculator.groovy' class GroovyCalculator implements Calculator { int add(int x, int y) { @@ -678,7 +677,6 @@ by using the Groovy dynamic language: [source,groovy,indent=0,subs="verbatim,quotes"] ---- - // from the file '/WEB-INF/groovy/FortuneController.groovy' package org.springframework.showcase.fortune.web import org.springframework.showcase.fortune.service.FortuneService @@ -689,6 +687,7 @@ by using the Groovy dynamic language: import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse + // from the file '/WEB-INF/groovy/FortuneController.groovy' class FortuneController implements Controller { @Property FortuneService fortuneService