Skip to content
Snippets Groups Projects
AvatarFromSysML.java 63.6 KiB
Newer Older
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
 *
 * ludovic.apvrille AT enst.fr
 *
 * This software is a computer program whose purpose is to allow the
 * edition of TURTLE analysis, design and deployment diagrams, to
 * allow the generation of RT-LOTOS or Java code from this diagram,
 * and at last to allow the analysis of formal validation traces
 * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
 * from INRIA Rhone-Alpes.
 *
 * This software is governed by the CeCILL  license under French law and
 * abiding by the rules of distribution of free software.  You can  use,
 * modify and/ or redistribute the software under the terms of the CeCILL
 * license as circulated by CEA, CNRS and INRIA at the following URL
 * "http://www.cecill.info".
 *
 * As a counterpart to the access to the source code and  rights to copy,
 * modify and redistribute granted by the license, users are provided only
 * with a limited warranty  and the software's author,  the holder of the
 * economic rights,  and the successive licensors  have only  limited
 * liability.
 *
 * In this respect, the user's attention is drawn to the risks associated
 * with loading,  using,  modifying and/or developing or reproducing the
 * software by the user in light of its specific status of free software,
 * that may mean  that it is complicated to manipulate,  and  that  also
 * therefore means  that it is reserved for developers  and  experienced
 * professionals having in-depth computer knowledge. Users are therefore
 * encouraged to load and test the software's suitability as regards their
 * requirements in conditions enabling the security of their systems and/or
 * data to be ensured and,  more generally, to use and operate it in the
 * same conditions as regards security.
 *
 * The fact that you are presently reading this means that you have had
 * knowledge of the CeCILL license and that you accept its terms.
 */
Sophie Coudert's avatar
Sophie Coudert committed
/**
 * Class AvatarFromSysML
 * Creation: 20/06/2024
 *
 * @author Sophie Coudert
 * @version 0.1 20/06/2024
 */
package avatartranslator.tosysmlv2;

Sophie Coudert's avatar
Sophie Coudert committed
import java.io.FileReader;
import java.util.HashMap;
import java.util.List;
import java.util.function.BiConsumer;

import avatartranslator.*;
import avatartranslator.tosysmlv2.AvatarFromSysMLSyntax.*;
import static java_cup.runtime.ComplexSymbolFactory.*;
import java_cup.runtime.ComplexSymbolFactory;
import myutil.TraceManager;
import static java.lang.System.out;

Sophie Coudert's avatar
Sophie Coudert committed
/** Class AvatarFromSysML
 * Creation: 20/06/2024
 *
 * @author Sophie Coudert
 * @version 0.1 20/06/2024
 *
 * Building Avatar Models from Their SysML V2 description. This Class exports the main function that does this. Technically,
 * the class implements the last step of this process, i.e. it builds Avatar models from abstract syntax trees build by AvatarSysMLParser.
 */
public class AvatarFromSysML {
Sophie Coudert's avatar
Sophie Coudert committed
    /** the build Avatar specification, returned at the end of the building process */
    private AvatarSpecification avSpec;
Sophie Coudert's avatar
Sophie Coudert committed
    /** the source abstract syntax tree, obtained through a call to the parser */
    private StxModel stxSpec;
Sophie Coudert's avatar
Sophie Coudert committed
    /** maps signal syntactic elements to their associated avatar signal by the building process */
    private HashMap<StxSignal, AvatarSignal> signalMap;
Sophie Coudert's avatar
Sophie Coudert committed
    /** maps block syntactic elements to their associated avatar block by the building process */
    private HashMap<StxBlock, AvatarBlock> blockMap;
Sophie Coudert's avatar
Sophie Coudert committed
    /** maps state syntactic elements to their associated avatar state-machine element by the building process (when exists) */
    private HashMap<StxState, AvatarStateMachineElement> stateMap;
Sophie Coudert's avatar
Sophie Coudert committed
    /** maps transition syntactic elements to their associated avatar transition by the building process (when exists) */
    private HashMap<AvatarStateMachineElement, StateTransitions> transitionMap;
Sophie Coudert's avatar
Sophie Coudert committed
    /** maps Avatar datatypes extracted from the SysML sourse to their sequence of primitive fields */
    private HashMap<AvatarDataType, AvatarDataTypePrimitiveFields> primitiveFieldsMap;
Sophie Coudert's avatar
Sophie Coudert committed
    /** all errors encountered while parsing and building model from parsing-returned abstract syntax tree */
Sophie Coudert's avatar
Sophie Coudert committed
    private List<AvatarFromSysMLError> errors;
    public AvatarFromSysML(){
        avSpec = null;
        stxSpec = null;
        signalMap = new HashMap<StxSignal, AvatarSignal>();
        blockMap = new HashMap<StxBlock, AvatarBlock>();
        stateMap = new HashMap<StxState, AvatarStateMachineElement>();
        transitionMap = new HashMap<AvatarStateMachineElement, StateTransitions>();
Sophie Coudert's avatar
Sophie Coudert committed
        errors = null;
    }
Sophie Coudert's avatar
Sophie Coudert committed

    /** register an error encountered while parsing and building model from parsing-returned abstract syntax tree */
    private void addError(AvatarFromSysMLError _err) { errors.add(_err); }

    /** to memorize the set of transitions of a state and memorize its block with them */
    private class StateTransitions {
        private AvatarBlock block;
        private List<AvatarTransition> transitions;
        public StateTransitions (AvatarBlock _block, List<AvatarTransition> _transitions) {
            block = _block;
            transitions = _transitions;
        }
        public AvatarBlock getBlock() { return block; }
        public List<AvatarTransition> getTransitions() { return transitions; }
    }
Sophie Coudert's avatar
Sophie Coudert committed

