Merge branch '6.0.x'

This commit is contained in:
Sam Brannen
2023-07-15 14:45:52 +02:00
3 changed files with 34 additions and 31 deletions

View File

@@ -78,7 +78,7 @@ public class DefaultGenerationContext implements GenerationContext {
* @param generatedFiles the generated files
* @param runtimeHints the runtime hints
*/
protected DefaultGenerationContext(GeneratedClasses generatedClasses,
DefaultGenerationContext(GeneratedClasses generatedClasses,
GeneratedFiles generatedFiles, RuntimeHints runtimeHints) {
Assert.notNull(generatedClasses, "'generatedClasses' must not be null");
@@ -90,9 +90,18 @@ public class DefaultGenerationContext implements GenerationContext {
this.runtimeHints = runtimeHints;
}
private DefaultGenerationContext(DefaultGenerationContext existing, String name) {
int sequence = existing.sequenceGenerator.computeIfAbsent(name, key -> new AtomicInteger()).getAndIncrement();
String featureName = (sequence > 0 ? name + sequence : name);
/**
* Create a new {@link DefaultGenerationContext} instance based on the
* supplied {@code existing} context and feature name.
* @param existing the existing context upon which to base the new one
* @param featureName the feature name to use
* @since 6.0.12
*/
protected DefaultGenerationContext(DefaultGenerationContext existing, String featureName) {
int sequence = existing.sequenceGenerator.computeIfAbsent(featureName, key -> new AtomicInteger()).getAndIncrement();
if (sequence > 0) {
featureName += sequence;
}
this.sequenceGenerator = existing.sequenceGenerator;
this.generatedClasses = existing.generatedClasses.withFeatureNamePrefix(featureName);
this.generatedFiles = existing.generatedFiles;

View File

@@ -176,19 +176,6 @@ public class GeneratedClasses {
return addForFeatureComponent(featureName, ClassName.get(targetComponent), type);
}
/**
* Create a new {@link GeneratedClasses} instance using the specified feature
* name prefix to qualify generated class names for a dedicated round of code
* generation.
* @param featureNamePrefix the feature name prefix to use
* @return a new instance for the specified feature name prefix
* @since 6.0.12
*/
public GeneratedClasses withFeatureNamePrefix(String featureNamePrefix) {
return new GeneratedClasses(this.classNameGenerator.withFeatureNamePrefix(featureNamePrefix),
this.classes, this.classesByOwner);
}
private GeneratedClass createAndAddGeneratedClass(String featureName,
@Nullable ClassName targetComponent, Consumer<TypeSpec.Builder> type) {
@@ -212,6 +199,18 @@ public class GeneratedClasses {
}
}
/**
* Create a new {@link GeneratedClasses} instance using the specified feature
* name prefix to qualify generated class names for a dedicated round of code
* generation.
* @param featureNamePrefix the feature name prefix to use
* @return a new instance for the specified feature name prefix
*/
GeneratedClasses withFeatureNamePrefix(String featureNamePrefix) {
return new GeneratedClasses(this.classNameGenerator.withFeatureNamePrefix(featureNamePrefix),
this.classes, this.classesByOwner);
}
private record Owner(String featureNamePrefix, String featureName, @Nullable ClassName target) {
}