diff options
Diffstat (limited to 'plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/BasicFsmGenBuilder.java')
-rw-r--r-- | plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/BasicFsmGenBuilder.java | 356 |
1 files changed, 356 insertions, 0 deletions
diff --git a/plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/BasicFsmGenBuilder.java b/plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/BasicFsmGenBuilder.java new file mode 100644 index 000000000..5bbb53340 --- /dev/null +++ b/plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/BasicFsmGenBuilder.java @@ -0,0 +1,356 @@ +/** + * 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 com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import com.google.inject.Injector; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.function.Consumer; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.etrice.core.fsm.fSM.ChoicePoint; +import org.eclipse.etrice.core.fsm.fSM.ChoicepointTerminal; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; +import org.eclipse.etrice.core.fsm.fSM.NonInitialTransition; +import org.eclipse.etrice.core.fsm.fSM.RefinedState; +import org.eclipse.etrice.core.fsm.fSM.RefinedTransition; +import org.eclipse.etrice.core.fsm.fSM.SimpleState; +import org.eclipse.etrice.core.fsm.fSM.State; +import org.eclipse.etrice.core.fsm.fSM.StateGraph; +import org.eclipse.etrice.core.fsm.fSM.StateGraphNode; +import org.eclipse.etrice.core.fsm.fSM.StateTerminal; +import org.eclipse.etrice.core.fsm.fSM.SubStateTrPointTerminal; +import org.eclipse.etrice.core.fsm.fSM.TrPoint; +import org.eclipse.etrice.core.fsm.fSM.TrPointTerminal; +import org.eclipse.etrice.core.fsm.fSM.Transition; +import org.eclipse.etrice.core.fsm.fSM.TransitionTerminal; +import org.eclipse.etrice.core.fsm.util.FSMHelpers; +import org.eclipse.etrice.core.genmodel.fsm.fsmgen.FsmGenFactory; +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.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.ListExtensions; + +@SuppressWarnings("all") +public class BasicFsmGenBuilder { + @Inject + @Extension + protected FSMHelpers fsmHelpers; + + protected final FsmGenFactory factory = FsmGenFactory.eINSTANCE; + + public BasicFsmGenBuilder(final Injector injector) { + injector.injectMembers(this); + } + + protected BasicFsmGenBuilder() { + } + + public GraphContainer createTransformedModel(final ModelComponent mc) { + return this.createContainer(mc); + } + + private GraphContainer createContainer(final ModelComponent mc) { + final ArrayList<?> _cacheKey = CollectionLiterals.newArrayList(mc); + final GraphContainer _result; + synchronized (_createCache_createContainer) { + if (_createCache_createContainer.containsKey(_cacheKey)) { + return _createCache_createContainer.get(_cacheKey); + } + GraphContainer _createGraphContainer = this.factory.createGraphContainer(); + _result = _createGraphContainer; + _createCache_createContainer.put(_cacheKey, _result); + } + _init_createContainer(_result, mc); + return _result; + } + + private final HashMap<ArrayList<?>, GraphContainer> _createCache_createContainer = CollectionLiterals.newHashMap(); + + private void _init_createContainer(final GraphContainer it, final ModelComponent mc) { + it.setComponent(mc); + Graph _createStateMachine = this.createStateMachine(mc); + it.setGraph(_createStateMachine); + } + + private Graph createStateMachine(final ModelComponent mc) { + Graph _xblockexpression = null; + { + final StateGraph superFSM = this.fsmHelpers.getSuperStateMachine(mc); + Graph _xifexpression = null; + boolean _notEquals = (!Objects.equal(superFSM, null)); + if (_notEquals) { + Graph _xblockexpression_1 = null; + { + ModelComponent _modelComponent = this.fsmHelpers.getModelComponent(superFSM); + final Graph baseGraph = this.createStateMachine(_modelComponent); + StateGraph _actualStateMachine = this.fsmHelpers.getActualStateMachine(mc); + _xblockexpression_1 = this.mergeGraph(baseGraph, _actualStateMachine); + } + _xifexpression = _xblockexpression_1; + } else { + StateGraph _actualStateMachine = this.fsmHelpers.getActualStateMachine(mc); + Graph _createGraph = null; + if (_actualStateMachine!=null) { + _createGraph=this.createGraph(_actualStateMachine); + } + _xifexpression = _createGraph; + } + _xblockexpression = _xifexpression; + } + return _xblockexpression; + } + + private Graph mergeGraph(final Graph graph, final StateGraph sg) { + EList<Node> _nodes = graph.getNodes(); + final Consumer<Node> _function = new Consumer<Node>() { + @Override + public void accept(final Node it) { + it.setInherited(true); + } + }; + _nodes.forEach(_function); + EList<Link> _links = graph.getLinks(); + final Consumer<Link> _function_1 = new Consumer<Link>() { + @Override + public void accept(final Link it) { + it.setInherited(true); + } + }; + _links.forEach(_function_1); + this.createContents(graph, sg); + graph.setStateGraph(sg); + return graph; + } + + private Graph createGraph(final StateGraph sg) { + final ArrayList<?> _cacheKey = CollectionLiterals.newArrayList(sg); + final Graph _result; + synchronized (_createCache_createGraph) { + if (_createCache_createGraph.containsKey(_cacheKey)) { + return _createCache_createGraph.get(_cacheKey); + } + Graph _createGraph = this.factory.createGraph(); + _result = _createGraph; + _createCache_createGraph.put(_cacheKey, _result); + } + _init_createGraph(_result, sg); + return _result; + } + + private final HashMap<ArrayList<?>, Graph> _createCache_createGraph = CollectionLiterals.newHashMap(); + + private void _init_createGraph(final Graph it, final StateGraph sg) { + it.setStateGraph(sg); + this.createContents(it, sg); + } + + private void createContents(final Graph graph, final StateGraph sg) { + EList<Node> _nodes = graph.getNodes(); + EList<ChoicePoint> _chPoints = sg.getChPoints(); + final Function1<ChoicePoint, Node> _function = new Function1<ChoicePoint, Node>() { + @Override + public Node apply(final ChoicePoint it) { + return BasicFsmGenBuilder.this.createNode(it); + } + }; + List<Node> _map = ListExtensions.<ChoicePoint, Node>map(_chPoints, _function); + _nodes.addAll(_map); + EList<Node> _nodes_1 = graph.getNodes(); + EList<TrPoint> _trPoints = sg.getTrPoints(); + final Function1<TrPoint, Node> _function_1 = new Function1<TrPoint, Node>() { + @Override + public Node apply(final TrPoint it) { + return BasicFsmGenBuilder.this.createNode(it); + } + }; + List<Node> _map_1 = ListExtensions.<TrPoint, Node>map(_trPoints, _function_1); + _nodes_1.addAll(_map_1); + EList<Node> _nodes_2 = graph.getNodes(); + EList<State> _states = sg.getStates(); + Iterable<SimpleState> _filter = Iterables.<SimpleState>filter(_states, SimpleState.class); + final Function1<SimpleState, Node> _function_2 = new Function1<SimpleState, Node>() { + @Override + public Node apply(final SimpleState it) { + return BasicFsmGenBuilder.this.createNode(it); + } + }; + Iterable<Node> _map_2 = IterableExtensions.<SimpleState, Node>map(_filter, _function_2); + Iterables.<Node>addAll(_nodes_2, _map_2); + EList<Link> _links = graph.getLinks(); + EList<Transition> _transitions = sg.getTransitions(); + final Function1<Transition, Link> _function_3 = new Function1<Transition, Link>() { + @Override + public Link apply(final Transition it) { + return BasicFsmGenBuilder.this.createLink(it); + } + }; + List<Link> _map_3 = ListExtensions.<Transition, Link>map(_transitions, _function_3); + _links.addAll(_map_3); + EList<State> _states_1 = sg.getStates(); + Iterable<RefinedState> _filter_1 = Iterables.<RefinedState>filter(_states_1, RefinedState.class); + final Consumer<RefinedState> _function_4 = new Consumer<RefinedState>() { + @Override + public void accept(final RefinedState it) { + BasicFsmGenBuilder.this.handleRefinedState(it); + } + }; + _filter_1.forEach(_function_4); + EList<RefinedTransition> _refinedTransitions = sg.getRefinedTransitions(); + final Consumer<RefinedTransition> _function_5 = new Consumer<RefinedTransition>() { + @Override + public void accept(final RefinedTransition it) { + BasicFsmGenBuilder.this.handleRefinedTransition(it); + } + }; + _refinedTransitions.forEach(_function_5); + } + + private void handleRefinedState(final RefinedState s) { + StateGraph _subgraph = s.getSubgraph(); + boolean _notEquals = (!Objects.equal(_subgraph, null)); + if (_notEquals) { + State _target = s.getTarget(); + StateGraph _subgraph_1 = _target.getSubgraph(); + boolean _notEquals_1 = (!Objects.equal(_subgraph_1, null)); + if (_notEquals_1) { + State _target_1 = s.getTarget(); + StateGraph _subgraph_2 = _target_1.getSubgraph(); + final Graph targetGraph = this.createGraph(_subgraph_2); + StateGraph _subgraph_3 = s.getSubgraph(); + this.mergeGraph(targetGraph, _subgraph_3); + } else { + State _target_2 = s.getTarget(); + Node _createNode = this.createNode(_target_2); + StateGraph _subgraph_4 = s.getSubgraph(); + Graph _createGraph = this.createGraph(_subgraph_4); + _createNode.setSubgraph(_createGraph); + } + } + State _target_3 = s.getTarget(); + final Node target = this.createNode(_target_3); + target.setStateGraphNode(s); + } + + private void handleRefinedTransition(final RefinedTransition t) { + Transition _target = t.getTarget(); + Link _createLink = this.createLink(_target); + _createLink.setTransition(t); + } + + private Link createLink(final Transition tr) { + final ArrayList<?> _cacheKey = CollectionLiterals.newArrayList(tr); + final Link _result; + synchronized (_createCache_createLink) { + if (_createCache_createLink.containsKey(_cacheKey)) { + return _createCache_createLink.get(_cacheKey); + } + Link _createLink = this.factory.createLink(); + _result = _createLink; + _createCache_createLink.put(_cacheKey, _result); + } + _init_createLink(_result, tr); + return _result; + } + + private final HashMap<ArrayList<?>, Link> _createCache_createLink = CollectionLiterals.newHashMap(); + + private void _init_createLink(final Link it, final Transition tr) { + it.setTransition(tr); + Node _xifexpression = null; + if ((tr instanceof NonInitialTransition)) { + TransitionTerminal _from = ((NonInitialTransition)tr).getFrom(); + _xifexpression = this.createNode(_from); + } + it.setSource(_xifexpression); + TransitionTerminal _to = tr.getTo(); + Node _createNode = this.createNode(_to); + it.setTarget(_createNode); + } + + private Node _createNode(final StateGraphNode s) { + final ArrayList<?> _cacheKey = CollectionLiterals.newArrayList(s); + final Node _result; + synchronized (_createCache_createNode) { + if (_createCache_createNode.containsKey(_cacheKey)) { + return _createCache_createNode.get(_cacheKey); + } + Node _createNode = this.factory.createNode(); + _result = _createNode; + _createCache_createNode.put(_cacheKey, _result); + } + _init_createNode(_result, s); + return _result; + } + + private final HashMap<ArrayList<?>, Node> _createCache_createNode = CollectionLiterals.newHashMap(); + + private void _init_createNode(final Node it, final StateGraphNode s) { + it.setStateGraphNode(s); + Graph _xifexpression = null; + if ((s instanceof State)) { + StateGraph _subgraph = ((State)s).getSubgraph(); + Graph _createGraph = null; + if (_subgraph!=null) { + _createGraph=this.createGraph(_subgraph); + } + _xifexpression = _createGraph; + } + it.setSubgraph(_xifexpression); + } + + private Node _createNode(final ChoicepointTerminal tt) { + ChoicePoint _cp = tt.getCp(); + return this.createNode(_cp); + } + + private Node _createNode(final TrPointTerminal tt) { + TrPoint _trPoint = tt.getTrPoint(); + return this.createNode(_trPoint); + } + + private Node _createNode(final StateTerminal tt) { + State _state = tt.getState(); + return this.createNode(_state); + } + + private Node _createNode(final SubStateTrPointTerminal tt) { + TrPoint _trPoint = tt.getTrPoint(); + return this.createNode(_trPoint); + } + + private Node createNode(final EObject tt) { + if (tt instanceof ChoicepointTerminal) { + return _createNode((ChoicepointTerminal)tt); + } else if (tt instanceof StateGraphNode) { + return _createNode((StateGraphNode)tt); + } else if (tt instanceof StateTerminal) { + return _createNode((StateTerminal)tt); + } else if (tt instanceof SubStateTrPointTerminal) { + return _createNode((SubStateTrPointTerminal)tt); + } else if (tt instanceof TrPointTerminal) { + return _createNode((TrPointTerminal)tt); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.<Object>asList(tt).toString()); + } + } +} |