    /** Builds an Avatar Specification From */
Sophie Coudert's avatar
Sophie Coudert committed
    public AvatarSpecification sysMLtoSpec(String _fileName) {
        AvatarFromSysMLParser parser;
        try { parser =
                new AvatarFromSysMLParser(new AvatarFromSysMLLexer(new FileReader(_fileName)),
                        new ComplexSymbolFactory()); }
        catch (java.lang.Exception e) {
            e.printStackTrace(out);
            return new AvatarSpecification("DummySpec", null);
        }
        TraceManager.addDev("Parsing Model");
        try { stxSpec = parser.parseModel(); }
        catch (java.lang.Exception e) {
            e.printStackTrace(out);
Sophie Coudert's avatar
Sophie Coudert committed
            return new AvatarSpecification("DummySpec", null);
        if (stxSpec == null) {
            for(AvatarFromSysMLError e : parser.getErrors())
                TraceManager.addDev(e.toString());
            return new AvatarSpecification("DummySpec", null);
        }
        errors = stxSpec.getErrors();
        TraceManager.addDev("Building Specification");
Sophie Coudert's avatar
Sophie Coudert committed
        avSpec = new AvatarSpecification("FromSysMLV2_EXAMPLE_SPECIFICATION",null);
        signalMap.clear();
        blockMap.clear();
        stateMap.clear();
        TraceManager.addDev("Building DataTypes");
        buildDataTypes();
        TraceManager.addDev("Building Blocks");
        buildBlocks();
        TraceManager.addDev("Building Relations");
        buildRelations();
        for(AvatarFromSysMLError e : errors)
            TraceManager.addDev(e.toString());
Sophie Coudert's avatar
Sophie Coudert committed
        return avSpec;
    private void addState(AvatarStateMachineElement e, AvatarBlock b) {
        if (transitionMap.get(e) == null){
            ArrayList<AvatarTransition> l = new ArrayList<AvatarTransition>();
            transitionMap.put(e, new StateTransitions(b, l));
        }
    }
    private void addTransition(AvatarTransition t, AvatarStateMachineElement e) {
        transitionMap.get(e).getTransitions().add(t);
    }
    private AvatarBlock getBlock(StxBlock _b) {
        AvatarBlock b = blockMap.get(_b);
        if (b == null) {
            b = new AvatarBlock(_b.getName(), avSpec, null);
            blockMap.put(_b, b);
        }
        return b;
    }
    private AvatarSignal getSignal(StxSignal _b) {
        AvatarSignal b = signalMap.get(_b);
        if (b == null) {
            if (_b.isInput())
                b = new AvatarSignal(_b.getName(), AvatarSignal.IN, null);
            else
                b = new AvatarSignal(_b.getName(), AvatarSignal.OUT, null);
            signalMap.put(_b, b);
        }
        return b;
    }
    private AvatarAttribute getOriginalAttributeByName(String _name, AvatarBlock _block) {
Sophie Coudert's avatar
Sophie Coudert committed
        List<AvatarAttribute> l = _block.getOriginalAttributes();
        int size = l.size();
        for (int i = 0; i < size; i++)
            if(l.get(i).getName().equals(_name)) return  l.get(i);
        return null;
    }
    private AvatarAttribute getAttributeByName(String _name, AvatarBlock _block) {
        List<AvatarAttribute> l = _block.getAttributes();
        int size = l.size();
        for (int i = 0; i < size; i++)
            if(l.get(i).getName().equals(_name)) return  l.get(i);
        return null;
    }
    private AvatarAttribute getTimerByName(String _name, AvatarBlock _block) {
        AvatarAttribute res =  getAttributeByName(_name, _block);
        if (res != null && res.getType() == AvatarType.TIMER) return res;
        return null;
    }
    private AvatarStateMachineElement getState(StxState _s, AvatarBlock _b) {
        AvatarStateMachineElement s = stateMap.get(_s);
        if (s == null) {
            switch(_s.getType()) {
                case AvatarFromSysMLSyntax.STXSTARTSTATE :
                    s = new AvatarStartState("StartState", null, _b);
                    break;
                case AvatarFromSysMLSyntax.STXSTANDARDSTATE :
                    s = new AvatarState(_s.getName(), null, _b);
                    break;
                case AvatarFromSysMLSyntax.STXRANDOMSTATE :
                    s = new AvatarRandom(_s.getName(), null, _b);
                    break;
                case AvatarFromSysMLSyntax.STXCOUNTSTATE :
                    s = new AvatarQueryOnSignal(_s.getName(), getSignal(_s.getSignal()),
                            getAttributeByName(_s.getVariable().replaceAll("\\.", "__"),_b), null, _b);
                case AvatarFromSysMLSyntax.STXSTOPSTATE :
                case AvatarFromSysMLSyntax.STXSENDSTATE :
                case AvatarFromSysMLSyntax.STXRECEIVESTATE :
Sophie Coudert's avatar
Sophie Coudert committed
                    s = new AvatarActionOnSignal(_s.getName(), null, null, _b);
                    break;
                case AvatarFromSysMLSyntax.STXPRESENDSTATE :
                case AvatarFromSysMLSyntax.STXPRERECEIVESTATE :
                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.BUGERROR, null,
                            "adding precom state (AvatarFromSysML.getState)", null));
                    break;
                case AvatarFromSysMLSyntax.STXSETTIMERSTATE :
                    s = new AvatarSetTimer(_s.getName(), null, _b);
                    break;
                case AvatarFromSysMLSyntax.STXRESETTIMERSTATE :
                    s = new AvatarResetTimer(_s.getName(), null, _b);
                    break;
                case AvatarFromSysMLSyntax.STXEXPIRETIMERSTATE :
                    s = new AvatarExpireTimer(_s.getName(), null, _b);
            }
            if (s != null) stateMap.put(_s, s);
        }
        return s;
    }
    // BUILDING DATATYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    private class BuildDataType implements BiConsumer<String, StxDataType> {
        private HashMap<String,AvatarDataType> dataTypeMap;
        private HashMap<AvatarAttribute,String> attributeMap;

