[tree generators] Add a method for configuring all leaf builders

It will be used in the new Swift IR tree that will be added in the next
commit.
This commit is contained in:
Sergej Jaskiewicz
2023-12-06 13:07:33 +01:00
committed by Space Team
parent 12905858fc
commit 39c84bca06
@@ -127,6 +127,9 @@ abstract class AbstractBuilderConfigurator<Element, Implementation, BuilderField
}
}
private val allLeafBuilders: List<LeafBuilder<BuilderField, Element, Implementation>>
get() = elements.flatMap { it.allImplementations }.mapNotNull { it.builder }
/**
* Allows to batch-apply [config] to certain fields in _all_ the builders that satisfy the given
* [builderPredicate].
@@ -143,8 +146,7 @@ abstract class AbstractBuilderConfigurator<Element, Implementation, BuilderField
fieldPredicate: ((BuilderField) -> Boolean)? = null,
config: LeafBuilderConfigurationContext.(field: String) -> Unit
) {
val builders = elements.flatMap { it.allImplementations }.mapNotNull { it.builder }
for (builder in builders) {
for (builder in allLeafBuilders) {
if (builderPredicate != null && !builderPredicate(builder)) continue
if (!builder.allFields.any { it.name == field }) continue
if (fieldPredicate != null && !fieldPredicate(builder[field])) continue
@@ -152,6 +154,17 @@ abstract class AbstractBuilderConfigurator<Element, Implementation, BuilderField
}
}
/**
* Allows to batch-apply [config] to _all_ leaf builders.
*
* @param config The configuration block. See [LeafBuilderConfigurationContext]'s documentation for description of its DSL methods.
*/
protected fun configureAllLeafBuilders(config: LeafBuilderConfigurationContext.() -> Unit) {
for (builder in allLeafBuilders) {
LeafBuilderConfigurationContext(builder).config()
}
}
/**
* A DSL for configuring one or more intermediate or leaf builder classes.
*/