withChild

fun withChild(targetProperty: KMutableProperty1<*, *>, sourceAccessor: Source.() -> Any?, scopedToType: KClass<*>): NodeTransformer<Source, Output>

Specify how to convert a child. The value obtained from the conversion could either be used as a constructor parameter when instantiating the parent, or be used to set the value after the parent has been instantiated.

Example using the scopedToType parameter:

    on.registerNodeTransformer(SASParser.DatasetOptionContext::class) { ctx ->
when {
...
}
}
.withChild(SASParser.DatasetOptionContext::macroStatementStrict, ComputedDatasetOption::computedWith, ComputedDatasetOption::class)
.withChild(SASParser.DatasetOptionContext::variableList, DropDatasetOption::variables, DropDatasetOption::class)
.withChild(SASParser.DatasetOptionContext::variableList, KeepDatasetOption::variables, KeepDatasetOption::class)
.withChild(SASParser.DatasetOptionContext::variableList, InDatasetOption::variables, InDatasetOption::class)
.withChild("indexDatasetOption.variables", IndexDatasetOption::variables, IndexDatasetOption::class)

Please note that we cannot merge this method with the variant without the type (making the type optional), as it would not permit to specify the lambda outside the list of method parameters.


fun withChild(targetProperty: KMutableProperty1<*, *>, sourceAccessor: Source.() -> Any?): NodeTransformer<Source, Output>
fun <Target : Any, Child : Any> withChild(get: (Source) -> Any?, set: (Target, Child?) -> Unit?, name: String, scopedToType: KClass<*>? = null): NodeTransformer<Source, Output>

Specify how to convert a child. The value obtained from the conversion could either be used as a constructor parameter when instantiating the parent, or be used to set the value after the parent has been instantiated.


fun withChild(targetProperty: KProperty1<*, *>, sourceAccessor: Source.() -> Any?): NodeTransformer<Source, Output>

Specify how to convert a child. The value obtained from the conversion can only be used as a constructor parameter when instantiating the parent. It cannot be used to set the value after the parent has been instantiated, because the property is not mutable.


fun withChild(targetProperty: KProperty1<*, *>, sourceAccessor: Source.() -> Any?, scopedToType: KClass<*>): NodeTransformer<Source, Output>

Specify how to convert a child. The value obtained from the conversion can only be used as a constructor parameter when instantiating the parent. It cannot be used to set the value after the parent has been instantiated, because the property is not mutable.

Please note that we cannot merge this method with the variant without the type (making the type optional), as it would not permit to specify the lambda outside the list of method parameters.