mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Suppress warnings in JsonMixin AOT-generated code
Closes gh-48564
This commit is contained in:
+9
-2
@@ -33,6 +33,7 @@ import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
|
||||
import org.springframework.beans.factory.aot.BeanRegistrationCode;
|
||||
import org.springframework.beans.factory.aot.BeanRegistrationCodeFragments;
|
||||
import org.springframework.beans.factory.aot.BeanRegistrationCodeFragmentsDecorator;
|
||||
import org.springframework.beans.factory.aot.CodeWarnings;
|
||||
import org.springframework.beans.factory.support.RegisteredBean;
|
||||
import org.springframework.javapoet.ClassName;
|
||||
import org.springframework.javapoet.CodeBlock;
|
||||
@@ -87,9 +88,15 @@ class JsonMixinModuleEntriesBeanRegistrationAotProcessor implements BeanRegistra
|
||||
method.addModifiers(Modifier.PRIVATE, Modifier.STATIC);
|
||||
method.returns(BEAN_TYPE);
|
||||
CodeBlock.Builder code = CodeBlock.builder();
|
||||
code.add("return $T.create(", JsonMixinModuleEntries.class).beginControlFlow("(mixins) ->");
|
||||
entries.doWithEntry(this.classLoader, (type, mixin) -> addEntryCode(code, type, mixin));
|
||||
CodeWarnings codeWarnings = new CodeWarnings();
|
||||
codeWarnings.detectDeprecation(BEAN_TYPE);
|
||||
code.add("return $T.create(", BEAN_TYPE).beginControlFlow("(mixins) ->");
|
||||
entries.doWithEntry(this.classLoader, (type, mixin) -> {
|
||||
codeWarnings.detectDeprecation(type, mixin);
|
||||
addEntryCode(code, type, mixin);
|
||||
});
|
||||
code.endControlFlow(")");
|
||||
codeWarnings.suppress(method);
|
||||
method.addCode(code.build());
|
||||
});
|
||||
return generatedMethod.toMethodReference().toCodeBlock();
|
||||
|
||||
+11
-8
@@ -109,14 +109,17 @@ class JsonMixinModuleEntriesBeanRegistrationAotProcessorTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
private void compile(BiConsumer<GenericApplicationContext, Compiled> result) {
|
||||
ClassName className = processAheadOfTime();
|
||||
TestCompiler.forSystem().with(this.generationContext).compile((compiled) -> {
|
||||
GenericApplicationContext freshApplicationContext = new GenericApplicationContext();
|
||||
ApplicationContextInitializer<GenericApplicationContext> initializer = compiled
|
||||
.getInstance(ApplicationContextInitializer.class, className.toString());
|
||||
initializer.initialize(freshApplicationContext);
|
||||
freshApplicationContext.refresh();
|
||||
result.accept(freshApplicationContext, compiled);
|
||||
});
|
||||
TestCompiler.forSystem()
|
||||
.withCompilerOptions("-Xlint:all", "-Werror")
|
||||
.with(this.generationContext)
|
||||
.compile((compiled) -> {
|
||||
GenericApplicationContext freshApplicationContext = new GenericApplicationContext();
|
||||
ApplicationContextInitializer<GenericApplicationContext> initializer = compiled
|
||||
.getInstance(ApplicationContextInitializer.class, className.toString());
|
||||
initializer.initialize(freshApplicationContext);
|
||||
freshApplicationContext.refresh();
|
||||
result.accept(freshApplicationContext, compiled);
|
||||
});
|
||||
}
|
||||
|
||||
private void registerEntries(Class<?>... basePackageClasses) {
|
||||
|
||||
Reference in New Issue
Block a user