Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 66f5adfff3e93c8f928b834b206d07cfbf549cd2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*******************************************************************************
 * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * CONTRIBUTORS:
 * 		Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.core.genmodel.fsm

import org.eclipse.etrice.core.fsm.fSM.NonInitialTransition
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Graph
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node
import org.eclipse.etrice.core.fsm.fSM.TrPoint
import org.eclipse.etrice.core.fsm.fSM.State

class FsmGenChecker {
	
	static def check(GraphContainer gc, ILogger logger) {
		// graphs
		gc.eAllContents.filter(typeof(Graph)).forEach[checkGraph(it, logger)]
		
		// nodes
		gc.eAllContents.filter(typeof(Node)).forEach[checkNode(it, logger)]
		
		// links
		gc.eAllContents.filter(typeof(Link)).forEach[checkLink(it, logger)]
	}
	
	private static def void checkLink(Link it, ILogger logger) {
		if (transition===null) {
			logger.logError("graph doesn't point to ROOM transition")
		}
		else if (transition.eIsProxy) {
			logger.logError("unresolved ROOM transition")
		}
		else if (transition.eContainer===null) {
			logger.logError("dangling ROOM transition")
		}
		else if (target===null) {
			logger.logError("link without target")
		}
		else if (source===null && transition instanceof NonInitialTransition) {
			logger.logError("non-initial link without source")
		}

		if (source!==null) {
			checkLinkEnd(it, it.source, logger)
		}
		checkLinkEnd(it, it.target, logger)
	}
	
	private static def checkLinkEnd(Link link, Node node, ILogger logger) {
		if (node.eContainer == link.eContainer) {
			return;
		}
		else {
			if (!(node.stateGraphNode instanceof TrPoint)) {
				logger.logError("subgraph item is not transition point")
			}
			else if (!(node.eContainer.eContainer instanceof Node)) {
				logger.logError("subgraph item is in unexpected container")
			}
			else if (!((node.eContainer.eContainer as Node).stateGraphNode instanceof State)) {
				logger.logError("subgraph item is in unexpected container")
			}
			else if (node.eContainer.eContainer.eContainer != link.eContainer) {
				logger.logError("subgraph item is in unexpected container")
			}
		}
	}
	
	private static def void checkNode(Node it, ILogger logger) {
		if (stateGraphNode===null) {
			logger.logError("graph doesn't point to ROOM state graph node")
		}
		else if (stateGraphNode.eIsProxy) {
			logger.logError("unresolved ROOM graph node")
		}
		else if (stateGraphNode.eContainer===null) {
			logger.logError("dangling ROOM graph node")
		}
		else if (stateGraphNode.getName()===null) {
			logger.logError("ROOM graph node without name")
		}
		else if (graph===null) {
			logger.logError("node isn't contained in a graph")
		}
		
		// incoming transitions
		for (l : incoming) {
			if (l.target.stateGraphNode != it.stateGraphNode) {
				logger.logError("ROOM target node of an incoming transition must be myself")
			}
		}
		
		// outgoing transitions
		for (l : outgoing) {
			if (l.source.stateGraphNode != it.stateGraphNode) {
				logger.logError("ROOM source node of an outgoing transition must be myself")
			}
		}
	}
	
	private static def void checkGraph(Graph it, ILogger logger) {
		if (stateGraph===null) {
			logger.logError("graph doesn't point to ROOM state graph")
		}
		else if (stateGraph.eIsProxy) {
			logger.logError("unresolved ROOM graph")
		}
		else if (stateGraph.eContainer===null) {
			logger.logError("dangling ROOM graph")
		}
	}
}

Back to the top