Skip to content

Commit

Permalink
feat(metamodel): Add incoming and outgoing StateTransitions to State
Browse files Browse the repository at this point in the history
Register and declare ReferenceSearchingAccessors for StateTransitions
leading into and out of a State:

- incoming_transitions to all *State classes except InitialPseudoState
- outgoing_transitions to all *State classes except FinalState and
  TerminatePseudoState

Refs: DSD-DBS#426
  • Loading branch information
chgio authored and Wuestengecko committed Sep 30, 2024
1 parent 0a808ae commit cae599b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
37 changes: 37 additions & 0 deletions capellambse/metamodel/capellacommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class State(AbstractStateMode):
m.ModelElement, "exit", aslist=m.MixedElementList
)

incoming_transitions = m.Accessor
outgoing_transitions = m.Accessor

functions: m.Accessor


Expand Down Expand Up @@ -161,6 +164,40 @@ def name(self) -> str: # type: ignore[override]
),
)

for cls in [
State,
Mode,
DeepHistoryPseudoState,
FinalState,
ForkPseudoState,
JoinPseudoState,
ShallowHistoryPseudoState,
TerminatePseudoState,
]:
m.set_accessor(
cls,
"incoming_transitions",
m.ReferenceSearchingAccessor(
StateTransition, "destination", aslist=m.ElementList
),
)
for cls in [
State,
Mode,
DeepHistoryPseudoState,
ForkPseudoState,
InitialPseudoState,
JoinPseudoState,
ShallowHistoryPseudoState,
]:
m.set_accessor(
cls,
"outgoing_transitions",
m.ReferenceSearchingAccessor(
StateTransition, "source", aslist=m.ElementList
),
)

m.set_accessor(
Region,
"states",
Expand Down
23 changes: 23 additions & 0 deletions tests/test_metamodel_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,26 @@ def test_state_attributes(
functions = getattr(state, attr)

assert functions == expected_functions


def test_state_outgoing_transitions(model: capellambse.MelodyModel) -> None:
state = model.by_uuid("1d03b3f0-f65b-451a-b9c7-b5df12b7bf4c")
expected_outgoing = [model.by_uuid("8f868115-f5fe-412c-b2a2-4adf92806fc6")]

assert state.outgoing_transitions == expected_outgoing


def test_initial_state_outgoing_transitions(
model: capellambse.MelodyModel,
) -> None:
initial_state = model.by_uuid("43932114-8ad4-4074-b2a9-b0d55b8d027b")
expected_outgoing = [model.by_uuid("4764929e-92b5-4400-a57c-432477275f48")]

assert initial_state.outgoing_transitions == expected_outgoing


def test_state_incoming_transitions(model: capellambse.MelodyModel) -> None:
state = model.by_uuid("1d03b3f0-f65b-451a-b9c7-b5df12b7bf4c")
expected_incoming = [model.by_uuid("8770f95c-ac4e-4d37-a690-0920aa22d3f9")]

assert state.incoming_transitions == expected_incoming

0 comments on commit cae599b

Please sign in to comment.