        public BuildDataType(HashMap<String,AvatarDataType> _dataTypeMap, HashMap<AvatarAttribute,String> _attributeMap) {
            dataTypeMap = _dataTypeMap;
            attributeMap = _attributeMap;
        }
        public void accept(String n, StxDataType d) {
Sophie Coudert's avatar
Sophie Coudert committed
            AvatarDataType dataType = new AvatarDataType(d.getName(),null);
Sophie Coudert's avatar
Sophie Coudert committed
            avSpec.addDataType(dataType);
            dataTypeMap.put(d.getName(), dataType);
            int nbFields = d.getSize();
            for (int i = 0; i < nbFields; i++) {
                StxField f = d.getField(i);
                String type =  f.getType();
                AvatarAttribute aa;
                if(type.equals("Integer"))
                    aa = new AvatarAttribute(f.getName(),AvatarType.INTEGER,null,null);
                else if(type.equals("Boolean"))
                    aa = new AvatarAttribute(f.getName(),AvatarType.BOOLEAN,null,null);
Sophie Coudert's avatar
Sophie Coudert committed
                else {
                    aa = new AvatarAttribute(f.getName(), AvatarType.UNDEFINED, null, null);
                    attributeMap.put(aa, type);
Sophie Coudert's avatar
Sophie Coudert committed
                }
                String initVal = f.getInitialValue().trim();
                if(f.getDefaultValue() && initVal.equals(aa.getType().getDefaultInitialValue()))
                    aa.setInitialValue("");
                else aa.setInitialValue(initVal);

                dataType.addAttribute(aa);
    private class CompleteDataTypeAttribute implements BiConsumer<AvatarAttribute,String> {
        HashMap<String,AvatarDataType> dataTypeMap;
        public CompleteDataTypeAttribute(HashMap<String,AvatarDataType> _dataTypeMap) { dataTypeMap = _dataTypeMap;}
        public void accept(AvatarAttribute aa, String dt) {
            AvatarDataType adt = dataTypeMap.get(dt);
            if (adt == null) {
Sophie Coudert's avatar
Sophie Coudert committed
                errors.add(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, "datatype " + dt + " in datatype field " +
                        aa.getName() + " is undefined"));
                aa.setType(AvatarType.INTEGER);
            }
            else aa.setDataType(adt);}
    }
    private void buildDataTypes(){
        List<AvatarDataType> dtList = avSpec.getDataTypes();
        HashMap<String,AvatarDataType> dataTypeMap = new HashMap<String,AvatarDataType>();
        HashMap<AvatarAttribute,String> attributeMap = new HashMap<AvatarAttribute,String>();
        stxSpec.getDataTypeMap().forEach(new BuildDataType(dataTypeMap, attributeMap));
        attributeMap.forEach(new CompleteDataTypeAttribute(dataTypeMap));

        List<String> err = new ArrayList<String>();
        primitiveFieldsMap = AvatarDataTypePrimitiveFields.buildMap(dtList, err);
        for(String e : err) errors.add(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR,e));
    Location location = null;
    // BUILDING BLOCKS (but not statemachines) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    private class BuildBlock implements BiConsumer<String, StxBlock> {
        List<AvatarDataType> dataTypeList;
        public BuildBlock(){}
        public void accept(String n, StxBlock blk) {
Sophie Coudert's avatar
Sophie Coudert committed
            if (!blk.isDeclared()) {
                addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR,
                        "block " + blk.getName() +"has been used but has not been declared"));
                return;
Sophie Coudert's avatar
Sophie Coudert committed
            }
            AvatarBlock theBlock = getBlock(blk);
            avSpec.addBlock(theBlock);
            // set father
            StxBlock fth = blk.getFather();
            if (fth != null) theBlock.setFather(getBlock(fth));
            // add Attributes
            int size = blk.getNbAttributes();
            for (int i = 0; i < size; i++) {
                StxAttribute a = blk.getAttribute(i);
                String initVal = a.getInit().trim();
                if (a.getType().equals("Integer")) {
                    aa = new AvatarAttribute(a.getName(), AvatarType.INTEGER, theBlock, null);
                    ax = new AvatarAttribute(a.getName(), AvatarType.INTEGER, theBlock, null);
                    if(a.getDefaultValue() && initVal.equals(AvatarType.INTEGER.getDefaultInitialValue()))
                        initVal = "";
                    aa.setInitialValue(initVal);
                    ax.setInitialValue(initVal);
                    theBlock.addAttribute(ax);
                    ax.setAsConstant(false);
                }
                else if (a.getType().equals("Boolean")) {
                    aa = new AvatarAttribute(a.getName(), AvatarType.BOOLEAN, theBlock, null);
                    ax = new AvatarAttribute(a.getName(), AvatarType.BOOLEAN, theBlock, null);
                    if(a.getDefaultValue() && initVal.equals(AvatarType.BOOLEAN.getDefaultInitialValue()))
                        initVal = "";
                    aa.setInitialValue(initVal);
                    ax.setInitialValue(initVal);
                    theBlock.addAttribute(ax);
                    ax.setAsConstant(false);
                    aa = new AvatarAttribute(a.getName(), AvatarType.UNDEFINED, theBlock, null);
Sophie Coudert's avatar
Sophie Coudert committed
                    AvatarDataType adt = avSpec.getDataTypeByName(a.getType());
                    aa.setDataType(adt);
                    String aaName =  a.getName() + "__";
                    AvatarDataTypePrimitiveFields primitiveFields = primitiveFieldsMap.get(adt);
Sophie Coudert's avatar
Sophie Coudert committed
                    int dtsize = primitiveFields.size();
                    for (int j = 0; j < dtsize; j++) {
                        ax = new AvatarAttribute(aaName + primitiveFields.getName(j),
                                primitiveFields.getType(j), theBlock, null);
                        theBlock.addAttribute(ax);
                        ax.setAsConstant(false);
                    }
                theBlock.addOriginalAttribute(aa);
                aa.setAsConstant(false);
            }
            // add Constants
            size = blk.getNbConstants();
            for (int i = 0; i < size; i++) {
                StxAttribute a = blk.getConstant(i);
                String initVal = a.getInit().trim();
                AvatarAttribute aa = null;
                if (a.getType().equals("Integer")) {
                    aa = new AvatarAttribute(a.getName(), AvatarType.INTEGER, theBlock, null);
                    theBlock.addOriginalAttribute(aa);
                    aa.setAsConstant(true);
                    ax = new AvatarAttribute(a.getName(), AvatarType.INTEGER, theBlock, null);
                    theBlock.addAttribute(ax);
                    ax.setAsConstant(true);
                    if(a.getDefaultValue() && initVal.equals(AvatarType.INTEGER.getDefaultInitialValue()))
                        initVal = "";
                    aa.setInitialValue(initVal);
                    ax.setInitialValue(initVal);
                }
                else if (a.getType().equals("Boolean")) {
                    aa = new AvatarAttribute(a.getName(), AvatarType.BOOLEAN, theBlock, null);
                    theBlock.addOriginalAttribute(aa);
                    aa.setAsConstant(true);
                    ax = new AvatarAttribute(a.getName(), AvatarType.BOOLEAN, theBlock, null);
                    theBlock.addAttribute(ax);
                    ax.setAsConstant(true);
                    if(a.getDefaultValue() && initVal.equals(AvatarType.BOOLEAN.getDefaultInitialValue()))
                        initVal = "";
                    aa.setInitialValue(initVal);
                    ax.setInitialValue(initVal);
                else
                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR,
                            a.getLeft(), "datatype for constants is not supported", null));
            // add Timers
            size = blk.getNbTimers();
            for (int i = 0; i < size; i++) {
                AvatarAttribute aa = new AvatarAttribute(blk.getTimer(i).getName(), AvatarType.TIMER, theBlock, null);
                theBlock.addOriginalAttribute(aa);
                aa.setAsConstant(false);
                aa = new AvatarAttribute(blk.getTimer(i).getName(), AvatarType.TIMER, theBlock, null);
                theBlock.addAttribute(aa);
                aa.setAsConstant(false);
           }
            // add Methods
            size = blk.getNbMethods();
            for (int i = 0; i < size; i++) {
                StxMethod sm = blk.getMethod(i);
                AvatarMethod am = new AvatarMethod(sm.getName(),null);
                theBlock.addMethod(am);
                buildProfile(sm, am, theBlock);
                String returnType = sm.getReturnType();
Sophie Coudert's avatar
Sophie Coudert committed
                if (returnType == null || returnType.length() == 0) continue;
                if (returnType.equals("Integer")) {
                    am.addReturnParameter(new AvatarAttribute("return__0", AvatarType.INTEGER, theBlock, null));
                    am.addOriginalReturnParameter(new AvatarAttribute("return__", AvatarType.INTEGER, theBlock, null));
               }
                else if (returnType.equals("Boolean")) {
                    am.addReturnParameter(new AvatarAttribute("return__0", AvatarType.BOOLEAN, theBlock, null));
                    am.addOriginalReturnParameter(new AvatarAttribute("return__", AvatarType.BOOLEAN, theBlock, null));
                }
               else {
Sophie Coudert's avatar
Sophie Coudert committed
                    AvatarDataType adt = avSpec.getDataTypeByName(returnType);
Sophie Coudert's avatar
Sophie Coudert committed
                    if (adt == null)
                        addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, sm.getLeft(),
                                "unknown type for method return parameter", null));
                    AvatarAttribute ret = new AvatarAttribute("return__", AvatarType.UNDEFINED, theBlock, null);
Sophie Coudert's avatar
Sophie Coudert committed
                    ret.setDataType(adt);
                    am.addOriginalReturnParameter(ret);
                    AvatarDataTypePrimitiveFields primitiveFields = primitiveFieldsMap.get(adt);
Sophie Coudert's avatar
Sophie Coudert committed
                    int dtsize = primitiveFields.size();
                    for (int j = 0; j < dtsize; j++) {
                        ret = new AvatarAttribute("return__" + j,
                                 primitiveFields.getType(j), theBlock, null);
                        am.addReturnParameter(ret);
                    }
                }
            }
            // add Signals (build profile delayed)
            size = blk.getNbSignals();
            for (int i = 0; i < size; i++) {
                StxSignal ss = blk.getSignal(i);
                AvatarSignal as = getSignal(ss);
                if (!ss.isDeclared()) {
                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, ss.getLeft(),
                            "signal " + theBlock.getName() + "." + ss.getName() + " has not been declared"));
                    continue;
                }
                theBlock.addSignal(as);
