Closed oyanyev closed 4 months ago
I dont think it is safe to relax "unique name" restriction.
APIs like findState(name: String, ...)
if based on it.
But possibly we can upgrade exportToPlantUml() function to accept converters/beautifiers for names. Converters/beautifiers are functions that take original state/transition/machine and return printable name.
So if your state names follow some schema like Block1.Group1.State1 you can simply drop the path and leave only State1 as printable name.
What do you think about it?
I have another idea:
displayName
or umlName
which can be defaulted to name
, but can be overriden and will be used solely in umls
yes, this is also possible, but this requires to change many APIs that are not related to the export feature.
What about plantUml itself, how it handles non unique names? I suppose it can have a problems with transitions directions?
PlantUml accepts titles for entities:
state InvalidBarcode as "Title"
transition.displayName is converted to arrow description without any problem
I can create PR, if you do not see that it might have side effects
looks this issue is related to https://github.com/nsk90/kstatemachine/issues/82
Some kind of meta data objects should cover both cases. I do not see any side effects, yes you can open a PR, thank you.
Started with PR and already have one question.
internal class CheckUniqueNamesVisitor : RecursiveVisitor {
...
private val transitionNames = mutableSetOf<String>()
...
override fun <E : Event> visit(transition: Transition<E>) {
transition.name?.let { check(transitionNames.add(it)) { "Transition name is not unique: $it" } }
}
}
transition.name visitor has no sense so far. Name is used only there and in export to uml. Can this check be omitted?
If check not applicable, then name
can be not unique and can be safely used for uml labels
it is also used here, so the name behaviour should not change.
/**
* Find transition by name. This might be used to start listening to transition after state machine setup.
*/
fun TransitionStateApi.findTransition(name: String) = transitions.find { it.name == name }
Added PR from my personal Github account. Should not break any existing code. https://github.com/nsk90/kstatemachine/pull/90
Published to local maven, added to my project - works.
Done in https://github.com/nsk90/kstatemachine/releases/tag/v0.27.0 Thanks, for the contribution!
Hi again!
I created a lot of states as objects and there is a lot of transition between them. There are a lot of use cases and I prefer not to reuse states between them and create a dedicated states even if they mean same, but scope is different. The state machine is complicated and is split into parts, each of them can be exported into uml.
To have a beautiful descriptive diagram, I heavily use names for states and transitions. And these names cannot be very long to fit diagram.
And here comes a problem when names are same and state machine won't start because of that. The simplest workaround is to add spaces to names, each time different number of them ))
Can states, transitions be somehow compared not by names? May be with
===