State Diagrams and Format Selection

Hello,

currently I’m trying to replicate the examples given in the OMG document:

Here on page 53, there is an example about the ‘Transition Guards and Effect Actions’ in State Diagrams.

The original example is as follows:

action performSelfTest{in vehicle : Vehicle;}

state def VehicleStates {
    in operatingVehicle : Vehicle;
    in controller : VehicleController; }

state vehicleStates : VehicleStates {
    in operatingVehicle : Vehicle;
    in controller : VehicleController;

    entry; then off;

    state off;
    accept VehicleStartSignal
        if operatingVehicle.brakePedalDepressed
        do send new ControllerStartSignal() to controller
        then starting;

    state starting;
    accept VehicleOnSignal
    then on;

    state on { … }
    accept VehicleOffSignal
    then off;
}

As it is an example, some definitions are missing:

  • part def Vehicle with action brakePedalDepressed defined as Boolean for the guard
  • part def VehicleController
  • action def ControllerStartSignal
  • action def VehicleStartSignal
  • action def VehicleOnSignal
  • action def VehicleOffSignal

Once included and formated (using “Format Selection”), the code in syside will look like this:

// Definitions not included in original example
part def Vehicle {action brakePedalDepressed : Boolean;}
part def VehicleController;
action def ControllerStartSignal;
action def VehicleStartSignal;
action def VehicleOnSignal;
action def VehicleOffSignal;

// Original example formated in syside
action performSelfTest { in vehicle : Vehicle; }
state def VehicleStates {
    in operatingVehicle : Vehicle;
    in controller : VehicleController;
}
state vehicleStates : VehicleStates {
    in operatingVehicle : Vehicle;
    in controller : VehicleController;
    entry;
    then off;
    state off;

    transition
        off
        accept VehicleStartSignal
        if operatingVehicle.brakePedalDepressed
            do send new ControllerStartSignal() to controller
        then starting;
    state starting;
    transition starting accept VehicleOnSignal then on;
    state on;
    transition on accept VehicleOffSignal then off;

What it is interesting to me is that the formatting added the word “transition“ that were not included in the original code.

My question:

Is there a way to control what the “Format Selection“ is adding to the code?

Acc. to same document (page 49), one can use a “shorthand for transition a whose source is the lexically previous state”.

Many thanks in advance!

Thanks for the report. Formatter should try to preserve original tokens by default so I would consider this a bug. I will have a look.

Fixed for the next release. In the meantime, formatter can be disabled with // syside-format ignore declaration which applies to the subtree it is attached to, e.g.

    // syside-format ignore
    accept VehicleStartSignal
        if operatingVehicle.brakePedalDepressed
        do send new ControllerStartSignal() to controller
        then starting;

Hello Daumantas,

many thanks for the quick repply.

The comment “// syside-format ignore” is working properly on my side, with just one small detail: It is not indenting the 3 next lines after "accept VehicleStartSignal” see highlighted text on the screenshots:

And:

So it keeps the below lines on its original position. Just in case it helps you with the debugging.

Saludos!

That’s intended. The directive disables formatting for the subtree contents - they are printed as they were written. Only the first line is indented to match indentation level of the current scope.