Sophie Coudert's avatar
Sophie Coudert committed
                StxChannel ch = ss.getChannel();
                if (ch == null) {
                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, ss.getLeft(),
                            "channel of signal " + ss.getName() + " has not been set"));
                    continue;
                }
                if (!ch.isDeclared()) {
                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, ss.getLeft(),
                            "channel of signal " + theBlock.getName() + "." + ss.getName() + " has not been declared"));
                    continue;
                }
                if (ss.isInput()) {
                    StxInMessage im = ss.getChannel().getInProfile();
                    if (im == null) {
                        addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, ss.getLeft(),
                                "input profile of signal " + ss.getName() + " has not been set"));
                        continue;
                    }
                    buildProfile(im, as, theBlock);
                }
                else {
                    StxOutMessage om = ss.getChannel().getOutProfile();
                    if (om == null) {
                        addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, ss.getLeft(),
                                "output profile of signal " + ss.getName() + " has not been set"));
                        continue;
                    }
                    buildProfile(om, as, theBlock);
                }
        }
    }
    private class BuildStateMachine implements BiConsumer<String, StxBlock> {
        List<AvatarDataType> dataTypeList;
        public BuildStateMachine(){}
        public void accept(String n, StxBlock blk) {
            AvatarBlock theBlock = getBlock(blk);
            StxState[] states = blk.getStates();
            AvatarStateMachine asm = theBlock.getStateMachine();
            AvatarStateMachineElement theSourceState;
            transitionMap.clear();
            int size = states.length;
            for (int i = 0; i < size; i++) {
                byte stateType = states[i].getType();
                boolean undeclaredState = false;
Sophie Coudert's avatar
Sophie Coudert committed
                if (! states[i].isDeclared()) {
                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR,
                            "state " + theBlock.getName() + "." + states[i].getName() + " is used but not declared"));
                    stateType = AvatarFromSysMLSyntax.STXSTANDARDSTATE;
                    undeclaredState = true;
Sophie Coudert's avatar
Sophie Coudert committed
                }
                if (stateType != AvatarFromSysMLSyntax.STXPRESENDSTATE &&
                        stateType != AvatarFromSysMLSyntax.STXPRERECEIVESTATE &&
                        stateType != AvatarFromSysMLSyntax.STXSTOPSTATE ) {
                    if (undeclaredState) {
                        states[i].setType(AvatarFromSysMLSyntax.STXSTANDARDSTATE);
                    }
                    theSourceState = getState(states[i], theBlock);
                    addState(theSourceState, theBlock);
                    asm.addElement(theSourceState);
                    if (stateType == AvatarFromSysMLSyntax.STXRANDOMSTATE) {
                        ((AvatarRandom) theSourceState).setOriginalValues(states[i].getMinValue(), states[i].getMaxValue());
                        ((AvatarRandom) theSourceState).setValues(
                                states[i].getMinValue().replaceAll("\\.", "__"),
                                states[i].getMaxValue().replaceAll("\\.", "__"));
                        ((AvatarRandom) theSourceState).setVariable(states[i].getVariable().replaceAll("\\.", "__"));
                    } else if (stateType == AvatarFromSysMLSyntax.STXSTARTSTATE)
                        asm.setStartState((AvatarStartState) theSourceState);
                    List<StxTransition> transitions = states[i].getTransitions();
                    int tsize = transitions.size();
                    if (tsize > 1 && stateType != AvatarFromSysMLSyntax.STXSTANDARDSTATE) {
                        tsize = 1;
                        addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, states[i].getTransitions().get(1).getLeft(),
                                "state " + states[i].getName() + " only accept one single outgoing transition",
                                states[i].getTransitions().get(1).getRleft()));
                    }
                    for (int j = 0; j < tsize; j++) {
                        StxTransition transition = transitions.get(j);
Sophie Coudert's avatar
Sophie Coudert committed
                        if (transition == null) {
                            addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, states[i].getLeft(),
                                    "something is wrong in state " + states[i].getName() + " : null transition found"));
                            continue;
                        }
                        if (! transition.isDeclared()) {
                            addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getRleft(),
                                    "transition request in state " + states[i].getName() + " of block " + theBlock.getName() +
                                            " has no associated declaration" ));
