Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eclipse Projects
Eclipse eTrice™
Eclipse eTrice
Commits
977cdf8e
Commit
977cdf8e
authored
Apr 13, 2022
by
Eyrak Paen-Rochlitz
Browse files
Fixed typos and uncaught exceptions in FSMValidationUtil
parent
ec7b2714
Changes
5
Hide whitespace changes
Inline
Side-by-side
plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/validation/FSMValidationUtil.java
View file @
977cdf8e
...
...
@@ -148,10 +148,10 @@ public class FSMValidationUtil extends FSMValidationUtilXtend {
else
if
(
src
instanceof
TrPointTerminal
)
{
TrPoint
srcTP
=
((
TrPointTerminal
)
src
).
getTrPoint
();
if
(
srcTP
.
eIsProxy
())
{
return
Result
.
error
(
"transition source not found"
,
trans
,
FSMPackage
.
eINSTANCE
.
getTrPointTerminal_TrPoint
(),
0
);
return
Result
.
error
(
"transition source not found"
,
src
,
FSMPackage
.
eINSTANCE
.
getTrPointTerminal_TrPoint
(),
0
);
}
if
(
srcTP
instanceof
ExitPoint
)
return
Result
.
error
(
"exit point can not be transition source"
,
trans
,
FSMPackage
.
eINSTANCE
.
getTrPointTerminal_TrPoint
(),
0
);
return
Result
.
error
(
"exit point can not be transition source"
,
src
,
FSMPackage
.
eINSTANCE
.
getTrPointTerminal_TrPoint
(),
0
);
// TransitionPoint and EntryPoint are valid
if
(
srcTP
instanceof
EntryPoint
)
{
for
(
Transition
t
:
sg
.
getTransitions
())
{
...
...
@@ -205,7 +205,7 @@ public class FSMValidationUtil extends FSMValidationUtilXtend {
}
else
if
(
src
instanceof
StateTerminal
)
{
if
(((
StateTerminal
)
src
).
getState
().
eIsProxy
())
{
return
Result
.
error
(
"transition
target
not found"
,
src
,
FSMPackage
.
eINSTANCE
.
getStateTerminal_State
(),
0
);
return
Result
.
error
(
"transition
source
not found"
,
src
,
FSMPackage
.
eINSTANCE
.
getStateTerminal_State
(),
0
);
}
}
...
...
tests/org.eclipse.etrice.core.room.tests/models/validator/transitions_invalid_entry_exit.room
0 → 100644
View file @
977cdf8e
RoomModel transitions_invalid_entry_exit {
ActorClass ac {
Structure {
Port p: pc
}
Behavior {
StateMachine {
State s1 {
subgraph {
State s11
EntryPoint enp
Transition init: initial -> s11
Transition t11: s11 -> my enp { triggers {<msg2:p>} } // Invalid target trPoint terminal
}
}
State s2 {
subgraph {
State s21
ExitPoint exp
Transition init: initial -> s21
Transition t21: my exp -> s21 // Invalid source trPoint terminal
}
}
EntryPoint enp
ExitPoint exp
Transition init: initial -> s1
Transition t1: s1 -> s2 { triggers{<msg:p>} }
Transition t2: enp of s1 -> s2 // source substate trPoint type invalid
Transition t3: s2 -> exp of s2 { triggers {<msg2:p>} } // target substate trPoint type invalid
}
}
}
ProtocolClass pc {
incoming {
Message msg
Message msg2
}
outgoing {
Message msg3
}
}
}
\ No newline at end of file
tests/org.eclipse.etrice.core.room.tests/models/validator/transitions_missing_source.room
0 → 100644
View file @
977cdf8e
RoomModel transitions_missing_source {
ActorClass ac {
Structure {
Port p: pc
}
Behavior {
StateMachine {
State s1
State s2 {
subgraph {
State s21
ExitPoint exp
Transition init: initial -> s21
Transition toExit: s21 -> my exp {
triggers { <msg: p> }
}
}
}
State s3
TransitionPoint trp
Transition init: initial -> s1
Transition t1: s1 -> s2 {triggers { <msg: p> }}
Transition t2: x -> s2 {triggers { <msg2: p> }} // error: missing StateTerminal source
Transition t3: exp of s2 -> s3
Transition t4: x of s2 -> s3 // error: missing SubStateTrPointTerminal source
Transition t5: my trp -> s1 {triggers { <msg: p> }}
Transition t6: my x -> s2 // error: missing TrPointTerminal
}
}
}
ProtocolClass pc {
incoming {
Message msg
Message msg2
}
outgoing {
Message msg3
}
}
}
\ No newline at end of file
tests/org.eclipse.etrice.core.room.tests/models/validator/transitions_missing_target.room
0 → 100644
View file @
977cdf8e
RoomModel transitions_missing_target {
ActorClass ac {
Structure {
Port p: pc
}
Behavior {
StateMachine {
State s1
State s2 {
subgraph {
State s21
EntryPoint enp
ExitPoint exp
Transition fromEntry: my enp -> s21
Transition toExit: s21 -> my exp {triggers { <msg: p> }}
Transition t21: s21 -> my x {triggers { <msg2: p> }} // error: missing TrPointTerminal
}
}
State s3
Transition init: initial -> s1
Transition t1: s1 -> s2 {triggers { <msg: p> }}
Transition t2: s1 -> x {triggers { <msg2: p> }} // error: missing StateTerminal source
Transition t3: s3 -> enp of s2 {triggers { <msg: p> }}
Transition t4: s3 -> x of s2 {triggers { <msg2: p> }} // error: missing SubStateTrPointTerminal source
}
}
}
ProtocolClass pc {
incoming {
Message msg
Message msg2
}
outgoing {
Message msg3
}
}
}
\ No newline at end of file
tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/FSMValidatorTest.xtend
0 → 100644
View file @
977cdf8e
package
org
.
eclipse
.
etrice
.
core
import
java
.
util
.
Set
import
org
.
eclipse
.
emf
.
common
.
util
.
Diagnostic
import
org
.
eclipse
.
emf
.
ecore
.
EObject
import
org
.
eclipse
.
emf
.
ecore
.
EStructuralFeature
import
org
.
eclipse
.
etrice
.
core
.
fsm
.
fSM
.
FSMPackage
import
org
.
eclipse
.
etrice
.
core
.
fsm
.
fSM
.
InitialTransition
import
org
.
eclipse
.
etrice
.
core
.
fsm
.
fSM
.
NonInitialTransition
import
org
.
eclipse
.
etrice
.
core
.
fsm
.
fSM
.
StateGraph
import
org
.
eclipse
.
etrice
.
core
.
room
.
ActorClass
import
org
.
eclipse
.
etrice
.
core
.
room
.
RoomModel
import
org
.
eclipse
.
xtend
.
lib
.
annotations
.
Data
import
org
.
eclipse
.
xtext
.
validation
.
FeatureBasedDiagnostic
import
org
.
junit
.
Assert
import
org
.
junit
.
Before
import
org
.
junit
.
Test
class
FSMValidatorTest
extends
TestBase
{
extension
FSMPackage
fsmPackage
=
FSMPackage
.
eINSTANCE
@
Before
def
void
setUp
()
{
prepare
(
CoreTestsActivator
.
getInstance
().
getBundle
())
}
@
Test
def
void
transitionMissingSource
()
{
val
resource
=
getResource
(
'validator/transitions_missing_source.room'
)
val
model
=
resource
.
contents
.
head
as
RoomModel
val
actorClass
=
model
.
roomClasses
.
filter
(
ActorClass
).
head
val
stateMachine
=
actorClass
.
stateMachine
val
diag
=
getDiag
(
model
)
assertSetEquals
(
newHashSet
(
"transition source not found"
->
new
DiagRef
(
stateMachine
.
transition
(
"t2"
).
from
,
stateTerminal_State
,
0
),
"transition source not found"
->
new
DiagRef
(
stateMachine
.
transition
(
"t4"
).
from
,
subStateTrPointTerminal_TrPoint
,
0
),
"transition source not found"
->
new
DiagRef
(
stateMachine
.
transition
(
"t6"
).
from
,
trPointTerminal_TrPoint
,
0
)
),
diag
.
featureBasedDiagnosticsSummary
)
}
@
Test
def
void
transitionMissingTarget
()
{
val
resource
=
getResource
(
'validator/transitions_missing_target.room'
)
val
model
=
resource
.
contents
.
head
as
RoomModel
val
actorClass
=
model
.
roomClasses
.
filter
(
ActorClass
).
head
val
stateMachine
=
actorClass
.
stateMachine
val
diag
=
getDiag
(
model
)
assertSetEquals
(
newHashSet
(
"transition target not found"
->
new
DiagRef
(
stateMachine
.
transition
(
"t2"
).
to
,
stateTerminal_State
,
0
),
"transition target not found"
->
new
DiagRef
(
stateMachine
.
transition
(
"t4"
).
to
,
subStateTrPointTerminal_TrPoint
,
0
),
"transition target not found"
->
new
DiagRef
(
stateMachine
.
subgraphOf
(
"s2"
).
transition
(
"t21"
).
to
,
trPointTerminal_TrPoint
,
0
)
),
diag
.
featureBasedDiagnosticsSummary
)
}
@
Test
def
void
transitionInvalidEntryExitPoints
()
{
val
resource
=
getResource
(
'validator/transitions_invalid_entry_exit.room'
)
val
model
=
resource
.
contents
.
head
as
RoomModel
val
actorClass
=
model
.
roomClasses
.
filter
(
ActorClass
).
head
val
stateMachine
=
actorClass
.
stateMachine
val
diag
=
getDiag
(
model
)
val
withIgnored
=
newHashSet
(
"Unreachable state/point of graph"
->
new
DiagRef
(
stateMachine
,
stateGraph_TrPoints
,
0
),
"Unreachable state/point of graph"
->
new
DiagRef
(
stateMachine
,
stateGraph_TrPoints
,
1
)
)
assertSetEquals
(
newHashSet
(
"entry point can not be transition target"
->
new
DiagRef
(
stateMachine
.
subgraphOf
(
"s1"
).
transition
(
"t11"
).
to
,
trPointTerminal_TrPoint
,
0
),
"exit point can not be transition source"
->
new
DiagRef
(
stateMachine
.
subgraphOf
(
"s2"
).
transition
(
"t21"
).
from
,
trPointTerminal_TrPoint
,
0
),
"entry and exit points forbidden on top level state graph"
->
new
DiagRef
(
stateMachine
,
stateGraph_TrPoints
,
0
),
"entry and exit points forbidden on top level state graph"
->
new
DiagRef
(
stateMachine
,
stateGraph_TrPoints
,
1
),
"sub state entry point can not be transition source"
->
new
DiagRef
(
stateMachine
.
transition
(
"t2"
).
from
,
subStateTrPointTerminal_TrPoint
,
0
),
"sub state exit point can not be transition target"
->
new
DiagRef
(
stateMachine
.
transition
(
"t3"
).
to
,
subStateTrPointTerminal_TrPoint
,
0
)
),
diag
.
getFeatureBasedDiagnosticsSummary
(
withIgnored
)
)
}
@
Data
static
class
DiagRef
{
EObject
source
EStructuralFeature
feature
int
index
override
toString
()
{
feature
.
EContainingClass
.
name
+
"."
+
feature
.
name
+
"["
+
index
+
"] of "
+
source
.
eResource
.
getURIFragment
(
source
)
}
}
//
non
-
initial
transitions
def
transition
(
StateGraph
it
,
String
nameToFind
)
{
it
.
transitions
.
filter
(
NonInitialTransition
).
findFirst
[
name
==
nameToFind
]
}
//
initial
transitions
def
initialTransition
(
StateGraph
it
,
String
nameToFind
)
{
it
.
transitions
.
filter
(
InitialTransition
).
findFirst
[
name
==
nameToFind
]
}
def
state
(
StateGraph
it
,
String
nameToFind
)
{
it
.
states
.
findFirst
[
name
==
nameToFind
]
}
def
subgraphOf
(
StateGraph
it
,
String
nameToFind
)
{
it
.
state
(
nameToFind
).
subgraph
}
def
getFeatureBasedDiagnosticsSummary
(
Diagnostic
it
)
{
getFeatureBasedDiagnosticsSummary
(
it
,
emptySet
)
}
def
getFeatureBasedDiagnosticsSummary
(
Diagnostic
it
,
Set
<
Pair
<
String
,
DiagRef
>>
ignored
)
{
children
.
filter
(
FeatureBasedDiagnostic
).
map
[
message
->
new
DiagRef
(
sourceEObject
,
feature
,
index
)].
reject
[
ignored
.
contains
(
it
)
].
toSet
}
def
<
T
>
assertSetEquals
(
Set
<?
extends
T
>
expected
,
Set
<?
extends
T
>
actual
)
{
val
equals
=
expected
.
containsAll
(
actual
)
&&
actual
.
containsAll
(
expected
)
val
missing
=
expected
.
reject
[
actual
.
contains
(
it
)].
toList
val
extra
=
actual
.
reject
[
expected
.
contains
(
it
)].
toList
val
message
=
"missing from actual:"
+
missing
+
", extra in actual: "
+
extra
Assert
.
assertTrue
(
message
,
equals
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment