Break dependency between TestCompiler and AOT

This commit improves `TestCompiler` with a `with` function that allows
to customize a test compiler instance. Rather than `TestCompiler`
knowing about `TestGenerationContext`, the latter implements the
function so that it can be passed as is.

See gh-29175
This commit is contained in:
Stephane Nicoll
2022-09-20 14:24:22 +02:00
parent 2f84096af1
commit 4625e92eb8
17 changed files with 108 additions and 37 deletions

View File

@@ -176,7 +176,7 @@ class AutowiredAnnotationBeanRegistrationAotContributionTests {
});
this.generationContext.writeGeneratedContent();
TestCompiler.forSystem().withFiles(this.generationContext.getGeneratedFiles()).compile(compiled ->
TestCompiler.forSystem().with(this.generationContext).compile(compiled ->
result.accept(compiled.getInstance(BiFunction.class), compiled));
}

View File

@@ -425,7 +425,7 @@ class BeanDefinitionMethodGeneratorTests {
.addCode("return $L;", methodInvocation).build());
});
this.generationContext.writeGeneratedContent();
TestCompiler.forSystem().withFiles(this.generationContext.getGeneratedFiles()).compile(compiled ->
TestCompiler.forSystem().with(this.generationContext).compile(compiled ->
result.accept((RootBeanDefinition) compiled.getInstance(Supplier.class).get(), compiled));
}

View File

@@ -429,7 +429,7 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
.addStatement("return beanDefinition").build());
});
this.generationContext.writeGeneratedContent();
TestCompiler.forSystem().withFiles(this.generationContext.getGeneratedFiles()).compile(compiled -> {
TestCompiler.forSystem().with(this.generationContext).compile(compiled -> {
RootBeanDefinition suppliedBeanDefinition = (RootBeanDefinition) compiled
.getInstance(Supplier.class).get();
result.accept(suppliedBeanDefinition, compiled);

View File

@@ -76,7 +76,7 @@ class BeanDefinitionPropertyValueCodeGeneratorTests {
.returns(Object.class).addStatement("return $L", generatedCode).build());
});
generationContext.writeGeneratedContent();
TestCompiler.forSystem().withFiles(generationContext.getGeneratedFiles()).compile(compiled ->
TestCompiler.forSystem().with(generationContext).compile(compiled ->
result.accept(compiled.getInstance(Supplier.class).get(), compiled));
}

View File

@@ -167,7 +167,7 @@ class BeanRegistrationsAotContributionTests {
.build());
});
this.generationContext.writeGeneratedContent();
TestCompiler.forSystem().withFiles(this.generationContext.getGeneratedFiles()).compile(compiled ->
TestCompiler.forSystem().with(this.generationContext).compile(compiled ->
result.accept(compiled.getInstance(Consumer.class), compiled));
}

View File

@@ -317,7 +317,7 @@ class InstanceSupplierCodeGeneratorTests {
.addStatement("return $L", generatedCode).build());
});
this.generationContext.writeGeneratedContent();
TestCompiler.forSystem().withFiles(this.generationContext.getGeneratedFiles()).compile(compiled ->
TestCompiler.forSystem().with(this.generationContext).compile(compiled ->
result.accept((InstanceSupplier<?>) compiled.getInstance(Supplier.class).get(), compiled));
}