Sophie Coudert's avatar
Sophie Coudert committed
                            continue;
                        }
                        if (! transition.isRequested()) {
                            addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getLeft(),
                                    "transition has no request in state " + states[i].getName()));
                            continue;
                        }
                        AvatarTransition theTransition = new AvatarTransition(theBlock,"", null);
                        if (transition.getGuard() != null) {
                            theTransition.setGuard(
                                    "[" + transition.getGuard().replaceAll("\\.", "__") + "]",
                                    "[" + transition.getGuard() + "]");
                        }
                        String minDelay = transition.getMinDelay().trim();
                        String maxDelay = transition.getMaxDelay().trim();
                        if (minDelay.equals(maxDelay)) maxDelay = "";
                        theTransition.setDelays(
                                minDelay.replaceAll("\\.", "__"),
                                maxDelay.replaceAll("\\.", "__"),
                                minDelay,
                                maxDelay);
Sophie Coudert's avatar
Sophie Coudert committed
                        setDistributionLaw(theTransition, transition.getDelayDistributionLaw(),transition.getDelayExtra(), transition);
                        theTransition.setProbability(transition.getProbability());
                        // add actions
                        List<StxAction> actions = transition.getActions(); // should exist only in some cases...
                        int asize = actions.size();
                        for (int k = 0; k < asize; k++) {
                            StxAction action = actions.get(k);
                            location = action.getLeft();
                            if(action.getType() == AvatarFromSysMLSyntax.STXASSIGNACTION){
                                String originalLeftHandStr = action.getTarget();
                                String leftHandStr = extendIdent(action.getTarget().replaceAll("\\.", "__"), blk);
                                String originalRightHandStr;
                                String rightHandStr;
                                StxTerm value = action.getValue();
                                if (value instanceof StxId) {
                                    originalRightHandStr = ((StxId)value).toString();
                                    rightHandStr = ((StxId)value).toString().replaceAll("\\.", "__");
                                }
                                else if (value instanceof StxExpr){
                                    originalRightHandStr = ((StxExpr)value).toString();
                                    rightHandStr = ((StxExpr)value).toString().replaceAll("\\.", "__");
                                }
                                else {
                                    originalRightHandStr = extendOriginalCall((StxCall)value,blk);
                                    rightHandStr = extendCall((StxCall)value,blk);
                                }
                                theTransition.addAction(leftHandStr + "=" + rightHandStr,
                                        originalLeftHandStr + "=" + originalRightHandStr);
                            }
                            else { // STXMETHODACTION
                                if (action.getValue() instanceof StxCall) { // else ERROR
                                    String originalTermStr = extendOriginalCall((StxCall)action.getValue(),blk);
                                    String termStr = extendCall((StxCall)action.getValue(),blk);
                                    theTransition.addAction(termStr, originalTermStr);
Sophie Coudert's avatar
Sophie Coudert committed
                        if (transition.getTarget() == null) {
                            addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getRleft(),
                                    "something is wrong in transition : no target defined", transition.getLeft()));
Sophie Coudert's avatar
Sophie Coudert committed
                            continue;
                        }
                        if (transition.getTarget().getType() == AvatarFromSysMLSyntax.STXPRESENDSTATE ||
                                transition.getTarget().getType() == AvatarFromSysMLSyntax.STXPRERECEIVESTATE) {
Sophie Coudert's avatar
Sophie Coudert committed
                            if (transition.getTarget().getTransitions().size() == 0 ||
                                    transition.getTarget().getTransition(0) == null) {
Sophie Coudert's avatar
Sophie Coudert committed
                                addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getTarget().getLeft(),
                                        "something is wrong in precommunication state " + transition.getTarget().getName() +
                                                " : no outgoing transition"));
Sophie Coudert's avatar
Sophie Coudert committed
                                continue;
                            }
                            byte type = transition.getTarget().getType();
                            transition = transition.getTarget().getTransition(0);
