diff options
Diffstat (limited to 'plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.java')
-rw-r--r-- | plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.java | 309 |
1 files changed, 0 insertions, 309 deletions
diff --git a/plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.java b/plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.java deleted file mode 100644 index b3acb42a5..000000000 --- a/plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.java +++ /dev/null @@ -1,309 +0,0 @@ -/** - * Copyright (c) 2011 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: - * hrr@protos.de (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.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.etrice.core.fsm.fSM.AbstractInterfaceItem; -import org.eclipse.etrice.core.fsm.fSM.FSMPackage; -import org.eclipse.etrice.core.fsm.fSM.MessageFromIf; -import org.eclipse.etrice.core.fsm.fSM.State; -import org.eclipse.etrice.core.fsm.fSM.StateGraphNode; -import org.eclipse.etrice.core.fsm.fSM.TransitionBase; -import org.eclipse.etrice.core.fsm.fSM.TransitionPoint; -import org.eclipse.etrice.core.fsm.fSM.Trigger; -import org.eclipse.etrice.core.fsm.fSM.TriggeredTransition; -import org.eclipse.etrice.core.fsm.naming.FSMNameProvider; -import org.eclipse.etrice.core.genmodel.fsm.BasicFsmGenBuilder; -import org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions; -import org.eclipse.etrice.core.genmodel.fsm.ICommonDataCalculator; -import org.eclipse.etrice.core.genmodel.fsm.IDiagnostician; -import org.eclipse.etrice.core.genmodel.fsm.fsmgen.CommonTrigger; -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.IteratorExtensions; -import org.eclipse.xtext.xbase.lib.ListExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - -@SuppressWarnings("all") -public class ExtendedFsmGenBuilder extends BasicFsmGenBuilder { - public static String TRIGGER_SEP = "#"; - - @Inject - @Extension - protected FSMNameProvider _fSMNameProvider; - - @Inject - @Extension - protected ICommonDataCalculator _iCommonDataCalculator; - - protected IDiagnostician validator; - - private final FsmGenFactory factory = FsmGenFactory.eINSTANCE; - - public ExtendedFsmGenBuilder(final Injector injector, final IDiagnostician validator) { - super(); - injector.injectMembers(this); - this.validator = validator; - } - - /** - * computes the available triggers for all leaf states - */ - public GraphContainer withTriggersInStates(final GraphContainer gc) { - Graph _graph = gc.getGraph(); - Iterator<Node> _allStateNodes = FsmGenExtensions.getAllStateNodes(_graph); - final Function1<Node, Boolean> _function = new Function1<Node, Boolean>() { - @Override - public Boolean apply(final Node it) { - Graph _subgraph = it.getSubgraph(); - return Boolean.valueOf(Objects.equal(_subgraph, null)); - } - }; - Iterator<Node> _filter = IteratorExtensions.<Node>filter(_allStateNodes, _function); - final Procedure1<Node> _function_1 = new Procedure1<Node>() { - @Override - public void apply(final Node it) { - ExtendedFsmGenBuilder.this.computeTriggers(it); - } - }; - IteratorExtensions.<Node>forEach(_filter, _function_1); - return gc; - } - - /** - * determines all transition chain heads of all transitions - */ - public GraphContainer withChainHeads(final GraphContainer gc) { - Graph _graph = gc.getGraph(); - Iterator<Link> _allChainHeads = FsmGenExtensions.getAllChainHeads(_graph); - final Procedure1<Link> _function = new Procedure1<Link>() { - @Override - public void apply(final Link it) { - ExtendedFsmGenBuilder.this.followChain(it, it); - } - }; - IteratorExtensions.<Link>forEach(_allChainHeads, _function); - return gc; - } - - /** - * calculates and stores the common data - */ - public GraphContainer withCommonData(final GraphContainer gc) { - Graph _graph = gc.getGraph(); - Iterator<Link> _allLinks = FsmGenExtensions.getAllLinks(_graph); - final Procedure1<Link> _function = new Procedure1<Link>() { - @Override - public void apply(final Link it) { - EObject _calculateCommonData = ExtendedFsmGenBuilder.this._iCommonDataCalculator.calculateCommonData(it); - it.setCommonData(_calculateCommonData); - } - }; - IteratorExtensions.<Link>forEach(_allLinks, _function); - return gc; - } - - private void followChain(final Link l, final Link head) { - TransitionBase _transition = head.getTransition(); - boolean _not = (!(_transition instanceof TriggeredTransition)); - if (_not) { - l.setIfitemTriggered(false); - } - EList<Link> _chainHeads = l.getChainHeads(); - _chainHeads.add(head); - Node _target = l.getTarget(); - final StateGraphNode target = _target.getStateGraphNode(); - if (((target instanceof State) || (target instanceof TransitionPoint))) { - return; - } else { - Node _target_1 = l.getTarget(); - EList<Link> _outgoing = _target_1.getOutgoing(); - for (final Link next : _outgoing) { - this.followChain(next, head); - } - } - } - - private void computeTriggers(final Node s) { - final LinkedHashMap<String, CommonTrigger> caughtTriggers = CollectionLiterals.<String, CommonTrigger>newLinkedHashMap(); - this.computeTriggersRecursive(s, caughtTriggers); - EList<CommonTrigger> _caughtTriggers = s.getCaughtTriggers(); - _caughtTriggers.clear(); - EList<CommonTrigger> _caughtTriggers_1 = s.getCaughtTriggers(); - Collection<CommonTrigger> _values = caughtTriggers.values(); - _caughtTriggers_1.addAll(_values); - } - - private void computeTriggersRecursive(final Node s, final HashMap<String, CommonTrigger> caughtTriggers) { - Iterable<TriggeredTransition> _outgoingTriggeredTranisitions = FsmGenExtensions.getOutgoingTriggeredTranisitions(s); - List<TriggeredTransition> _list = IterableExtensions.<TriggeredTransition>toList(_outgoingTriggeredTranisitions); - this.computeTriggers(_list, caughtTriggers); - Graph _graph = s.getGraph(); - Iterable<Node> _trPointNodes = FsmGenExtensions.getTrPointNodes(_graph); - final Function1<Node, EList<Link>> _function = new Function1<Node, EList<Link>>() { - @Override - public EList<Link> apply(final Node it) { - return it.getOutgoing(); - } - }; - Iterable<EList<Link>> _map = IterableExtensions.<Node, EList<Link>>map(_trPointNodes, _function); - final Iterable<Link> outgoing = Iterables.<Link>concat(_map); - final Function1<Link, Boolean> _function_1 = new Function1<Link, Boolean>() { - @Override - public Boolean apply(final Link it) { - TransitionBase _transition = it.getTransition(); - return Boolean.valueOf((_transition instanceof TriggeredTransition)); - } - }; - Iterable<Link> _filter = IterableExtensions.<Link>filter(outgoing, _function_1); - final Function1<Link, TransitionBase> _function_2 = new Function1<Link, TransitionBase>() { - @Override - public TransitionBase apply(final Link it) { - return it.getTransition(); - } - }; - Iterable<TransitionBase> _map_1 = IterableExtensions.<Link, TransitionBase>map(_filter, _function_2); - Iterable<TriggeredTransition> _filter_1 = Iterables.<TriggeredTransition>filter(_map_1, TriggeredTransition.class); - final List<TriggeredTransition> trPointTransitions = IterableExtensions.<TriggeredTransition>toList(_filter_1); - this.computeTriggers(trPointTransitions, caughtTriggers); - Graph _graph_1 = s.getGraph(); - boolean _isTopLevel = FsmGenExtensions.isTopLevel(_graph_1); - boolean _not = (!_isTopLevel); - if (_not) { - Node _parentState = FsmGenExtensions.getParentState(s); - this.computeTriggersRecursive(_parentState, caughtTriggers); - } - } - - private void computeTriggers(final List<TriggeredTransition> sameLevelTransitions, final HashMap<String, CommonTrigger> caughtTriggers) { - for (final TriggeredTransition t : sameLevelTransitions) { - EList<Trigger> _triggers = t.getTriggers(); - for (final Trigger tr : _triggers) { - EList<MessageFromIf> _msgFromIfPairs = tr.getMsgFromIfPairs(); - for (final MessageFromIf mif : _msgFromIfPairs) { - { - final String tag = this.getTriggerTag(mif); - final CommonTrigger ct = caughtTriggers.get(tag); - boolean _equals = Objects.equal(ct, null); - if (_equals) { - CommonTrigger _createCommonTrigger = this.createCommonTrigger(t, mif, tag); - caughtTriggers.put(tag, _createCommonTrigger); - } else { - EList<TriggeredTransition> _transitions = ct.getTransitions(); - final Function1<TriggeredTransition, EList<Trigger>> _function = new Function1<TriggeredTransition, EList<Trigger>>() { - @Override - public EList<Trigger> apply(final TriggeredTransition it) { - return it.getTriggers(); - } - }; - List<EList<Trigger>> _map = ListExtensions.<TriggeredTransition, EList<Trigger>>map(_transitions, _function); - Iterable<Trigger> _flatten = Iterables.<Trigger>concat(_map); - final Function1<Trigger, Boolean> _function_1 = new Function1<Trigger, Boolean>() { - @Override - public Boolean apply(final Trigger it) { - return Boolean.valueOf((ExtendedFsmGenBuilder.this.hasMatchingTrigger(it, tag) && (!ExtendedFsmGenBuilder.this.fsmHelpers.isGuarded(it)))); - } - }; - Iterable<Trigger> _filter = IterableExtensions.<Trigger>filter(_flatten, _function_1); - Trigger _head = IterableExtensions.<Trigger>head(_filter); - EObject _eContainer = null; - if (_head!=null) { - _eContainer=_head.eContainer(); - } - final TriggeredTransition unguarded = ((TriggeredTransition) _eContainer); - boolean _notEquals = (!Objects.equal(unguarded, null)); - if (_notEquals) { - boolean _contains = sameLevelTransitions.contains(unguarded); - if (_contains) { - boolean _isGuarded = this.fsmHelpers.isGuarded(tr); - if (_isGuarded) { - EList<TriggeredTransition> _transitions_1 = ct.getTransitions(); - final int idx = _transitions_1.indexOf(unguarded); - EList<TriggeredTransition> _transitions_2 = ct.getTransitions(); - _transitions_2.add(idx, t); - } else { - EReference _triggeredTransition_Triggers = FSMPackage.eINSTANCE.getTriggeredTransition_Triggers(); - this.validationError("Transitions with same trigger on same level have to be guarded!", t, _triggeredTransition_Triggers); - } - } - } else { - EList<TriggeredTransition> _transitions_3 = ct.getTransitions(); - _transitions_3.add(t); - } - } - } - } - } - } - } - - private boolean hasMatchingTrigger(final Trigger trig, final String tag) { - EList<MessageFromIf> _msgFromIfPairs = trig.getMsgFromIfPairs(); - for (final MessageFromIf mifp2 : _msgFromIfPairs) { - { - final String tr2 = this.getTriggerTag(mifp2); - boolean _equals = tr2.equals(tag); - if (_equals) { - return true; - } - } - } - return false; - } - - private CommonTrigger createCommonTrigger(final TriggeredTransition transition, final MessageFromIf mif, final String tag) { - final CommonTrigger it = this.factory.createCommonTrigger(); - it.setTrigger(tag); - AbstractInterfaceItem _from = mif.getFrom(); - it.setIfitem(_from); - EObject _message = mif.getMessage(); - it.setMsg(_message); - EList<TriggeredTransition> _transitions = it.getTransitions(); - _transitions.add(transition); - return it; - } - - private String getTriggerTag(final MessageFromIf it) { - AbstractInterfaceItem _from = it.getFrom(); - String _name = _from.getName(); - String _plus = (_name + ExtendedFsmGenBuilder.TRIGGER_SEP); - EObject _message = it.getMessage(); - String _messageName = this._fSMNameProvider.getMessageName(_message); - return (_plus + _messageName); - } - - protected void validationError(final String msg, final EObject obj, final EStructuralFeature feature) { - this.validationError(msg, obj, feature, IDiagnostician.INSIGNIFICANT_INDEX); - } - - protected void validationError(final String msg, final EObject obj, final EStructuralFeature feature, final int idx) { - this.validator.error(msg, obj, feature, idx); - } -} |