From 39770a85b966fb491193f45da4d743724b248c71 Mon Sep 17 00:00:00 2001 From: Juergen Haug Date: Tue, 25 Jun 2019 17:25:22 +0200 Subject: Bug 541775 - [generator.fsm] State machine without initial transition causes null pointer exception in generator * added test * fixed NPE * added validation on genmodel level Change-Id: Ib4f66e88ad995a7a1178312e5a39873bfaf37544 --- .../core/genmodel/fsm/ExtendedFsmGenBuilder.xtend | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'plugins/org.eclipse.etrice.core.genmodel.fsm') diff --git a/plugins/org.eclipse.etrice.core.genmodel.fsm/src/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.xtend b/plugins/org.eclipse.etrice.core.genmodel.fsm/src/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.xtend index 5dd9c54f9..a26ee681f 100644 --- a/plugins/org.eclipse.etrice.core.genmodel.fsm/src/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.xtend +++ b/plugins/org.eclipse.etrice.core.genmodel.fsm/src/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.xtend @@ -32,6 +32,8 @@ import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node import static extension org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions.* import org.eclipse.etrice.core.fsm.util.FSMHelpers +import org.eclipse.etrice.core.fsm.fSM.ModelComponent +import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Graph class ExtendedFsmGenBuilder extends BasicFsmGenBuilder { @@ -49,6 +51,10 @@ class ExtendedFsmGenBuilder extends BasicFsmGenBuilder { this.validator = if(validator === null) new NullDiagnostician else validator } + override GraphContainer createTransformedModel(ModelComponent mc) { + super.createTransformedModel(mc).check(mc) + } + /** * computes the available triggers for all leaf states */ @@ -229,6 +235,32 @@ class ExtendedFsmGenBuilder extends BasicFsmGenBuilder { return it } + def protected check(GraphContainer gc, ModelComponent mc) { + if (!mc.isAbstract) { + gc.eAllContents.toIterable.filter(Graph).forEach[checkInitialTransition(mc)] + } + return gc + } + + def protected checkInitialTransition(Graph graph, ModelComponent mc) { + if (graph.initialTransition!==null) { + // graph has an initial transition + return + } + + if (graph.eContainer instanceof GraphContainer) { + validationError("Top level state graph must have an initial transition", mc, FSMPackage.Literals.MODEL_COMPONENT__STATE_MACHINE); + return; + } + + // in the super state graph search for a transition which points to our parent state + val parentState = graph.eContainer as Node + val parentGraph = parentState.eContainer as Graph + if (!parentGraph.links.filter[target==parentState].empty) { + validationError("The state graph has transitions to history in its parent graph, thus it must have an initial transition", parentState.stateGraphNode, FSMPackage.Literals.STATE__SUBGRAPH); + } + } + protected def void validationError(String msg, EObject obj, EStructuralFeature feature) { validationError(msg, obj, feature, IDiagnostician.INSIGNIFICANT_INDEX) } -- cgit v1.2.3