Sophie Coudert's avatar
Sophie Coudert committed
                            if (type == AvatarFromSysMLSyntax.STXPRESENDSTATE &
                                    ! ( ( transition.getTarget().getType() == AvatarFromSysMLSyntax.STXSENDSTATE &&
                                            transition.getType() == AvatarFromSysMLSyntax.STXSENDTRANSITION ) ||
                                            ( transition.getTarget().getType() == AvatarFromSysMLSyntax.STXSETTIMERSTATE &&
                                                    transition.getType() == AvatarFromSysMLSyntax.STXSETTIMERTRANSITION ) ||
                                            ( transition.getTarget().getType() == AvatarFromSysMLSyntax.STXRESETTIMERSTATE &&
                                                    transition.getType() == AvatarFromSysMLSyntax.STXRESETTIMERTRANSITION ) )) {
Sophie Coudert's avatar
Sophie Coudert committed
                                addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getTarget().getLeft(),
                                        "outgoing transitions from pre-send state must be sending transitions leading to some sending state " +
                                                "(send/set timer /reset timer)", transition.getLeft()));
                                continue;
                            }
                            if (type == AvatarFromSysMLSyntax.STXPRERECEIVESTATE &
                                    ! ( ( transition.getTarget().getType() == AvatarFromSysMLSyntax.STXRECEIVESTATE &&
                                            transition.getType() == AvatarFromSysMLSyntax.STXRECEIVETRANSITION ) ||
                                            ( transition.getTarget().getType() == AvatarFromSysMLSyntax.STXEXPIRETIMERSTATE &&
                                                    transition.getType() == AvatarFromSysMLSyntax.STXEXPIRETIMERTRANSITION ) )) {
Sophie Coudert's avatar
Sophie Coudert committed
                                addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getTarget().getLeft(),
                                        "outgoing transitions from pre-reveive state must be sending transitions leading to some " +
                                                "receivinging state (receive/expire timer)", transition.getLeft()));
                                continue;
                            }
                        }
                        AvatarStateMachineElement tgtState;
                        if (transition.getTarget().getType() == AvatarFromSysMLSyntax.STXSTOPSTATE) {
Sophie Coudert's avatar
Sophie Coudert committed
                            if (transition.getTarget().getTransitions().size() != 0) {
                                addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWWARNING, transition.getTarget().getLeft(),
                                        "stopstate should not have outgoing transitions"));
                            }
                            tgtState = new AvatarStopState("StopState", null, theBlock);
                            addState(tgtState, theBlock);
Sophie Coudert's avatar
Sophie Coudert committed
                        else tgtState = getState(transition.getTarget(), theBlock);
                        addState(tgtState, theBlock);
                        byte tgtType = transition.getTarget().getType();
                        Location tgtLoc = transition.getTarget().getLeft();
                        if (transition.getType() == AvatarFromSysMLSyntax.STXSENDTRANSITION) {
                            if(tgtState instanceof AvatarActionOnSignal) {
                                AvatarActionOnSignal state = (AvatarActionOnSignal)tgtState;
Sophie Coudert's avatar
Sophie Coudert committed
                                if (transition.getSignal() == null) {
                                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getRleft(),
                                            "sending transition should have an associated signal", transition.getLeft()));
                                    continue;
                                }
                                state.setSignal( getSignal(transition.getSignal()));
Sophie Coudert's avatar
Sophie Coudert committed
                                if (state.getSignal().isIn()) {
                                    new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getRleft(),
                                            "signal of sending transition must be an output signal", transition.getSignal().getLeft());
                                    continue;
                                }
                                if (! transition.getSignal().isDeclared()) {
                                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, transition.getRleft(),
                                            "transition uses a signal " + transition.getSignal().getName() + " that has not been declared"));
                                    continue;
                                }
                                location = transition.getRleft();
                                ArrayList<StxTerm> sendPayload = transition.getSendPayload();
Sophie Coudert's avatar
Sophie Coudert committed
                                if (sendPayload != null) {
                                    int nbParam = sendPayload.size();
                                    for(int u = 0; u < nbParam; u++) {
                                        StxTerm p = sendPayload.get(u);
                                        if (p instanceof StxId) {
                                            state.addOriginalValue(p.toString());
                                            String[] ids;
                                            String extendedPath = extendPath(p.toString().replaceAll("\\.", "__"), blk);
                                            if (extendedPath == null) {
                                                addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, p.getLeft(), "attribute \"" +
                                                        p.toString() + "\" cannot be typed"));
                                                AvatarDataType adt = state.getSignal().getListOfOriginalAttributes().get(u).getDataType();
                                                if (adt == null) {
                                                    ids = new String[1];
                                                    ids[0] = p.toString();
                                                } else {
                                                    ids = extendName(p.toString().replaceAll("\\.", "__"),adt).split(",");
                                                }
                                            }
                                            else ids = extendedPath.split(",");
                                            int isize = ids.length;
                                            for (int w = 0; w < isize; w++) state.addValue(ids[w]);
                                        }
                                        else if (p instanceof StxExpr) {
                                            state.addOriginalValue( p.toString() );
                                            state.addValue( p.toString().replaceAll("\\.", "__"));
                                        }
                                        else {
                                            state.addOriginalValue(extendOriginalCall((StxCall)p,blk));
                                            state.addValue(extendCall((StxCall)p,blk));
                                        }
Sophie Coudert's avatar
Sophie Coudert committed
                            else  {
                                addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getLeft(),
                                        "sending transition should lead to a send state", transition.getRleft()));
                                continue;
Sophie Coudert's avatar
Sophie Coudert committed
                            }
                        }
                        else if (transition.getType() == AvatarFromSysMLSyntax.STXRECEIVETRANSITION) {
                            if(tgtState instanceof AvatarActionOnSignal) {
                                AvatarActionOnSignal state = (AvatarActionOnSignal)tgtState;
Sophie Coudert's avatar
Sophie Coudert committed
                                if (transition.getSignal() == null) {
                                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getRleft(),
                                            "receiving transition should have an associated signal", transition.getLeft()));
                                    continue;
                                }
                                state.setSignal(getSignal(transition.getSignal()));
Sophie Coudert's avatar
Sophie Coudert committed
                                if (! transition.getSignal().isDeclared()) {
                                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, transition.getRleft(),
                                            "transition uses a signal " + transition.getSignal().getName() + " that has not been declared"));
Sophie Coudert's avatar
Sophie Coudert committed
                                    continue;
                                }
                                if (state.getSignal().isOut()) {
                                    new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getRleft(),
                                            "signal of receiving transition must be an input signal", transition.getSignal().getLeft());
                                    continue;
                                }
                                if (transition.getSignal().getChannel() == null) {
                                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getRleft(),
                                            "signal of receiving transition doesn't have an associated channel", transition.getSignal().getLeft()));
                                    continue;
                                }
                                location = transition.getLeft();
                                List<AvatarAttribute> profile = state.getSignal().getListOfOriginalAttributes();
                                if (profile != null && !profile.isEmpty()) {
Sophie Coudert's avatar
Sophie Coudert committed
                                    HashMap<String, String> receivePayload = transition.getReceivePayload();
                                    int nbParams = profile.size();
Sophie Coudert's avatar
Sophie Coudert committed
                                    for (int k = 0; k < nbParams; k++) {
                                        AvatarAttribute aa = profile.get(k);
                                        String value;
                                        if (aa == null) {
                                            addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, transition.getLeft(),
                                                    "parameter " + k + " of signal " + state.getSignal().getName() +
                                                            " is not well defined"));
                                            value = "";
                                        } else {
                                            value = receivePayload.get(aa.getName());
                                            if (value == null) {
                                                addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, transition.getLeft(),
                                                        "receiving transition has a missing field"));
                                                value = "";
                                            }
                                        }
                                        state.addOriginalValue(value);

                                        String[] ids;
                                        String extendedPath = extendPath(value.replaceAll("\\.", "__"), blk);
                                        if (extendedPath == null) {
                                            addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, location, "attribute \"" +
                                                    value + "\" cannot be typed"));
                                            AvatarDataType adt = profile.get(k).getDataType();
                                            if (adt == null) {
                                                ids = new String[1];
                                                ids[0] = value;
                                            } else {
                                                ids = extendName(value.replaceAll("\\.", "__"),adt).split(",");
                                            }
                                        }
                                        else ids = extendedPath.split(",");
                                        int isize = ids.length;
                                        for (int w = 0; w < isize; w++) state.addValue(ids[w]);
Sophie Coudert's avatar
Sophie Coudert committed
                                    }
Sophie Coudert's avatar
Sophie Coudert committed
                            else  {
                                addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getLeft(),
                                        "receiving transition should lead to a receive state", transition.getRleft()));
                                continue;
Sophie Coudert's avatar
Sophie Coudert committed
                            }
Sophie Coudert's avatar
Sophie Coudert committed

                        }
                        else if (transition.getType() == AvatarFromSysMLSyntax.STXSETTIMERTRANSITION) {
                            if(tgtState instanceof AvatarSetTimer) {
                                AvatarSetTimer state = (AvatarSetTimer) tgtState;
                                if (transition.getTimer() == null) {
                                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getLeft(),
                                            "set-timer transition has no associated timer", transition.getRleft()));
                                    continue;
                                }
                                state.setTimer(getTimerByName(transition.getTimer(), theBlock));
                                if (transition.getSendPayload() == null || transition.getSendPayload().size() != 1
                                        || !(transition.getSendPayload().get(0) instanceof StxExpr)) {
                                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getLeft(),
                                            "payload of set-timer transition is not well formed", transition.getRleft()));
                                    continue;
                                }
                                state.setTimerValue(((StxExpr)transition.getSendPayload().get(0)).toString().replaceAll(".","__"));
                                state.setTimerOriginalValue(((StxExpr)transition.getSendPayload().get(0)).toString());
                            }
                            else  {
                                addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getLeft(),
                                        "set-timer transition should lead to a set-timer state", transition.getRleft()));
                                continue;
                            }
                        }
                        else if (transition.getType() == AvatarFromSysMLSyntax.STXRESETTIMERTRANSITION) {
                            if(tgtState instanceof AvatarResetTimer) {
                                AvatarResetTimer state = (AvatarResetTimer) tgtState;
Sophie Coudert's avatar
Sophie Coudert committed
                                if (transition.getTimer() == null) {
                                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getLeft(),
                                            "reset-timer transition has no associated timer", transition.getRleft()));
                                    continue;
Sophie Coudert's avatar
Sophie Coudert committed
                                }
                                state.setTimer(getTimerByName(transition.getTimer(), theBlock));
                            }
                            else  {
                                addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getLeft(),
                                        "reset-timer transition should lead to a reset-timer state", transition.getRleft()));
                                continue;
                            }
                        }
                        else if (transition.getType() == AvatarFromSysMLSyntax.STXEXPIRETIMERTRANSITION) {
                            if(tgtState instanceof AvatarExpireTimer) {
                                AvatarExpireTimer state = (AvatarExpireTimer) tgtState;
Sophie Coudert's avatar
Sophie Coudert committed
                                if (transition.getTimer() == null) {
                                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getLeft(),
                                            "expire-timer transition has no associated timer", transition.getRleft()));
                                    continue;
Sophie Coudert's avatar
Sophie Coudert committed
                                }
                                state.setTimer(getTimerByName(transition.getTimer(), theBlock));
                            else  {
                                addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getLeft(),
                                        "expire-timer transition should lead to a expire-timer state", transition.getRleft()));
                                continue;
                            }
                        else if (! (tgtType == AvatarFromSysMLSyntax.STXSTOPSTATE ||
                                tgtType == AvatarFromSysMLSyntax.STXSTANDARDSTATE ||
                                tgtType == AvatarFromSysMLSyntax.STXRANDOMSTATE ||
                                tgtType == AvatarFromSysMLSyntax.STXCOUNTSTATE ||
                                tgtType == AvatarFromSysMLSyntax.STXSTARTSTATE) ) {
                            addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, transition.getLeft(),
                                    "transition type is not consistant with the type of its target state", tgtLoc));
                            continue;
                        }
                        asm.addElement(theTransition);
                        theSourceState.addNext(theTransition);
                        addTransition(theTransition, tgtState);
Sophie Coudert's avatar
Sophie Coudert committed
                        theTransition.addNext(tgtState);
                    }
                }
            }
            transitionMap.forEach(new CheckIncommings());
        }
    }
    private class CheckIncommings implements BiConsumer<AvatarStateMachineElement, StateTransitions> {
        List<AvatarDataType> dataTypeList;
        public CheckIncommings(){}
        public void accept(AvatarStateMachineElement e, StateTransitions st) {
            int s = st.getTransitions().size();
            if (s == 0 && ! (e instanceof AvatarStartState)) {
                addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, "state " + e.getName() +
                        " of block " + st.getBlock().getName() + " is unreachable --> removed"));
                st.getBlock().getStateMachine().removeElement(e);
                for(AvatarStateMachineElement x : e.getNexts())
                    st.getBlock().getStateMachine().removeElement(x);
            }
            if (s > 0 && (e instanceof AvatarStartState)) {
                addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, "start state in bloc " +
                        st.getBlock().getName() + " has some input transition"));
                for(int i = 0; i < s; i++) {
                    st.getTransitions().get(i).getNexts().clear();
                    AvatarStopState nw = new AvatarStopState("errorstate",null, st.getBlock());
                    st.getTransitions().get(i).addNext(nw);
                    st.getBlock().getStateMachine().addElement(nw);
            if (s > 1 && !(e instanceof AvatarStartState || e instanceof AvatarStateElement)) {
                addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, "state " + e.getName() + " in bloc " +
                        st.getBlock().getName() + " has more than one incomming transition"));

                for(int i = 1; i < s; i++) {
                    st.getTransitions().get(i).getNexts().clear();
                    AvatarStopState nw = new AvatarStopState("errorstate",null, st.getBlock());
                    st.getTransitions().get(i).addNext(nw);
                    st.getBlock().getStateMachine().addElement(nw);
        }
    }
    private void buildBlocks(){
        stxSpec.getBlockMap().forEach(new BuildBlock());
        stxSpec.getBlockMap().forEach(new BuildStateMachine());
Sophie Coudert's avatar
Sophie Coudert committed
    private void setDistributionLaw(AvatarTransition _t, String distributionLaw, HashMap<String,String> delayExtra, StxTransition _st) {
        int law = -1;
        int size;
        if (distributionLaw == null || distributionLaw.equals("")) law = AvatarTransition.DELAY_UNIFORM_LAW;
        else {
            size = _t.DISTRIBUTION_LAWS.length;
            for (int i = 0; i < size; i++) {
                if (_t.DISTRIBUTION_LAWS[i].equals(distributionLaw)) {
                    law = i;
                    break;
                }
            }
Sophie Coudert's avatar
Sophie Coudert committed
            if (law == -1) {
                addError(new AvatarFromSysMLError(AvatarFromSysMLError.HIGHERROR, _st.getLeft(),
                 "transition with unknown transition law : " + distributionLaw + " (set to uniform)"));
                law = AvatarTransition.DELAY_UNIFORM_LAW;
            }
        }
        String extra1 = _t.LABELS_OF_EXTRA_ATTRIBUTES_1[law];
        String extra2 = _t.LABELS_OF_EXTRA_ATTRIBUTES_2[law];
        size = _t.NB_OF_EXTRA_ATTRIBUTES[law];
Sophie Coudert's avatar
Sophie Coudert committed
        String tmpString;
Sophie Coudert's avatar
Sophie Coudert committed
            tmpString = extra1;
            extra1 = delayExtra.get(extra1);
Sophie Coudert's avatar
Sophie Coudert committed
            if (extra1 == null) {
                addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, _st.getLeft(),
                 "transition law : " + distributionLaw + " requires a " + tmpString + " parameter"));
            }
Sophie Coudert's avatar
Sophie Coudert committed
                tmpString = extra2;
                extra2 = delayExtra.get(extra2);
Sophie Coudert's avatar
Sophie Coudert committed
                if (extra2 == null) {
                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWERROR, _st.getLeft(),
                     "transition law : " + distributionLaw + " requires a " + tmpString + " parameter"));
                }
Sophie Coudert's avatar
Sophie Coudert committed
        if (delayExtra != null && delayExtra.size() > size) {
Sophie Coudert's avatar
Sophie Coudert committed
                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWWARNING, _st.getLeft(),
                     "transition law : " + distributionLaw + " has too much parameters"));

        }
        _t.setDistributionLaw(law, extra1, extra2);
    }
    private void buildProfile(StxStructure ss, AvatarMethod am, AvatarBlock b) {
        AvatarAttribute aa;
        int size = ss.getSize();
        for (int i = 0; i < size; i++) {
            String type = ss.getFieldType(i);
            if (type.equals("Integer")){
                aa = new AvatarAttribute(ss.getFieldName(i), AvatarType.INTEGER, b, null);
Sophie Coudert's avatar
Sophie Coudert committed
                am.addOriginalParameter(aa);
                aa.setAsConstant(false);
                aa = new AvatarAttribute(ss.getFieldName(i), AvatarType.INTEGER, b, null);
                am.addParameter(aa);
                aa.setAsConstant(false);
           } else if (type.equals("Boolean")) {
                aa = new AvatarAttribute(ss.getFieldName(i), AvatarType.BOOLEAN, b, null);
Sophie Coudert's avatar
Sophie Coudert committed
                am.addOriginalParameter(aa);
                aa.setAsConstant(false);
                aa = new AvatarAttribute(ss.getFieldName(i), AvatarType.BOOLEAN, b, null);
                am.addParameter(aa);
                aa.setAsConstant(false);
Sophie Coudert's avatar
Sophie Coudert committed
                AvatarDataType adt = avSpec.getDataTypeByName(type);
Sophie Coudert's avatar
Sophie Coudert committed
                if (adt == null) {
                    addError(new AvatarFromSysMLError(AvatarFromSysMLError.LOWWARNING, ss.getLeft(),
                     "message profile uses undefined datatype " + type));
                String aaName = ss.getFieldName(i);
                aa = new AvatarAttribute(aaName, AvatarType.UNDEFINED, b, null);
Sophie Coudert's avatar
Sophie Coudert committed
                aa.setDataType(adt);
                am.addOriginalParameter(aa);
                aa.setAsConstant(false);
                aaName = aaName + "__";
                AvatarDataTypePrimitiveFields primitiveFields = primitiveFieldsMap.get(adt);
Sophie Coudert's avatar
Sophie Coudert committed
                int dtsize = primitiveFields.size();
                for (int j = 0; j < dtsize; j++) {
                    aa = new AvatarAttribute(aaName + primitiveFields.getName(j),
                             primitiveFields.getType(j), b, null);
                    am.addParameter(aa);
                    aa.setAsConstant(false);
                }
           }
        }
    }
    private String getStxAttributeType(String name, StxBlock blk){
        int size = blk.getNbAttributes();
        for (int i = 0; i < size; i++) {
            if (blk.getAttribute(i).getName().equals(name)) return blk.getAttribute(i).getType();
        }
        return null;
    }
    private String getStxPathType(String s, StxBlock b) {
        String[] path = s.split("__");
        String type = getStxAttributeType(path[0], b);
        int size = path.length;
        for (int i = 1; i < size; i++) {
Sophie Coudert's avatar
Sophie Coudert committed
            AvatarDataType adt = avSpec.getDataTypeByName(type);
            if (adt == null) return null;
            int nbFields = adt.attributeNb();
            int j;
            for (j = 0; j < nbFields; j++)
Sophie Coudert's avatar
Sophie Coudert committed
                if (adt.getAttribute(j).getName().equals(path[i])) break;
            if (j == nbFields) return null;