Migrate AOT tests to use GeneratedClasses and refine/polish AOT APIs

Migrate all AOT tests to make use of `GeneratedClasses` rather than
directly generating Java files. This commit also refines and polishes
AOT APIs to being greater consistency.

Specifically:

	- The `MethodGenerator` interface has been removed in favor of
	  working directly with `GeneratedMethods`.
	- The visibility of several constructors and methods has been
	  reduced to package-private.
	- The `using(...)` and `builder` methods have been removed in
	  favor of setting the `Consumer` callbacks directly as
	  constructor arguments.
	- Variable names for builders are now named `type` or `method`
	  depending on what they're building.

Closes gh-28831
This commit is contained in:
Phillip Webb
2022-06-23 13:48:38 -07:00
parent 4f8516e2c3
commit f2d31b7a20
51 changed files with 1255 additions and 1399 deletions

View File

@@ -152,30 +152,30 @@ class ScopedProxyBeanRegistrationAotProcessor
Executable constructorOrFactoryMethod,
boolean allowDirectSupplierShortcut) {
GeneratedMethod method = beanRegistrationCode.getMethodGenerator()
.generateMethod("get", "scopedProxyInstance").using(builder -> {
GeneratedMethod generatedMethod = beanRegistrationCode.getMethods()
.add("getScopedProxyInstance", method -> {
Class<?> beanClass = this.targetBeanDefinition.getResolvableType()
.toClass();
builder.addJavadoc(
method.addJavadoc(
"Create the scoped proxy bean instance for '$L'.",
this.registeredBean.getBeanName());
builder.addModifiers(Modifier.PRIVATE, Modifier.STATIC);
builder.returns(beanClass);
builder.addParameter(RegisteredBean.class,
method.addModifiers(Modifier.PRIVATE, Modifier.STATIC);
method.returns(beanClass);
method.addParameter(RegisteredBean.class,
REGISTERED_BEAN_PARAMETER_NAME);
builder.addStatement("$T factory = new $T()",
method.addStatement("$T factory = new $T()",
ScopedProxyFactoryBean.class,
ScopedProxyFactoryBean.class);
builder.addStatement("factory.setTargetBeanName($S)",
method.addStatement("factory.setTargetBeanName($S)",
this.targetBeanName);
builder.addStatement(
method.addStatement(
"factory.setBeanFactory($L.getBeanFactory())",
REGISTERED_BEAN_PARAMETER_NAME);
builder.addStatement("return ($T) factory.getObject()",
method.addStatement("return ($T) factory.getObject()",
beanClass);
});
return CodeBlock.of("$T.of($T::$L)", InstanceSupplier.class,
beanRegistrationCode.getClassName(), method.getName());
beanRegistrationCode.getClassName(), generatedMethod.getName());
}
}