Commit 700ba108 authored by Sudeep Kanav's avatar Sudeep Kanav
Browse files

YELLOW

refs 2756
parent efd05799
......@@ -17,17 +17,24 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.state.generator.nusmv;
import static org.eclipse.emf.ecore.util.EcoreUtil.remove;
import static org.fortiss.af3.component.utils.BehaviorModelElementFactory.createAction;
import static org.fortiss.af3.component.utils.BehaviorModelElementFactory.createGuard;
import static org.fortiss.af3.state.utils.StateAutomatonUtils.setSourceState;
import static org.fortiss.af3.state.utils.StateAutomatonUtils.setTargetState;
import static org.fortiss.af3.state.utils.StateModelElementFactory.createState;
import static org.fortiss.af3.state.utils.StateModelElementFactory.createStateAutomaton;
import static org.fortiss.af3.state.utils.StateModelElementFactory.createTransitionSegmentSpecification;
import static org.fortiss.af3.state.utils.StateModelElementFactory.createTransitionSegmentWithoutSpecification;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.copy;
import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.getLargestID;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.behavior.code.CodeSpecification;
import org.fortiss.af3.component.model.behavior.common.Action;
import org.fortiss.af3.component.model.behavior.common.Guard;
import org.fortiss.af3.component.utils.BehaviorModelElementFactory;
import org.fortiss.af3.expression.model.terms.imperative.Assignment;
import org.fortiss.af3.expression.model.terms.imperative.IStatementTerm;
import org.fortiss.af3.expression.model.terms.imperative.IfThenElse;
......@@ -37,8 +44,6 @@ import org.fortiss.af3.state.model.State;
import org.fortiss.af3.state.model.StateAutomaton;
import org.fortiss.af3.state.model.TransitionSegment;
import org.fortiss.af3.state.model.TransitionSegmentSpecification;
import org.fortiss.af3.state.utils.StateAutomatonUtils;
import org.fortiss.af3.state.utils.StateModelElementFactory;
import org.fortiss.pragmatictransformation.service.CacheSupportedTransformationBase;
import org.fortiss.pragmatictransformation.service.IPragmaticTransformation;
......@@ -62,7 +67,7 @@ import org.fortiss.pragmatictransformation.service.IPragmaticTransformation;
* @author kanav
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 76689CF20F84F070F2BC79E914F8E6AD
* @ConQAT.Rating YELLOW Hash: 8B16C6AD9C2CC4E4D2F5D2BCC33D0BE0
*/
public class CodeSpecificationToStateAutomata extends CacheSupportedTransformationBase {
/** Maximum id in the project. */
......@@ -81,7 +86,7 @@ public class CodeSpecificationToStateAutomata extends CacheSupportedTransformati
StateAutomaton sa =
(StateAutomaton)deferedTransformation.buildTransformation(eo);
EObject ec = eo.eContainer();
EcoreUtil.remove(eo);
remove(eo);
((Component)ec).getSpecifications().add(sa);
}
}
......@@ -94,21 +99,20 @@ public class CodeSpecificationToStateAutomata extends CacheSupportedTransformati
// It is work of the previous transformations to do that
else if(c instanceof CodeSpecification) {
CodeSpecification cs = (CodeSpecification)c;
StateAutomaton sa = StateModelElementFactory.createStateAutomaton();
StateAutomaton sa = createStateAutomaton();
sa.setId(++maxID);
State rootState = sa.getRootState();
rootState.setId(++maxID);
State initState = StateModelElementFactory.createState("Init", "", true);
State initState = createState("Init", "", true);
initState.setId(++maxID);
rootState.getContainedElements().add(initState);
for(IStatementTerm s : cs.getBody().getStatements()) {
TransitionSegment ts =
StateModelElementFactory.createTransitionSegmentWithoutSpecification();
TransitionSegment ts = createTransitionSegmentWithoutSpecification();
ts.setId(++maxID);
ts.setOwner(rootState);
StateAutomatonUtils.setSourceState(ts, initState, ++maxID);
StateAutomatonUtils.setTargetState(ts, initState, ++maxID);
setSourceState(ts, initState, ++maxID);
setTargetState(ts, initState, ++maxID);
TransitionSegmentSpecification tss =
(TransitionSegmentSpecification)deferedTransformation
......@@ -118,22 +122,20 @@ public class CodeSpecificationToStateAutomata extends CacheSupportedTransformati
return sa;
} else if(c instanceof IfThenElse) {
IfThenElse ifThenElseStatement = (IfThenElse)c;
TransitionSegmentSpecification tss =
StateModelElementFactory.createTransitionSegmentSpecification();
TransitionSegmentSpecification tss = createTransitionSegmentSpecification();
tss.setId(++maxID);
Guard guard =
BehaviorModelElementFactory.createGuard(copy(ifThenElseStatement.getGuard()));
Guard guard = createGuard(copy(ifThenElseStatement.getGuard()));
tss.setGuard(guard);
for(IStatementTerm s : ifThenElseStatement.getThenBlock().getStatements()) {
if(s instanceof Return)
if(s instanceof Return) {
break;
}
tss.getActions().add((Action)deferedTransformation.buildTransformation(s));
}
return tss;
} else if(c instanceof Assignment) {
Assignment a = (Assignment)c;
return BehaviorModelElementFactory.createAction(copy(a.getVariable()),
copy(a.getValue()));
return createAction(copy(a.getVariable()), copy(a.getValue()));
}
return null;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment