Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Commit

Permalink
Use default entry when history is empty (#2383)
Browse files Browse the repository at this point in the history
* Add test case for entering through history state without initialization (#2371)

* Use default entry when history entry defines no outgoing transition and history is empty (#2371)
  • Loading branch information
tkutz committed Oct 31, 2018
1 parent c45e3f0 commit b5795dd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
Expand Up @@ -247,24 +247,11 @@ class ReactionBuilder {

def defineReaction(Entry e) {

// first get the mapped control flow element the entry
// first get the mapped control flow element for the entry
val execEntry = e.create

// if the entry defines a transition then we will derive the entry transition sequence
var Sequence entryTransSeq = null
val entryTransitionEffect = e?.transition?.effect
val target = e.target.create
val targetEnterSequence = if (target !== null && e.outgoingTransitions.size > 0) { e.outgoingTransitions.mapToStateConfigurationEnterSequence } else null

if ( entryTransitionEffect !== null || targetEnterSequence !== null) {
entryTransSeq = sexecFactory.createSequence
if (entryTransitionEffect !== null) {
entryTransSeq.steps += entryTransitionEffect.mapEffect
}
if (targetEnterSequence !== null) {
entryTransSeq.steps += targetEnterSequence
}
}
var Sequence entryTransSeq = e.createEntrySequence

// we add behavior to the already created react sequence from defineStateEnterSequence(Entry)
val seq = execEntry.reactSequence
Expand All @@ -281,6 +268,9 @@ class ReactionBuilder {
entryStep.deep = false
entryStep.region = (e.eContainer as Region).create

// if history does not have outgoing transition => take the default entry as fall-back
if (entryTransSeq === null) entryTransSeq = e.parentRegion.entry.createEntrySequence

if (entryTransSeq !== null) entryStep.initialStep = entryTransSeq

entryStep.historyStep = (e.eContainer as Region).create.shallowEnterSequence.newCall
Expand All @@ -293,12 +283,32 @@ class ReactionBuilder {
entryStep.region = (e.eContainer as Region).create
entryStep.deep = true

if (entryTransSeq !== null) entryStep.initialStep = entryTransSeq
// if history does not have outgoing transition => take the default entry as fall-back
if (entryTransSeq === null) entryTransSeq = e.parentRegion.entry.createEntrySequence

if (entryTransSeq !== null) entryStep.initialStep = entryTransSeq

entryStep.historyStep = (e.eContainer as Region).create.deepEnterSequence.newCall

seq.steps += entryStep
}
}

def protected createEntrySequence(Entry e) {
var Sequence entryTransSeq = null
val entryTransitionEffect = e?.transition?.effect
val target = e.target.create
val targetEnterSequence = if (target !== null && e.outgoingTransitions.size > 0) { e.outgoingTransitions.mapToStateConfigurationEnterSequence } else null

if ( entryTransitionEffect !== null || targetEnterSequence !== null) {
entryTransSeq = sexecFactory.createSequence
if (entryTransitionEffect !== null) {
entryTransSeq.steps += entryTransitionEffect.mapEffect
}
if (targetEnterSequence !== null) {
entryTransSeq.steps += targetEnterSequence
}
}
entryTransSeq
}
}
Expand Up @@ -57,6 +57,14 @@ public void enterDThroughHistory() throws Exception {
timer.timeLeap(getCyclePeriod());
assertTrue(isStateActive("D"));
}
@Test
public void enterThroughHistoryWithoutInit() throws Exception {
interpreter.enter();
assertTrue(isStateActive("A"));
raiseEvent("toHistory");
timer.timeLeap(getCyclePeriod());
assertTrue(isStateActive("C"));
}
public void init() throws Exception {
interpreter.enter();
assertTrue(isStateActive("A"));
Expand Down
Expand Up @@ -39,6 +39,15 @@ testclass HistoryWithoutInitialStep for statechart HistoryWithoutInitialStep {
proceed 1 cycle
assert active(HistoryWithoutInitialStep.main_region.B.r1.D)
}

@Test
operation enterThroughHistoryWithoutInit(){
enter
assert active(HistoryWithoutInitialStep.main_region.A)
raise toHistory
proceed 1 cycle
assert active(HistoryWithoutInitialStep.main_region.B.r1.C)
}

operation init(){
enter
Expand Down

0 comments on commit b5795dd

Please sign in to comment.