Remove remaining Kotlin "translations" of Java APIs in the reference manual

This commit is contained in:
Sam Brannen
2021-02-16 11:16:14 +01:00
parent 1e57e572dd
commit efc335e198
5 changed files with 33 additions and 427 deletions

View File

@@ -25,26 +25,13 @@ target different advice with the same pointcut.
The `org.springframework.aop.Pointcut` interface is the central interface, used to
target advices to particular classes and methods. The complete interface follows:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface Pointcut {
ClassFilter getClassFilter();
MethodMatcher getMethodMatcher();
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface Pointcut {
fun getClassFilter(): ClassFilter
fun getMethodMatcher(): MethodMatcher
}
----
@@ -56,27 +43,17 @@ The `ClassFilter` interface is used to restrict the pointcut to a given set of t
classes. If the `matches()` method always returns true, all target classes are
matched. The following listing shows the `ClassFilter` interface definition:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface ClassFilter {
boolean matches(Class clazz);
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface ClassFilter {
fun matches(clazz: Class<*>): Boolean
}
----
The `MethodMatcher` interface is normally more important. The complete interface follows:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface MethodMatcher {
@@ -87,18 +64,6 @@ The `MethodMatcher` interface is normally more important. The complete interface
boolean matches(Method m, Class targetClass, Object[] args);
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface MethodMatcher {
val isRuntime: Boolean
fun matches(m: Method, targetClass: Class<*>): Boolean
fun matches(m: Method, targetClass: Class<*>, args: Array<Any>): Boolean
}
----
The `matches(Method, Class)` method is used to test whether this pointcut ever
matches a given method on a target class. This evaluation can be performed when an AOP
@@ -335,22 +300,13 @@ Spring is compliant with the AOP `Alliance` interface for around advice that use
interception. Classes that implement `MethodInterceptor` and that implement around advice should also implement the
following interface:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface MethodInterceptor extends Interceptor {
Object invoke(MethodInvocation invocation) throws Throwable;
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface MethodInterceptor : Interceptor {
fun invoke(invocation: MethodInvocation) : Any
}
----
The `MethodInvocation` argument to the `invoke()` method exposes the method being
invoked, the target join point, the AOP proxy, and the arguments to the method. The
@@ -413,22 +369,13 @@ interceptor chain.
The following listing shows the `MethodBeforeAdvice` interface:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface MethodBeforeAdvice extends BeforeAdvice {
void before(Method m, Object[] args, Object target) throws Throwable;
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface MethodBeforeAdvice : BeforeAdvice {
fun before(m: Method, args: Array<Any>, target: Any)
}
----
(Spring's API design would allow for
field before advice, although the usual objects apply to field interception and it is
@@ -591,8 +538,7 @@ TIP: Throws advice can be used with any pointcut.
An after returning advice in Spring must implement the
`org.springframework.aop.AfterReturningAdvice` interface, which the following listing shows:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface AfterReturningAdvice extends Advice {
@@ -600,14 +546,6 @@ An after returning advice in Spring must implement the
throws Throwable;
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface AfterReturningAdvice : Advice {
fun afterReturning(returnValue: Any, m: Method, args: Array<Any>, target: Any)
}
----
An after returning advice has access to the return value (which it cannot modify),
the invoked method, the method's arguments, and the target.
@@ -660,22 +598,13 @@ Spring treats introduction advice as a special kind of interception advice.
Introduction requires an `IntroductionAdvisor` and an `IntroductionInterceptor` that
implement the following interface:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface IntroductionInterceptor extends MethodInterceptor {
boolean implementsInterface(Class intf);
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface IntroductionInterceptor : MethodInterceptor {
fun implementsInterface(intf: Class<*>): Boolean
}
----
The `invoke()` method inherited from the AOP Alliance `MethodInterceptor` interface must
implement the introduction. That is, if the invoked method is on an introduced
@@ -686,8 +615,7 @@ Introduction advice cannot be used with any pointcut, as it applies only at the
rather than the method, level. You can only use introduction advice with the
`IntroductionAdvisor`, which has the following methods:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface IntroductionAdvisor extends Advisor, IntroductionInfo {
@@ -701,22 +629,6 @@ rather than the method, level. You can only use introduction advice with the
Class<?>[] getInterfaces();
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface IntroductionAdvisor : Advisor, IntroductionInfo {
val classFilter: ClassFilter
@Throws(IllegalArgumentException::class)
fun validateInterfaces()
}
interface IntroductionInfo {
val interfaces: Array<Class<*>>
}
----
There is no `MethodMatcher` and, hence, no `Pointcut` associated with introduction
advice. Only class filtering is logical.

View File

@@ -3406,16 +3406,10 @@ The `org.springframework.beans.factory.InitializingBean` interface lets a bean
perform initialization work after the container has set all necessary properties on the
bean. The `InitializingBean` interface specifies a single method:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
void afterPropertiesSet() throws Exception;
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
fun afterPropertiesSet()
----
We recommend that you do not use the `InitializingBean` interface, because it
unnecessarily couples the code to Spring. Alternatively, we suggest using
@@ -3491,16 +3485,10 @@ Implementing the `org.springframework.beans.factory.DisposableBean` interface le
bean get a callback when the container that contains it is destroyed. The
`DisposableBean` interface specifies a single method:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
void destroy() throws Exception;
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
fun destroy()
----
We recommend that you do not use the `DisposableBean` callback interface, because it
unnecessarily couples the code to Spring. Alternatively, we suggest using
@@ -3711,8 +3699,7 @@ Destroy methods are called in the same order:
The `Lifecycle` interface defines the essential methods for any object that has its own
lifecycle requirements (such as starting and stopping some background process):
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface Lifecycle {
@@ -3723,18 +3710,6 @@ lifecycle requirements (such as starting and stopping some background process):
boolean isRunning();
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface Lifecycle {
fun start()
fun stop()
val isRunning: Boolean
}
----
Any Spring-managed object may implement the `Lifecycle` interface. Then, when the
`ApplicationContext` itself receives start and stop signals (for example, for a stop/restart
@@ -3742,8 +3717,7 @@ scenario at runtime), it cascades those calls to all `Lifecycle` implementations
defined within that context. It does this by delegating to a `LifecycleProcessor`, shown
in the following listing:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface LifecycleProcessor extends Lifecycle {
@@ -3752,16 +3726,6 @@ in the following listing:
void onClose();
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface LifecycleProcessor : Lifecycle {
fun onRefresh()
fun onClose()
}
----
Notice that the `LifecycleProcessor` is itself an extension of the `Lifecycle`
interface. It also adds two other methods for reacting to the context being refreshed
@@ -3788,27 +3752,17 @@ prior to objects of another type. In those cases, the `SmartLifecycle` interface
another option, namely the `getPhase()` method as defined on its super-interface,
`Phased`. The following listing shows the definition of the `Phased` interface:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface Phased {
int getPhase();
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface Phased {
val phase: Int
}
----
The following listing shows the definition of the `SmartLifecycle` interface:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface SmartLifecycle extends Lifecycle, Phased {
@@ -3817,16 +3771,6 @@ The following listing shows the definition of the `SmartLifecycle` interface:
void stop(Runnable callback);
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface SmartLifecycle : Lifecycle, Phased {
val isAutoStartup: Boolean
fun stop(callback: Runnable)
}
----
When starting, the objects with the lowest phase start first. When stopping, the
reverse order is followed. Therefore, an object that implements `SmartLifecycle` and
@@ -3938,23 +3882,13 @@ When an `ApplicationContext` creates an object instance that implements the
with a reference to that `ApplicationContext`. The following listing shows the definition
of the `ApplicationContextAware` interface:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface ApplicationContextAware {
void setApplicationContext(ApplicationContext applicationContext) throws BeansException;
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface ApplicationContextAware {
@Throws(BeansException::class)
fun setApplicationContext(applicationContext: ApplicationContext)
}
----
Thus, beans can programmatically manipulate the `ApplicationContext` that created them,
through the `ApplicationContext` interface or by casting the reference to a known
@@ -3983,23 +3917,13 @@ When an `ApplicationContext` creates a class that implements the
a reference to the name defined in its associated object definition. The following listing
shows the definition of the BeanNameAware interface:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface BeanNameAware {
void setBeanName(String name) throws BeansException;
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface BeanNameAware {
@Throws(BeansException::class)
fun setBeanName(name: String)
}
----
The callback is invoked after population of normal bean properties but before an
initialization callback such as `InitializingBean`, `afterPropertiesSet`, or a custom

View File

@@ -41,7 +41,6 @@ following listing provides an overview of the `Resource` interface. See the
[source,java,indent=0,subs="verbatim,quotes"]
.Java
----
public interface Resource extends InputStreamSource {
@@ -78,7 +77,6 @@ interface. The following listing shows the definition of the `InputStreamSource`
interface:
[source,java,indent=0,subs="verbatim,quotes"]
.Java
----
public interface InputStreamSource {
@@ -261,7 +259,6 @@ The `ResourceLoader` interface is meant to be implemented by objects that can re
interface definition:
[source,java,indent=0,subs="verbatim,quotes"]
.Java
----
public interface ResourceLoader {
@@ -374,7 +371,6 @@ which defines a strategy for resolving a location pattern (for example, an Ant-s
pattern) into `Resource` objects.
[source,java,indent=0,subs="verbatim,quotes"]
.Java
----
public interface ResourcePatternResolver extends ResourceLoader {
@@ -426,7 +422,6 @@ components that expect to be provided a `ResourceLoader` reference. The followin
shows the definition of the `ResourceLoaderAware` interface:
[source,java,indent=0,subs="verbatim,quotes"]
.Java
----
public interface ResourceLoaderAware {

View File

@@ -874,8 +874,7 @@ application where type conversion is needed.
The SPI to implement type conversion logic is simple and strongly typed, as the following
interface definition shows:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
package org.springframework.core.convert.converter;
@@ -884,16 +883,6 @@ interface definition shows:
T convert(S source);
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
package org.springframework.core.convert.converter
interface Converter<S, T> {
fun convert(source: S): T
}
----
To create your own converter, implement the `Converter` interface and parameterize `S`
as the type you are converting from and `T` as the type you are converting to. You can also transparently apply such a
@@ -910,8 +899,7 @@ Several converter implementations are provided in the `core.convert.support` pac
a convenience. These include converters from strings to numbers and other common types.
The following listing shows the `StringToInteger` class, which is a typical `Converter` implementation:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
package org.springframework.core.convert.support;
@@ -922,20 +910,6 @@ The following listing shows the `StringToInteger` class, which is a typical `Con
}
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
package org.springframework.core.convert.support
import org.springframework.core.convert.converter.Converter
internal class StringToInteger : Converter<String, Int> {
override fun convert(source: String): Int? {
return Integer.valueOf(source)
}
}
----
@@ -946,8 +920,7 @@ When you need to centralize the conversion logic for an entire class hierarchy
(for example, when converting from `String` to `Enum` objects), you can implement
`ConverterFactory`, as the following example shows:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
package org.springframework.core.convert.converter;
@@ -956,16 +929,6 @@ When you need to centralize the conversion logic for an entire class hierarchy
<T extends R> Converter<S, T> getConverter(Class<T> targetType);
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
package org.springframework.core.convert.converter
interface ConverterFactory<S, R> {
fun <T : R> getConverter(targetType: Class<T>): Converter<S, T>
}
----
Parameterize S to be the type you are converting from and R to be the base type defining
the __range__ of classes you can convert to. Then implement `getConverter(Class<T>)`,
@@ -974,7 +937,6 @@ where T is a subclass of R.
Consider the `StringToEnumConverterFactory` as an example:
[source,java,indent=0,subs="verbatim,quotes"]
.Java
----
package org.springframework.core.convert.support;
@@ -1011,8 +973,7 @@ context that you can use when you implement your conversion logic. Such context
type conversion be driven by a field annotation or by generic information declared on a
field signature. The following listing shows the interface definition of `GenericConverter`:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
package org.springframework.core.convert.converter;
@@ -1023,18 +984,6 @@ field signature. The following listing shows the interface definition of `Generi
Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType);
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
package org.springframework.core.convert.converter
interface GenericConverter {
fun getConvertibleTypes(): Set<ConvertiblePair>?
fun convert(@Nullable source: Any?, sourceType: TypeDescriptor, targetType: TypeDescriptor): Any?
}
----
To implement a `GenericConverter`, have `getConvertibleTypes()` return the supported
source->target type pairs. Then implement `convert(Object, TypeDescriptor,
@@ -1063,8 +1012,7 @@ on the target field, or you might want to run a `Converter` only if a specific m
`ConditionalGenericConverter` is the union of the `GenericConverter` and
`ConditionalConverter` interfaces that lets you define such custom matching criteria:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface ConditionalConverter {
@@ -1074,16 +1022,6 @@ on the target field, or you might want to run a `Converter` only if a specific m
public interface ConditionalGenericConverter extends GenericConverter, ConditionalConverter {
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface ConditionalConverter {
fun matches(sourceType: TypeDescriptor, targetType: TypeDescriptor): Boolean
}
interface ConditionalGenericConverter : GenericConverter, ConditionalConverter
----
A good example of a `ConditionalGenericConverter` is an `EntityConverter` that converts
between a persistent entity identifier and an entity reference. Such an `EntityConverter`
@@ -1099,8 +1037,7 @@ might match only if the target entity type declares a static finder method (for
`ConversionService` defines a unified API for executing type conversion logic at
runtime. Converters are often run behind the following facade interface:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
package org.springframework.core.convert;
@@ -1113,24 +1050,6 @@ runtime. Converters are often run behind the following facade interface:
boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType);
Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType);
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
package org.springframework.core.convert
interface ConversionService {
fun canConvert(sourceType: Class<*>, targetType: Class<*>): Boolean
fun <T> convert(source: Any, targetType: Class<T>): T
fun canConvert(sourceType: TypeDescriptor, targetType: TypeDescriptor): Boolean
fun convert(source: Any, sourceType: TypeDescriptor, targetType: TypeDescriptor): Any
}
----
@@ -1301,8 +1220,7 @@ provides a unified type conversion API for both SPIs.
The `Formatter` SPI to implement field formatting logic is simple and strongly typed. The
following listing shows the `Formatter` interface definition:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
package org.springframework.format;
@@ -1313,25 +1231,15 @@ following listing shows the `Formatter` interface definition:
`Formatter` extends from the `Printer` and `Parser` building-block interfaces. The
following listing shows the definitions of those two interfaces:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
public interface Printer<T> {
String print(T fieldValue, Locale locale);
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface Printer<T> {
fun print(fieldValue: T, locale: Locale): String
}
----
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
import java.text.ParseException;
@@ -1340,15 +1248,6 @@ following listing shows the definitions of those two interfaces:
T parse(String clientValue, Locale locale) throws ParseException;
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
interface Parser<T> {
@Throws(ParseException::class)
fun parse(clientValue: String, locale: Locale): T
}
----
To create your own `Formatter`, implement the `Formatter` interface shown earlier.
Parameterize `T` to be the type of object you wish to format -- for example,
@@ -1432,8 +1331,7 @@ Field formatting can be configured by field type or annotation. To bind
an annotation to a `Formatter`, implement `AnnotationFormatterFactory`. The following
listing shows the definition of the `AnnotationFormatterFactory` interface:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
package org.springframework.format;
@@ -1446,20 +1344,6 @@ listing shows the definition of the `AnnotationFormatterFactory` interface:
Parser<?> getParser(A annotation, Class<?> fieldType);
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
package org.springframework.format
interface AnnotationFormatterFactory<A : Annotation> {
val fieldTypes: Set<Class<*>>
fun getPrinter(annotation: A, fieldType: Class<*>): Printer<*>
fun getParser(annotation: A, fieldType: Class<*>): Parser<*>
}
----
To create an implementation:
. Parameterize A to be the field `annotationType` with which you wish to associate
@@ -1602,8 +1486,7 @@ for use with Spring's `DataBinder` and the Spring Expression Language (SpEL).
The following listing shows the `FormatterRegistry` SPI:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
package org.springframework.format;
@@ -1618,22 +1501,6 @@ The following listing shows the `FormatterRegistry` SPI:
void addFormatterForAnnotation(AnnotationFormatterFactory<?> factory);
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
package org.springframework.format
interface FormatterRegistry : ConverterRegistry {
fun addFormatterForFieldType(fieldType: Class<*>, printer: Printer<*>, parser: Parser<*>)
fun addFormatterForFieldType(fieldType: Class<*>, formatter: Formatter<*>)
fun addFormatterForFieldType(formatter: Formatter<*>)
fun addFormatterForAnnotation(factory: AnnotationFormatterFactory<*>)
}
----
As shown in the preceding listing, you can register formatters by field type or by annotation.
@@ -1651,8 +1518,7 @@ these rules once, and they are applied whenever formatting is needed.
`FormatterRegistrar` is an SPI for registering formatters and converters through the
FormatterRegistry. The following listing shows its interface definition:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
[source,java,indent=0,subs="verbatim,quotes"]
----
package org.springframework.format;
@@ -1661,16 +1527,6 @@ FormatterRegistry. The following listing shows its interface definition:
void registerFormatters(FormatterRegistry registry);
}
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
package org.springframework.format
interface FormatterRegistrar {
fun registerFormatters(registry: FormatterRegistry)
}
----
A `FormatterRegistrar` is useful when registering multiple related converters and
formatters for a given formatting category, such as date formatting. It can also be