Sort children during generation
I want to sort children during the generation flow. At the moment I'm using the sort method to create a new sorted sequence (sorted = parentNode.children.sort({...}, asc)). Afterwards I clear the original sequence (parentNode.children.clear) and add all elements from the sorted sequence (parentNode.children.addAll(sorted)).
Even if this hack sounds quite dirty, it will do its job and the generated code is correct. Unfortunately references to the sorted elements break for a short period during generation. This results in flood of error messages like this:
Even if this hack sounds quite dirty, it will do its job and the generated code is correct. Unfortunately references to the sorted elements break for a short period during generation. This results in flood of error messages like this:
[jetbrains.mps.smodel.StaticReference] couldn't resolve reference 'target' from SignalReference ... -- target model 'r:50633910-27cb-4832-90d8-4ef14916a957(hml.sandbox.types@8_0)' doesn't contain node with id=3800155958210691946Is there any way to sort the children in place without clearing the list?
Please sign in to leave a comment.
This is a bad practice, which will not work in future.
Instead, you can:
1) sort input nodes everywhere you need the sequence to be sorted
2) add an additional generation step, on which the collection will be sorted
3) make a "pre-process mapping script", which can change input model, and sort there
Do I understand you right that you list alternatives?
I use the third one at the moment. The script looks like this:
Is this what you would recommend?
Filed: http://youtrack.jetbrains.com/issue/MPS-19767