KStateMachine / kstatemachine

KStateMachine is a Kotlin DSL library for creating state machines and statecharts.
https://kstatemachine.github.io/kstatemachine/
Boost Software License 1.0
339 stars 19 forks source link

Safe state and transition naming for uml #90

Closed ayanyev closed 4 months ago

preetb123 commented 5 months ago

To get rid of this problem I wrote below code. @ayanyev @nsk90


private fun printStateMachine() {
  var plantUmlDiagramString = machine?.exportToPlantUmlBlocking()!!
  plantUmlDiagramString = generatePlantUmlString(plantUmlDiagramString, machine?.states!!)
  println(plantUmlDiagramString)
}

// FIXME add cases for conditional transition & guards
fun generatePlantUmlString(plantUmlStr: String, states: Set<IState>): String {
  var str = plantUmlStr
  for (state in states) {
    if (state.states.isNotEmpty()) {
      str = generatePlantUmlString(str, state.states)
    }
    val stateName = state.javaClass.canonicalName?.substringAfterLast(".")
    val hashCode = state.hashCode()
    str = str.replace("State$hashCode", stateName!!)
  }
  return str
}
oyanyev commented 4 months ago

Also removed metaInfo from state creation functions, left it as construction parameter of base and default implementations and made it mutable in IState, so it can be overriden in StateBlock

sonarcloud[bot] commented 4 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud