Browse Source

Introduce complete DefaultGenerationContext constructor

Prior to this commit, it was possible to create a DefaultGenerationContext
based on a ClassNameGenerator and GeneratedFiles; however, there was no way
to create a DefaultGenerationContext that reused an existing RuntimeHints
instance which is necessary in certain use cases -- for example, in the
TestContext framework where multiple GenerationContexts are created
based on shared instances of GeneratedFiles and RuntimeHints.

This commit addresses this by introducing a public
DefaultGenerationContext(ClassNameGenerator,GeneratedFiles,RuntimeHints)
constructor.
pull/28958/head
Sam Brannen 2 years ago
parent
commit
9ab046bdbb
  1. 17
      spring-core/src/main/java/org/springframework/aot/generate/DefaultGenerationContext.java
  2. 4
      spring-core/src/test/java/org/springframework/aot/generate/DefaultGenerationContextTests.java

17
spring-core/src/main/java/org/springframework/aot/generate/DefaultGenerationContext.java

@ -32,6 +32,7 @@ import org.springframework.util.Assert; @@ -32,6 +32,7 @@ import org.springframework.util.Assert;
*
* @author Phillip Webb
* @author Stephane Nicoll
* @author Sam Brannen
* @since 6.0
*/
public class DefaultGenerationContext implements GenerationContext {
@ -53,7 +54,21 @@ public class DefaultGenerationContext implements GenerationContext { @@ -53,7 +54,21 @@ public class DefaultGenerationContext implements GenerationContext {
* @param generatedFiles the generated files
*/
public DefaultGenerationContext(ClassNameGenerator classNameGenerator, GeneratedFiles generatedFiles) {
this(new GeneratedClasses(classNameGenerator), generatedFiles, new RuntimeHints());
this(classNameGenerator, generatedFiles, new RuntimeHints());
}
/**
* Create a new {@link DefaultGenerationContext} instance backed by the
* specified {@link ClassNameGenerator}, {@link GeneratedFiles}, and
* {@link RuntimeHints}.
* @param classNameGenerator the naming convention to use for generated
* class names
* @param generatedFiles the generated files
* @param runtimeHints the runtime hints
*/
public DefaultGenerationContext(ClassNameGenerator classNameGenerator, GeneratedFiles generatedFiles,
RuntimeHints runtimeHints) {
this(new GeneratedClasses(classNameGenerator), generatedFiles, runtimeHints);
}
/**

4
spring-core/src/test/java/org/springframework/aot/generate/DefaultGenerationContextTests.java

@ -66,8 +66,8 @@ class DefaultGenerationContextTests { @@ -66,8 +66,8 @@ class DefaultGenerationContextTests {
@Test
void createWhenGeneratedClassesIsNullThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new DefaultGenerationContext(null, this.generatedFiles,
this.runtimeHints))
.isThrownBy(() -> new DefaultGenerationContext((GeneratedClasses) null,
this.generatedFiles, this.runtimeHints))
.withMessage("'generatedClasses' must not be null");
}

Loading…
Cancel
Save