diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index 2b63946d5b31084bbb7dda418ceb3d75eb686373..0000000000000000000000000000000000000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="Palette2"> - <group name="Swing"> - <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> - </item> - <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> - </item> - <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> - </item> - <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true"> - <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> - </item> - <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> - <initial-values> - <property name="text" value="Button" /> - </initial-values> - </item> - <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> - <initial-values> - <property name="text" value="RadioButton" /> - </initial-values> - </item> - <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> - <initial-values> - <property name="text" value="CheckBox" /> - </initial-values> - </item> - <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> - <initial-values> - <property name="text" value="Label" /> - </initial-values> - </item> - <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> - <preferred-size width="150" height="-1" /> - </default-constraints> - </item> - <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> - <preferred-size width="150" height="-1" /> - </default-constraints> - </item> - <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> - <preferred-size width="150" height="-1" /> - </default-constraints> - </item> - <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> - <preferred-size width="150" height="50" /> - </default-constraints> - </item> - <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> - <preferred-size width="150" height="50" /> - </default-constraints> - </item> - <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> - <preferred-size width="150" height="50" /> - </default-constraints> - </item> - <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> - </item> - <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> - <preferred-size width="150" height="50" /> - </default-constraints> - </item> - <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> - <preferred-size width="150" height="50" /> - </default-constraints> - </item> - <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> - <preferred-size width="150" height="50" /> - </default-constraints> - </item> - <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> - <preferred-size width="200" height="200" /> - </default-constraints> - </item> - <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> - <preferred-size width="200" height="200" /> - </default-constraints> - </item> - <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> - </item> - <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> - </item> - <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> - </item> - <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> - </item> - <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> - <preferred-size width="-1" height="20" /> - </default-constraints> - </item> - <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> - </item> - <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> - </item> - </group> - </component> -</project> \ No newline at end of file diff --git a/src/main/java/avatartranslator/tosysmlv2/Avatar2SysML.java b/src/main/java/avatartranslator/tosysmlv2/Avatar2SysML.java index dd36682fd2dd1e8d813cb2cff7d0679833556a74..562ac1b219a1b607a79c45f8a991a020bfa65563 100644 --- a/src/main/java/avatartranslator/tosysmlv2/Avatar2SysML.java +++ b/src/main/java/avatartranslator/tosysmlv2/Avatar2SysML.java @@ -55,17 +55,68 @@ import java.util.ArrayList; * @version 0.1 20/06/2024 */ public class Avatar2SysML { + /** the source Avatar Specification */ + private AvatarSpecification avspec; + /** the buffer in which theSysML Model is written (returned at the end of the generation process) */ + private StringBuffer avsysml; + /** signals concerned by AvatarQueryOnSignal */ + private HashSet<AvatarSignal> fifoSet = new HashSet<AvatarSignal>(); + private HashMap<AvatarMethod, MethodInfo> methodMap = new HashMap<AvatarMethod, MethodInfo>(); + private HashMap<AvatarStateMachineElement, StateInfo> stateMap = new HashMap<AvatarStateMachineElement, StateInfo>(); + private ArrayList<AvatarStateMachineElement> stateList = new ArrayList<AvatarStateMachineElement>(); + private ArrayList<AvatarAttribute> timerList = new ArrayList<AvatarAttribute>(); + /** path from top level to the block (block sequence) being currently handled */ + private ArrayList<String> blockChain = new ArrayList<String>(); + /** SysML code to make inner blocks visible at top level. Contains one declaration per inner block */ + private StringBuffer blockLinks; + /** the standard indentation step string */ + private final String indentStep = " "; + /** size of the standard indentation step */ + private final int indentStepSize = 4; + /** the current indentation string */ + private String indentation; + + /** (fixed) header for any Avatar SysML model instance */ + private final String header = "package AvatarInstance {\n" + + indentStep + "import ScalarValues::String;\n" + + indentStep + "import ScalarValues::Positive;\n" + + indentStep + "import ScalarValues::Integer;\n" + + indentStep + "import ScalarValues::Boolean;\n" + + indentStep + "import ScalarValues::Real;\n" + + indentStep + "import AvatarBlockTypes::*;\n" + + indentStep + "import AvatarCommunication::*;\n"; + + /** the single constructor */ public Avatar2SysML(AvatarSpecification _avspec) { avspec = _avspec; } - StringBuffer avsysml; - HashSet<AvatarSignal> fifoSet = new HashSet<AvatarSignal>(); - HashMap<AvatarMethod, MethodInfo> methodMap = new HashMap<AvatarMethod, MethodInfo>(); - HashMap<AvatarStateMachineElement, StateInfo> stateMap = new HashMap<AvatarStateMachineElement, StateInfo>(); - ArrayList<AvatarStateMachineElement> stateList = new ArrayList<AvatarStateMachineElement>(); - ArrayList<AvatarAttribute> timerList = new ArrayList<AvatarAttribute>(); - private AvatarSpecification avspec; + /** the generator. Builds the SysML model of the specification provided to the constructor */ + public StringBuffer avatar2SysML() { + fifoSet.clear(); + methodMap.clear(); + stateMap.clear(); + stateList.clear(); + blockChain.clear(); + indentation = ""; + blockLinks = new StringBuffer(indentStep + "// Block Shortcut Links $$$$$$$$$$$$\n"); + avsysml = new StringBuffer(header); + indent(1); + searchCountSignals();; + dataTypes2SysML(); + communications2SysML(); + blocks2SysML(); + avsysml.append(blockLinks); + avsysml.append("}\n"); + return avsysml; + } + + /** increase indentation */ + private void indent(int n) { for (int i= 0; i < n; i++) indent(1); } + /** decrease indentation */ + private void unindent(int n) { indentation = indentation.substring(n * indentStepSize); } - /** to collect infos used later (for example when handling ActionsOnSignal) */ + /** infos collected while generating declarations of methods and signals, to be used later. + * + * (for example when handling ActionsOnSignal) */ static private class MethodInfo { private String name; // method name private String msgtype; // null for methods that are not signals @@ -75,7 +126,8 @@ public class Avatar2SysML { private AvatarType returnType; // int, bool or undefined private AvatarDataType returnDataType; // datatype if returnType is "undefined", otherwise null. - MethodInfo(String _name) { // for void methods + /** for void methods (without return type) */ + MethodInfo(String _name) { name = _name; msgtype = null; fieldNames = new ArrayList<String>(); @@ -85,7 +137,8 @@ public class Avatar2SysML { returnDataType = null; } - MethodInfo(String _name, AvatarType _returnType, AvatarDataType dt) { // for non-void methods + /** for non-void methods (with return type) */ + MethodInfo(String _name, AvatarType _returnType, AvatarDataType dt) { name = _name; msgtype = null; fieldNames = new ArrayList<String>(); @@ -98,7 +151,8 @@ public class Avatar2SysML { returnDataType = dt; } - MethodInfo(String _name, String _msgtype) { // for signals + /** for signals */ + MethodInfo(String _name, String _msgtype) { name = _name; msgtype = _msgtype; fieldNames = new ArrayList<String>(); @@ -108,8 +162,7 @@ public class Avatar2SysML { returnDataType = null; } - /** @param _fieldName - * @param _type + /** add parameter at the end. * @param _dt datatype, only relevant if _type is UNDEFINED */ public void addField(String _fieldName, AvatarType _type, AvatarDataType _dt){ @@ -123,48 +176,66 @@ public class Avatar2SysML { fieldTypes.add(_type); } - /** number of fields */ + /** number of parameters */ public int getArity() { return fieldNames.size(); } /** SysML name */ public String getName(){ return name; } - /** SysML name for message describing profile */ + /** SysML name for message type describing profile */ public String getMessageType(){ return msgtype; } + /** method Avatar return type (null if none)*/ public AvatarType getReturnType(){ return returnType; } + /** method Avatar return datatype (null if no return type or return primitive type)*/ public AvatarDataType getReturnDataType(){ return returnDataType; } - /** SysML field name */ + /** ith parameter SysML name */ public String getFieldName(int i){ return fieldNames.get(i); } + /** ith parameter Avatar type */ public AvatarType getFieldType(int i){ return fieldTypes.get(i); } + /** ith parameter Avatar datatype (null if primitive type)*/ public AvatarDataType getDataType(int i){ return dataTypes.get(i); } } /** * Memorized while naming states, to be reused for generating states */ - class StateInfo { - private String name; // SysML name - private String prename = ""; // name of the state that is technically added before this (if exists) + static private class StateInfo { + /** SysML name */ + private String name; + + /** Sysml name of the state that is technically added before this (if exists) */ + private String prename = ""; + /** for states that havn't technically added state before them + * @param _name SysML name + */ StateInfo(String _name) { name = _name; } + /** for states that have a technically added state before them + * @param _name SysML name of the state + * @param _prename SysML name of the technically added state before + */ StateInfo(String _name, String _prename) { name = _name; prename = _prename; } + /** SysML name of the state */ public String getName(){ return name; } + /** SysML name of the technically added state before */ public String getPreName(){ return prename; } } - - void searchCountSignals() { - fifoSet.clear(); + /** Collect (in fifoSet) all signals that are used in an AvatarQueryOnSignal element of the specification. + * + * (they require some specific handling while generating...) + */ + private void searchCountSignals() { for(AvatarBlock block: avspec.getListOfBlocks()) { for(AvatarStateMachineElement sme : block.getStateMachine().getListOfElements()) { if(sme instanceof AvatarQueryOnSignal) @@ -172,10 +243,21 @@ public class Avatar2SysML { } } } - ArrayList<String> blockChain = new ArrayList<String>(); - void chainBlock(String _block) { blockChain.add(_block); } - void unchainBlock() { if(blockChain.size() > 0) blockChain.remove(blockChain.size() - 1); } - void blocklink() { + + /** update path blockChain when entering the block-handling procedure for a a block / sub-block + * @param _block: the block /sub-block to handle + */ + private void chainBlock(String _block) { blockChain.add(_block); } + + /** update path blockChain when exiting the block-handling procedure for a a block / sub-block */ + private void unchainBlock() { if(blockChain.size() > 0) blockChain.remove(blockChain.size() - 1); } + + /** generate SysML code to make a block visible at top level through its name (and not its path). + * + * Links block name to block path (updates blockLinks which is added to avsysml at the end of + * the generation process). Consistent because all blocks have different names. + */ + private void blocklink() { int size = blockChain.size(); if (size < 2) return; StringBuffer chain = new StringBuffer(); @@ -186,53 +268,25 @@ public class Avatar2SysML { blockLinks.append( indentStep + "part " + blockChain.get(size - 1) + " : '#AvatarBlock' :> " + chain.toString() + " = " + chain.toString() + ";\n" ); } - StringBuffer blockLinks = new StringBuffer(); - - String indentStep = " "; - int indentStepSize = 4; - String indent = ""; - String header = "package AvatarInstance {\n" + - indentStep + "import ScalarValues::String;\n" + - indentStep + "import ScalarValues::Positive;\n" + - indentStep + "import ScalarValues::Integer;\n" + - indentStep + "import ScalarValues::Boolean;\n" + - indentStep + "import ScalarValues::Real;\n" + - indentStep + "import AvatarBlockTypes::*;\n" + - indentStep + "import AvatarCommunication::*;\n"; - - - StringBuffer avatar2SysML() { - methodMap.clear(); - stateMap.clear(); - stateList.clear(); - blockChain.clear(); - blockLinks = new StringBuffer(indentStep + "// Block Shortcut Links $$$$$$$$$$$$\n"); - avsysml = new StringBuffer(header); - indent += indentStep; - searchCountSignals();; - dataTypes2SysML(); - communications2SysML(); - blocks2SysML(); - avsysml.append(blockLinks); - avsysml.append("}\n"); - //AvatarFromSysML parser = new AvatarFromSysML(); - //parser.sysMLtoSpec(avsysml.toString()); /// !!!!!!!!!!!!!! TESTEUR - return avsysml; - } - void dataTypes2SysML(){ + + /** generates SysML datatype declarations and put them at the current position (end) of avsysml */ + private void dataTypes2SysML(){ if (avspec.getDataTypes() == null || avspec.getDataTypes().size() == 0) return; - avsysml.append("\n" + indent + "// DATATYPES $$$$$$$$$$$$$$$$$$$$$$$$\n"); + avsysml.append("\n" + indentation + "// DATATYPES $$$$$$$$$$$$$$$$$$$$$$$$\n"); for(AvatarDataType dt : avspec.getDataTypes()){ - avsysml.append("\n" + indent + "attribute def " + dataTypeSysMLname(dt.getName()) + " :> '#AvatarDataType'"); + // put Header + avsysml.append("\n" + indentation + "attribute def " + dataTypeSysMLname(dt.getName()) + " :> '#AvatarDataType'"); + // handle fields int nbFields = dt.attributeNb(); if (nbFields == 0) avsysml.append(";\n"); - else { + else { // put fields. + // Note: SysML has no default values thus default values are explicitely set avsysml.append(" { \n"); - indent += indentStep; + indent(1); for (int i = 0; i < nbFields; i++) { AvatarAttribute aa = dt.getAttribute(i); - avsysml.append( indent + "attribute " + fieldSysMLname(aa.getName()) + " : " ); + avsysml.append( indentation + "attribute " + fieldSysMLname(aa.getName()) + " : " ); if (aa.getType() == AvatarType.BOOLEAN) { avsysml.append("Boolean"); if (aa.hasInitialValue()) @@ -248,13 +302,23 @@ public class Avatar2SysML { avsysml.append(" default := " + AvatarType.INTEGER.getDefaultInitialValue().trim() + ";\n"); } else - avsysml.append(aa.getDataType().getName() + ";\n"); + avsysml.append(aa.getDataType().getName() + ";\n"); // datatypes don't have default values } - indent = indent.substring(indentStepSize); - avsysml.append(indent + "}\n"); + unindent(1); + avsysml.append(indentation + "}\n"); } } } + /** generates SysML declarations of communication structures and put them at the current position (end) of avsysml. + * + * Communication structures are + * <ul> + * <li> Relations, corresponding to Avatar relations </li> + * <li> Channels declarations (a channel is an inSignal/outSignal connection inside a relation) </li> + * <li> Binding of block signals to channels, to complete channel's characterization </li> + * <li> in/out Messages (structures) declarations, linking them to channels. This providing signals with profiles </li> + * </ul> + */ void communications2SysML(){ int nbfiforelNumber = 0; int bfiforelNumber = 0; @@ -262,18 +326,18 @@ public class Avatar2SysML { if (avspec.getRelations() == null || avspec.getRelations().size() == 0) return; - avsysml.append("\n" + indent + "// COMMUNICATIONS $$$$$$$$$$$$$$$$$$$$$$$$\n"); + avsysml.append("\n" + indentation + "// COMMUNICATIONS $$$$$$$$$$$$$$$$$$$$$$$$\n"); for(AvatarRelation ar: avspec.getRelations()) { - // parameters depending on relation type ============== - int relationType; - int relationNumber; - String relationConstructor; - String relationParameters = null; - String channelConstructor; + // declare some parameters depending on relation type ============== + int relationType; // SYNC, FIFO or BFIFO + int relationNumber; // to distinguish relations with same characteristics + String relationConstructor; // #Sync_Rel, #Bfifo_Rel, #NBfifo_Rel (c.f. Avatar SysML library) + String relationParameters; // for the call of SysML constructors of relation parts + String channelConstructor; // #Sync, #Bfifo, #NBfifo (c.f. Avatar SysML library) - // computine parameters depending on relation type ============== - // if (ar.isAMS()) throw exception + // compute parameters depending on relation type ============== + // if (ar.isAMS()) ... TODO String blk1 = ar.getBlock1().getName(); String blk2 = ar.getBlock2().getName(); String blk1SysMLname = blockSysMLname(blk1); @@ -284,28 +348,28 @@ public class Avatar2SysML { relationNumber = syncrelNumber++; relationConstructor = "'#Sync_Rel'"; channelConstructor = "'#Sync'"; - if(ar.isPrivate()) relationParameters += ", '@private'=true)"; + if(ar.isPrivate()) relationParameters += ", '@private'=true)"; // default is false in Avatar SysML library } else { // fifo relation - if(ar.isPrivate()) // default: false - if(ar.isLossy()) // default: false - if(ar.getSizeOfFIFO() > 1) // default size: 1 + if(ar.isPrivate()) // default: false in Avatar SysML library + if(ar.isLossy()) // default: false in Avatar SysML library + if(ar.getSizeOfFIFO() > 1) // default size: 1 in Avatar SysML library relationParameters += ", '@private'=true, '@lossy'=true, '@max_size'=" + ar.getSizeOfFIFO() + ")"; else relationParameters += ", '@private'=true, '@lossy'=true)"; else - if(ar.getSizeOfFIFO() > 1) // default size: 1 + if(ar.getSizeOfFIFO() > 1) // default size: 1 in Avatar SysML library relationParameters += ", '@private'=true, '@max_size'=" + ar.getSizeOfFIFO() + ")"; else relationParameters += ", '@private'=true)"; else - if(ar.isLossy()) // default: false - if(ar.getSizeOfFIFO() > 1) // default size: 1 + if(ar.isLossy()) // default: false in Avatar SysML library + if(ar.getSizeOfFIFO() > 1) // default size: 1 in Avatar SysML library relationParameters += ", '@lossy'=true, '@max_size'=" + ar.getSizeOfFIFO() + ")"; else relationParameters += ", '@lossy'=true)"; else - if(ar.getSizeOfFIFO() > 1) // default size: 1 + if(ar.getSizeOfFIFO() > 1) // default size: 1 in Avatar SysML library relationParameters += ", '@max_size'=" + ar.getSizeOfFIFO() + ")"; if (ar.isBlocking()) { // blocking fifo relation @@ -322,14 +386,14 @@ public class Avatar2SysML { } } - // general type-independent generation ============== + // general generation (using parameters above) : put declaration to avsysml ============== String relationSYSMLname = relationSysMLname(blk1, blk2, relationType, relationNumber); // relation declaration -------------------- - avsysml.append("\n" + indent + "// Relation " + relationSYSMLname + "=============\n"); - avsysml.append(indent + "part " + relationSYSMLname + ": " + relationConstructor); + avsysml.append("\n" + indentation + "// Relation " + relationSYSMLname + "=============\n"); + avsysml.append(indentation + "part " + relationSYSMLname + ": " + relationConstructor); if(relationParameters != null) avsysml.append(" = " + relationConstructor + relationParameters); avsysml.append(";\n"); @@ -337,59 +401,68 @@ public class Avatar2SysML { // Channels and associated Messages declarations ---------------- int relationSize = ar.getSignals1().size(); - for(int i=0; i<relationSize; i++) { + for(int i=0; i<relationSize; i++) { // iterate on signal connections AvatarSignal sig1 = ar.getSignals1().get(i); AvatarSignal sig2 = ar.getSignals2().get(i); - boolean in2out = (sig1.getInOut() == AvatarSignal.IN); - - // to remove - String channelName = channelName(blk1, blk2, sig1.getName(), sig2.getName(), in2out); + boolean out2in = (sig1.getInOut() == AvatarSignal.OUT); - String channelSYSMLname = channelSysMLname(channelName(blk1, blk2, sig1.getName(), sig2.getName(), in2out), relationType); + String channelSYSMLname = channelSysMLname(channelName(blk1, blk2, sig1.getName(), sig2.getName(), out2in), relationType); String sig1SYSMLname = signalSysMLname(sig1.getName()); String sig2SYSMLname = signalSysMLname(sig2.getName()); String message1SYSMLname = messageSysMLname(blk1,sig1.getName()); String message2SYSMLname = messageSysMLname(blk2,sig2.getName()); - MethodInfo sig1Info = new MethodInfo(sig1SYSMLname, message1SYSMLname); - MethodInfo sig2Info = new MethodInfo(sig2SYSMLname, message2SYSMLname); + MethodInfo sig1Info = new MethodInfo(sig1SYSMLname, message1SYSMLname); // to collect info + MethodInfo sig2Info = new MethodInfo(sig2SYSMLname, message2SYSMLname); // to collect info // Channel declaration ......................... - avsysml.append("\n" + indent + "// Channel " + channelSYSMLname + "-------------\n"); - avsysml.append(indent + "part " + channelSYSMLname + " : " + channelConstructor + " = " + avsysml.append("\n" + indentation + "// Channel " + channelSYSMLname + "-------------\n"); + avsysml.append(indentation + "part " + channelSYSMLname + " : " + channelConstructor + " = " + channelConstructor + "('@relation' = " + relationSYSMLname + ");\n"); - if (in2out) { - avsysml.append(indent + "binding : '#InSignalBinding' bind " + blk1SysMLname + "." + sig1SYSMLname + " = " + channelSYSMLname + + + // Binding block signals to the channel ................ + + if (out2in) { // depends on direction. symetric. + avsysml.append(indentation + "binding : '#InSignalBinding' bind " + blk1SysMLname + "." + sig1SYSMLname + " = " + channelSYSMLname + ";\n"); - avsysml.append(indent + "binding : '#OutSignalBinding' bind " + blk2SysMLname + "." + sig2SYSMLname + " = " + channelSYSMLname + + avsysml.append(indentation + "binding : '#OutSignalBinding' bind " + blk2SysMLname + "." + sig2SYSMLname + " = " + channelSYSMLname + ";\n"); } else { - avsysml.append(indent + "binding : '#OutSignalBinding' bind " + blk1SysMLname + "." + sig1SYSMLname + " = " + channelSYSMLname + ";\n"); - avsysml.append(indent + "binding : '#InSignalBinding' bind " + blk2SysMLname + "." + sig2SYSMLname + " = " + channelSYSMLname + ";\n"); + avsysml.append(indentation + "binding : '#OutSignalBinding' bind " + blk1SysMLname + "." + sig1SYSMLname + " = " + channelSYSMLname + ";\n"); + avsysml.append(indentation + "binding : '#InSignalBinding' bind " + blk2SysMLname + "." + sig2SYSMLname + " = " + channelSYSMLname + ";\n"); } - // Message declaration ......................... - - StringBuffer msg1Buf = new StringBuffer(indent + "\n// Message of signal " + blk1SysMLname + "." + sig1SYSMLname + "............\n"); - StringBuffer msg2Buf = new StringBuffer(indent + "\n// Message of signal " + blk2SysMLname + "." + sig2SYSMLname + "............\n"); - if (in2out) { - msg1Buf.append(indent + "part def " + message1SYSMLname + " :> '#InMessage' {\n" + - indent + indentStep + "private part '@channel' : '#Channel' = " + channelSYSMLname + ";\n"); - msg2Buf.append(indent + "part def " + message2SYSMLname + " :> '#OutMessage', " + message1SYSMLname + " {\n"); + + // Message declarations ......................... + // one Message per direction, parallel build in two buffers msg1Buf and msg2Buf + + // put declaration headers + StringBuffer msg1Buf = new StringBuffer(indentation + "\n// Message of signal " + blk1SysMLname + "." + sig1SYSMLname + "............\n"); + StringBuffer msg2Buf = new StringBuffer(indentation + "\n// Message of signal " + blk2SysMLname + "." + sig2SYSMLname + "............\n"); + if (out2in) { + msg1Buf.append(indentation + "part def " + message1SYSMLname + " :> '#InMessage' {\n" + + indentation + indentStep + "private part '@channel' : '#Channel' = " + channelSYSMLname + ";\n"); + msg2Buf.append(indentation + "part def " + message2SYSMLname + " :> '#OutMessage', " + message1SYSMLname + " {\n"); } else { - msg1Buf.append(indent + "part def " + message1SYSMLname + " :> '#OutMessage', " + message2SYSMLname + " {\n"); - msg2Buf.append(indent + "part def " + message2SYSMLname + " :> '#InMessage' {\n" + - indent + indentStep + "private part '@channel' : '#Channel' = " + channelSYSMLname + ";\n"); + msg1Buf.append(indentation + "part def " + message1SYSMLname + " :> '#OutMessage', " + message2SYSMLname + " {\n"); + msg2Buf.append(indentation + "part def " + message2SYSMLname + " :> '#InMessage' {\n" + + indentation + indentStep + "private part '@channel' : '#Channel' = " + channelSYSMLname + ";\n"); } - indent += indentStep; - // message fields. SysML names preserve Avatar sender and receiver names - int channelSize = sig1.getListOfOriginalAttributes().size(); - int j=0; + indent(1); + + // handle message fields. in-message fields redefine out-message fields + int nbFields = sig1.getListOfOriginalAttributes().size(); + // parameters for handling a field AvatarType type; - String attributeType; + String attributeType; // SysML name associated to type String fieldName1; String fieldName2; - while (j < channelSize ) { // browse channels' parameters + int j=0; + while (j < nbFields ) { // browse channels' fielsd AvatarAttribute aa1 = sig1.getListOfOriginalAttributes().get(j); + + // compute parameters for handling this field + + // compute field type parameters AvatarDataType dataType = null; if (aa1.isDataType()) { dataType = aa1.getDataType(); @@ -403,25 +476,33 @@ public class Avatar2SysML { else if (aa1.isInt()) { attributeType = "Integer;\n"; type = AvatarType.INTEGER; - } else { attributeType = "Integer;\n"; type = AvatarType.INTEGER; } // ERROR: SHOULD NOT BE TIMER + } else { attributeType = "Integer;\n"; type = AvatarType.INTEGER; } // TODO : error: SHOULD NOT BE TIMER + + // compute field names fieldName1 = fieldSysMLname(aa1.getName()); fieldName2 = fieldSysMLname(sig2.getListOfOriginalAttributes().get(j).getName()); - j++; - if (in2out) { - msg1Buf.append(indent + "attribute " + fieldName1 + " : " + attributeType); - msg2Buf.append(indent + "attribute " + fieldName2 + " redefines " + fieldName1 + ";\n"); + + // put field declaration + if (out2in) { // depends on direction. symetric. + msg1Buf.append(indentation + "attribute " + fieldName1 + " : " + attributeType); + msg2Buf.append(indentation + "attribute " + fieldName2 + " redefines " + fieldName1 + ";\n"); } else { - msg1Buf.append(indent + "attribute " + fieldName1 + " redefines " + fieldName2 + ";\n"); - msg2Buf.append(indent + "attribute " + fieldName2 + " : " + attributeType); + msg1Buf.append(indentation + "attribute " + fieldName1 + " redefines " + fieldName2 + ";\n"); + msg2Buf.append(indentation + "attribute " + fieldName2 + " : " + attributeType); } + + // collect info to be used later sig1Info.addField(fieldName1, type, dataType); sig2Info.addField(fieldName2, type, dataType); + + j++; } - indent = indent.substring(indentStepSize); - msg1Buf.append(indent + "}\n"); - msg2Buf.append(indent + "}\n"); + unindent(1); + msg1Buf.append(indentation + "}\n"); + msg2Buf.append(indentation + "}\n"); - if (in2out) { + // put declarations to avsysml + if (out2in) { // order only relevant for the aesthetics avsysml.append(msg1Buf); avsysml.append(msg2Buf); } else { @@ -429,25 +510,30 @@ public class Avatar2SysML { avsysml.append(msg1Buf); } - + // memorize collected info methodMap.put(sig1,sig1Info); methodMap.put(sig2,sig2Info); } } } + /** generates SysML declarations for block methods. + * To be called while generating block declarations. Directly put generated text in avsysml. + */ void method2SysML(AvatarMethod am){ - // "return tuple" not handled - String returnType; - List<AvatarAttribute> returns = am.getListOfOriginalReturnAttributes(); - AvatarDataType returnDataType; - MethodInfo methodInfo; - if(returns.size() == 0) { + + MethodInfo methodInfo; // to collect info + + // compute return type (null for void methods).................... + + String returnType; // SysML name of return type, or null + List<AvatarAttribute> returns = am.getListOfOriginalReturnAttributes(); // size must be <= 1 + if(returns.size() == 0) { // void method returnType = null; methodInfo = new MethodInfo(methodSysMLname(am.getName())); } else { - returnDataType = returns.get(0).getDataType(); if (returns.get(0).isDataType()) { + AvatarDataType returnDataType = returns.get(0).getDataType(); returnType = dataTypeSysMLname(returns.get(0).getDataType().getName()); methodInfo = new MethodInfo(methodSysMLname(am.getName()), AvatarType.UNDEFINED, returnDataType); @@ -463,68 +549,91 @@ public class Avatar2SysML { methodInfo = new MethodInfo(methodSysMLname(am.getName()), AvatarType.INTEGER, null); } } + + // put header (different for void and non-void methods)..................... + if (returnType == null) - avsysml.append(indent + "action " + methodSysMLname(am.getName()) + ": '#AvatarVoidMethod' {\n"); + avsysml.append(indentation + "action " + methodSysMLname(am.getName()) + ": '#AvatarVoidMethod'"); else - avsysml.append(indent + "calc " + methodSysMLname(am.getName()) + ": '#AvatarCalcMethod' {\n"); - indent += indentStep; + avsysml.append(indentation + "calc " + methodSysMLname(am.getName()) + ": '#AvatarCalcMethod'"); + + // put parameters and return type as fields ....................... + // collect corresponding info - int j = 0; int nbFields = am.getListOfOriginalAttributes().size(); - while (j < nbFields) { - AvatarAttribute aa = am.getListOfOriginalAttributes().get(j); - if (aa.isDataType()) { - avsysml.append(indent + "attribute " + fieldSysMLname(aa.getName()) - + " : " + dataTypeSysMLname(aa.getDataType().getName())+ ";\n"); - methodInfo.addField(fieldSysMLname(aa.getName()), AvatarType.UNDEFINED, aa.getDataType()); - } else if (aa.isInt()) { - avsysml.append(indent + "attribute " + fieldSysMLname(aa.getName()) + " : Integer;\n"); - methodInfo.addField(fieldSysMLname(aa.getName()), AvatarType.INTEGER, null); - } else if (aa.isBool()){ - avsysml.append(indent + "attribute " + fieldSysMLname(aa.getName()) + " : Boolean;\n"); - methodInfo.addField(fieldSysMLname(aa.getName()), AvatarType.BOOLEAN, null); - } else { // ERROR should not happen - avsysml.append(indent + "attribute " + fieldSysMLname(aa.getName()) + " : Integer;\n"); - methodInfo.addField(fieldSysMLname(aa.getName()), AvatarType.INTEGER, null); + if (nbFields == 0 && returnType == null) + avsysml.append(";\n"); + else { + avsysml.append(" {\n"); + indent(1); + + int j = 0; + // iterate on method parameters, put corresponding fields + while (j < nbFields) { + AvatarAttribute aa = am.getListOfOriginalAttributes().get(j); + if (aa.isDataType()) { + avsysml.append(indentation + "attribute " + fieldSysMLname(aa.getName()) + + " : " + dataTypeSysMLname(aa.getDataType().getName()) + ";\n"); + methodInfo.addField(fieldSysMLname(aa.getName()), AvatarType.UNDEFINED, aa.getDataType()); + } else if (aa.isInt()) { + avsysml.append(indentation + "attribute " + fieldSysMLname(aa.getName()) + " : Integer;\n"); + methodInfo.addField(fieldSysMLname(aa.getName()), AvatarType.INTEGER, null); + } else if (aa.isBool()) { + avsysml.append(indentation + "attribute " + fieldSysMLname(aa.getName()) + " : Boolean;\n"); + methodInfo.addField(fieldSysMLname(aa.getName()), AvatarType.BOOLEAN, null); + } else { // ERROR should not happen + avsysml.append(indentation + "attribute " + fieldSysMLname(aa.getName()) + " : Integer;\n"); + methodInfo.addField(fieldSysMLname(aa.getName()), AvatarType.INTEGER, null); + } + j++; } - j++; + // put return field for non-void methods + if (returnType != null) + avsysml.append(indentation + "return : " + returnType + ";\n"); + + unindent(1); + avsysml.append(indentation + "}\n"); } - if (returnType != null) - avsysml.append(indent + "return : " + returnType + ";\n"); - indent = indent.substring(indentStepSize); - avsysml.append(indent + "}\n"); - methodMap.put(am, methodInfo); + methodMap.put(am, methodInfo); // memorize collected info } + /** generates SysML declarations for block signals. + * To be called while generating block declarations. Directly put generated text in avsysml. Signals used in AvatarQueryOnSignal elements must + * be typed as fifos (other ones are not constrained). Thus, fifoSet must have been computed before calling this method. + */ void signal2SysML(AvatarSignal as){ - avsysml.append(indent + "part " + methodMap.get(as).getName() + " : " + + avsysml.append(indentation + "part " + methodMap.get(as).getName() + " : " + (fifoSet.contains(as) ? "'#Fifo'" : "'#Channel'") + ";\n"); } - // handling one block + + /** generates SysML declarations for blocks and declaration to directly access inner blocks through their name (not their full path) */ void block2SysML(AvatarBlock block){ String blockSYSMLname = blockSysMLname(block.getName()); - timerList.clear(); + timerList.clear(); // to memorize timers while iterating on attributes (delayed declarations) chainBlock(blockSYSMLname); - blocklink(); + blocklink(); // to directly access inner blocks through their (short) name - // block header -------------------- - avsysml.append("\n" + indent + "// Block " + blockSYSMLname + "=============\n"); - avsysml.append(indent + "part " + blockSYSMLname + " : '#AvatarBlock' {\n"); - indent += indentStep; + // put block header -------------------- + avsysml.append("\n" + indentation + "// Block " + blockSYSMLname + "=============\n"); + avsysml.append(indentation + "part " + blockSYSMLname + " : '#AvatarBlock' {\n"); + indent(1); + + // put attribute declarations ---------------------------- + // no default value in SysML, thus default values are set explicitly + // timer attributes are memorized to be declared later - // attributes -------------------- if (block.getAttributes() != null && block.getAttributes().size() != 0) { - avsysml.append("\n" + indent + "// Attributes ---------------------\n"); + avsysml.append("\n" + indentation + "// Attributes ---------------------\n"); int j = 0; int nbAttributes = block.getOriginalAttributes().size(); - while(j < nbAttributes) { + while(j < nbAttributes) { // iterate on block's attributes AvatarAttribute aa = block.getOriginalAttributes().get(j); if (aa.isDataType()) { - avsysml.append(indent + "attribute " + attributeSysMLname(aa.getName()) + + avsysml.append(indentation + "attribute " + attributeSysMLname(aa.getName()) + " : " + dataTypeSysMLname(aa.getDataType().getName()) + ";\n"); } else if (aa.isInt()) { - avsysml.append(indent + "attribute " + attributeSysMLname(aa.getName()) + " : Integer"); + avsysml.append(indentation + "attribute " + attributeSysMLname(aa.getName()) + " : Integer"); if (aa.hasInitialValue()) avsysml.append(" := " + aa.getInitialValue().trim()); else @@ -532,7 +641,7 @@ public class Avatar2SysML { avsysml.append(";\n"); } else if (aa.isBool()) { - avsysml.append(indent + "attribute " + attributeSysMLname(aa.getName()) + " : Boolean"); + avsysml.append(indentation + "attribute " + attributeSysMLname(aa.getName()) + " : Boolean"); if (aa.hasInitialValue()) avsysml.append(" := " + aa.getInitialValue().trim()); else @@ -541,23 +650,24 @@ public class Avatar2SysML { } else if (aa.isTimer()) { timerList.add(aa); - } else {} // ERROR, should not happen + } else {} // TODO : should not happen. to remove if not possible j++; } } - // constants -------------------- + + // put constant declarations -------------------- if (block.getConstants() != null && block.getConstants().size() != 0) { - avsysml.append("\n" + indent + "// Constants ---------------------\n"); + avsysml.append("\n" + indentation + "// Constants ---------------------\n"); int j = 0; int nbConstants = block.getConstants().size(); - while(j < nbConstants) { + while(j < nbConstants) { // iterate on block's constants AvatarAttribute aa = block.getOriginalAttributes().get(j); if (aa.isDataType()) { - avsysml.append(indent + "readolny attribute " + attributeSysMLname(aa.getName()) + + avsysml.append(indentation + "readolny attribute " + attributeSysMLname(aa.getName()) + " : " + dataTypeSysMLname(aa.getDataType().getName()) + ";\n"); } else if (aa.isInt()) { - avsysml.append(indent + "readolny attribute " + attributeSysMLname(aa.getName()) + " : Integer"); + avsysml.append(indentation + "readolny attribute " + attributeSysMLname(aa.getName()) + " : Integer"); if (aa.hasInitialValue()) avsysml.append(" := " + aa.getInitialValue().trim()); else @@ -565,50 +675,57 @@ public class Avatar2SysML { avsysml.append(";\n"); } else if (aa.isBool()) { - avsysml.append(indent + "readolny attribute " + attributeSysMLname(aa.getName()) + " : Boolean"); + avsysml.append(indentation + "readolny attribute " + attributeSysMLname(aa.getName()) + " : Boolean"); if (aa.hasInitialValue()) avsysml.append(" := " + aa.getInitialValue().trim()); else avsysml.append(" default := " + AvatarType.BOOLEAN.getDefaultInitialValue().trim()); avsysml.append(";\n"); } - else {} // ERROR, should not happen + else {} // TODO ? error should not happen (timers arn't constants...) j++; } } - // methods -------------------- + + // put method declarations -------------------- if (block.getMethods() != null && block.getMethods().size() != 0) { - avsysml.append("\n" + indent + "// Methods ---------------------\n"); + avsysml.append("\n" + indentation + "// Methods ---------------------\n"); for (AvatarMethod am : block.getMethods()) method2SysML(am); } + + // put signal declarations -------------------- if (block.getSignals() != null && block.getSignals().size() != 0) { - avsysml.append("\n" + indent + "// Signals ---------------------\n"); + avsysml.append("\n" + indentation + "// Signals ---------------------\n"); for (AvatarSignal as : block.getSignals()) signal2SysML(as); } - // timers ------------------- + + // put timer declarations ------------------- if (timerList != null && timerList.size() != 0) { - avsysml.append("\n" + indent + "// Timers ---------------------\n"); + avsysml.append("\n" + indentation + "// Timers ---------------------\n"); for (AvatarAttribute timer : timerList) - avsysml.append(indent + "part " + timerBlockSysMLname(timer.getName()) + ": '#AvatarTimer' = '#AvatarTimer'();\n"); + avsysml.append(indentation + "part " + timerBlockSysMLname(timer.getName()) + ": '#AvatarTimer' = '#AvatarTimer'();\n"); } - // state-machine -------------------- - avsysml.append("\n" + indent + "// state-machine -------------------\n"); + + // put state-machine description -------------------- + avsysml.append("\n" + indentation + "// state-machine -------------------\n"); statemachine2SysML(block.getStateMachine()); + // sub-blocks ------------------- List<AvatarBlock> subBlockList = new ArrayList<AvatarBlock>(); for(AvatarBlock blk: avspec.getListOfBlocks()) { if (blk.getFather() == block) subBlockList.add(blk); } - if (subBlockList != null && subBlockList.size() != 0) { - avsysml.append("\n" + indent + "// Sub-Blocks øøøøøøøøøøøøøøøøøøøøøøø\n"); - for (AvatarBlock blk : subBlockList) if (blk.getFather() == block) block2SysML(blk); + if (subBlockList.size() != 0) { + avsysml.append("\n" + indentation + "// Sub-Blocks øøøøøøøøøøøøøøøøøøøøøøø\n"); + for (AvatarBlock blk : subBlockList) block2SysML(blk); } - indent = indent.substring(indentStepSize); - avsysml.append(indent + "}\n"); + + unindent(1); + avsysml.append(indentation + "}\n"); unchainBlock(); } // handling all blocks void blocks2SysML(){ - avsysml.append("\n" + indent + "// BLOCKS $$$$$$$$$$$$$$$$$$$$$$$$\n"); + avsysml.append("\n" + indentation + "// BLOCKS $$$$$$$$$$$$$$$$$$$$$$$$\n"); for(AvatarBlock block: avspec.getListOfBlocks()) if (block.getFather() == null) block2SysML(block); } @@ -661,117 +778,117 @@ public class Avatar2SysML { stateList.add(asme); stateMap.put(asme, stateinfo); } - avsysml.append(indent + "exhibit state '@statemachine' : '#AvatarStateMachine' {\n"); - indent += indentStep; + avsysml.append(indentation + "exhibit state '@statemachine' : '#AvatarStateMachine' {\n"); + indent(1); // generate SysML states with associated transitions stopState = false; for (AvatarStateMachineElement asme : stateList) state2SysML(asme); - indent = indent.substring(indentStepSize); - avsysml.append(indent + "}\n"); + unindent(1); + avsysml.append(indentation + "}\n"); } StringBuffer sysMLtransitions = new StringBuffer(); StringBuffer sysMLrequests = new StringBuffer(); List<AvatarStateMachineElement> requirePreCom = new ArrayList<AvatarStateMachineElement>(); void state2SysML(AvatarStateMachineElement asme){ - indent += indentStep; + indent(1); transitionsAndRequests(stateMap.get(asme).getName(), asme.getNexts(), ((asme instanceof AvatarState) ? "'@pool'" : "'@request'")); - indent = indent.substring(indentStepSize); + unindent(1); String requests = sysMLrequests.toString(); // State Description, depending on state type if(asme instanceof AvatarState){ - avsysml.append("\n" + indent + "state " + stateMap.get(asme).getName() + " : '#AvatarStandardState'"); + avsysml.append("\n" + indentation + "state " + stateMap.get(asme).getName() + " : '#AvatarStandardState'"); if (requests.equals("")) avsysml.append(";\n"); else - avsysml.append(" = '#AvatarStandardState'(\n" + requests + "\n" + indent + ");\n"); + avsysml.append(" = '#AvatarStandardState'(\n" + requests + "\n" + indentation + ");\n"); } else if(asme instanceof AvatarRandom){ - avsysml.append("\n" + indent + "state " + stateMap.get(asme).getName() + " : '#AvatarRandomState' = '#AvatarRandomState'(\n"); + avsysml.append("\n" + indentation + "state " + stateMap.get(asme).getName() + " : '#AvatarRandomState' = '#AvatarRandomState'(\n"); if (!requests.equals("")) avsysml.append(requests + ",\n"); - indent += indentStep; - avsysml.append(indent + "'@state_action' = '#Assignment'(\n"); - indent += indentStep; - avsysml.append(indent + "'@target' = " + attributeSysMLname(((AvatarRandom)asme).getVariable()) + ",\n"); - avsysml.append(indent + "'@value' = '#bound_random'(" + + indent(1); + avsysml.append(indentation + "'@state_action' = '#Assignment'(\n"); + indent(1); + avsysml.append(indentation + "'@target' = " + attributeSysMLname(((AvatarRandom)asme).getVariable()) + ",\n"); + avsysml.append(indentation + "'@value' = '#bound_random'(" + expr2SysML(((AvatarRandom)asme).getMinValue().replaceAll("__",".")) + ", " + expr2SysML(((AvatarRandom)asme).getMaxValue().replaceAll("__",".")) +")\n"); - indent = indent.substring(indentStepSize); - avsysml.append(indent + ")\n"); - indent = indent.substring(indentStepSize); - avsysml.append(indent + ");\n"); + unindent(1); + avsysml.append(indentation + ")\n"); + unindent(1); + avsysml.append(indentation + ");\n"); } else if(asme instanceof AvatarQueryOnSignal){ - avsysml.append("\n" + indent + "state " + stateMap.get(asme).getName() + " : '#AvatarCountState' = '#AvatarCountState'(\n"); + avsysml.append("\n" + indentation + "state " + stateMap.get(asme).getName() + " : '#AvatarCountState' = '#AvatarCountState'(\n"); if (!requests.equals("")) avsysml.append(requests + ",\n"); - indent += indentStep; - avsysml.append(indent + "'@state_action' = '#Assignment'(\n"); - indent += indentStep; - avsysml.append(indent + "'@target' = " + attributeSysMLname(((AvatarQueryOnSignal)asme).getAttribute().getName()) + ",\n"); - avsysml.append(indent + "'@value' = " + methodMap.get(((AvatarQueryOnSignal)asme).getSignal()).getName() + ".'@amount'()\n"); - indent = indent.substring(indentStepSize); - avsysml.append(indent + ")\n"); - indent = indent.substring(indentStepSize); - avsysml.append(indent + ");\n"); + indent(1); + avsysml.append(indentation + "'@state_action' = '#Assignment'(\n"); + indent(1); + avsysml.append(indentation + "'@target' = " + attributeSysMLname(((AvatarQueryOnSignal)asme).getAttribute().getName()) + ",\n"); + avsysml.append(indentation + "'@value' = " + methodMap.get(((AvatarQueryOnSignal)asme).getSignal()).getName() + ".'@amount'()\n"); + unindent(1); + avsysml.append(indentation + ")\n"); + unindent(1); + avsysml.append(indentation + ");\n"); } else if(asme instanceof AvatarActionOnSignal){ if(((AvatarActionOnSignal)asme).isSending()) { - avsysml.append("\n" + indent + "state " + stateMap.get(asme).getName() + " : '#AvatarSendState'"); + avsysml.append("\n" + indentation + "state " + stateMap.get(asme).getName() + " : '#AvatarSendState'"); if (requests.equals("")) avsysml.append(";\n"); else - avsysml.append(" = '#AvatarSendState'(\n" + requests + "\n" +indent + ");\n"); + avsysml.append(" = '#AvatarSendState'(\n" + requests + "\n" + indentation + ");\n"); } else { - avsysml.append("\n" + indent + "state " + stateMap.get(asme).getName() + " : '#AvatarReceiveState'"); + avsysml.append("\n" + indentation + "state " + stateMap.get(asme).getName() + " : '#AvatarReceiveState'"); if (requests.equals("")) avsysml.append(";\n"); else - avsysml.append(" = '#AvatarReceiveState'(\n" + requests + "\n" + indent + ");\n"); + avsysml.append(" = '#AvatarReceiveState'(\n" + requests + "\n" + indentation + ");\n"); } } else if(asme instanceof AvatarStartState){ - avsysml.append("\n" + indent + "entry action " + stateMap.get(asme).getName() + " :'#AvatarStartState'"); + avsysml.append("\n" + indentation + "entry action " + stateMap.get(asme).getName() + " :'#AvatarStartState'"); if (requests.equals("")) avsysml.append(";\n"); else - avsysml.append(" = '#AvatarStartState'(\n" + requests + "\n" + indent + ");\n"); + avsysml.append(" = '#AvatarStartState'(\n" + requests + "\n" + indentation + ");\n"); } else if(asme instanceof AvatarStopState){ if(! stopState) - avsysml.append("\n" + indent + "exit action " + stateMap.get(asme).getName() + " :'#AvatarStopState';\n"); + avsysml.append("\n" + indentation + "exit action " + stateMap.get(asme).getName() + " :'#AvatarStopState';\n"); stopState = true; } else if(asme instanceof AvatarSetTimer){ - avsysml.append("\n" + indent + "state " + stateMap.get(asme).getName() + " : '#AvatarSetTimerState'"); + avsysml.append("\n" + indentation + "state " + stateMap.get(asme).getName() + " : '#AvatarSetTimerState'"); if (requests.equals("")) avsysml.append(";\n"); else - avsysml.append(" = '#AvatarSetTimerState'(\n" + requests + "\n" + indent + ");\n"); + avsysml.append(" = '#AvatarSetTimerState'(\n" + requests + "\n" + indentation + ");\n"); } else if(asme instanceof AvatarResetTimer){ - avsysml.append("\n" + indent + "state " + stateMap.get(asme).getName() + " : '#AvatarResetTimerState'"); + avsysml.append("\n" + indentation + "state " + stateMap.get(asme).getName() + " : '#AvatarResetTimerState'"); if (requests.equals("")) avsysml.append(";\n"); else - avsysml.append(" = '#AvatarResetTimerState'(\n" + requests + "\n" + indent + ");\n"); + avsysml.append(" = '#AvatarResetTimerState'(\n" + requests + "\n" + indentation + ");\n"); } else if(asme instanceof AvatarExpireTimer){ - avsysml.append("\n" + indent + "state " + stateMap.get(asme).getName() + " : '#AvatarExpireTimerState'"); + avsysml.append("\n" + indentation + "state " + stateMap.get(asme).getName() + " : '#AvatarExpireTimerState'"); if (requests.equals("")) avsysml.append(";\n"); else - avsysml.append(" = '#AvatarExpireTimerState'(\n" + requests + "\n" + indent + ");\n"); + avsysml.append(" = '#AvatarExpireTimerState'(\n" + requests + "\n" + indentation + ");\n"); } // Transition descriptions @@ -785,85 +902,85 @@ public class Avatar2SysML { if (((AvatarActionOnSignal)aos).isSending()) { // preComm State - avsysml.append("\n" + indent + "state " + stateinfo.getPreName() + " : '#AvatarPreSendState' = '#AvatarPreSendState' (\n"); - indent += indentStep; - avsysml.append(indent + "'@request' =\n"); - indent += indentStep; + avsysml.append("\n" + indentation + "state " + stateinfo.getPreName() + " : '#AvatarPreSendState' = '#AvatarPreSendState' (\n"); + indent(1); + avsysml.append(indentation + "'@request' =\n"); + indent(1); avsysml.append(sendRequest2SysML(1, "0", "0", signalinfo, ((AvatarActionOnSignal)aos).getOriginalValues()) + "\n"); - indent = indent.substring(2 * indentStepSize); - avsysml.append(indent + ");\n"); + indentation = indentation.substring(2 * indentStepSize); + avsysml.append(indentation + ");\n"); // its transition - avsysml.append("\n" + indent + "transition : '#AvatarTransition' first " + stateinfo.getPreName() + + avsysml.append("\n" + indentation + "transition : '#AvatarTransition' first " + stateinfo.getPreName() + " then " + stateinfo.getName() + endTransition(0,"","", 1)); } else { - avsysml.append("\n" + indent + "state " + stateinfo.getPreName() + " : '#AvatarPreReceiveState' = '#AvatarPreReceiveState' (\n"); - indent += indentStep; - avsysml.append(indent + "'@request' =\n"); - indent += indentStep; + avsysml.append("\n" + indentation + "state " + stateinfo.getPreName() + " : '#AvatarPreReceiveState' = '#AvatarPreReceiveState' (\n"); + indent(1); + avsysml.append(indentation + "'@request' =\n"); + indent(1); avsysml.append(receiveRequest2SysML(1, "0", "0", signalinfo) + "\n"); - indent = indent.substring(2 * indentStepSize); - avsysml.append(indent + ");\n"); + indentation = indentation.substring(2 * indentStepSize); + avsysml.append(indentation + ");\n"); // its transition - avsysml.append("\n" + indent + "transition : '#AvatarTransition' first " + stateinfo.getPreName() + "\n"); - indent += indentStep; + avsysml.append("\n" + indentation + "transition : '#AvatarTransition' first " + stateinfo.getPreName() + "\n"); + indent(1); String doAction = receiveActions2SysML(signalinfo, ((AvatarActionOnSignal)aos).getOriginalValues()); if (doAction.length() == 0) - avsysml.append(indent + "then " + stateinfo.getName() + + avsysml.append(indentation + "then " + stateinfo.getName() + endTransition(0,"","", 1)); else { avsysml.append(doAction); avsysml.append(" then " + stateinfo.getName() + endTransition(0,"","", 1)); } - indent = indent.substring(indentStepSize); + unindent(1); } } else if (aos instanceof AvatarSetTimer) { // preComm State - avsysml.append("\n" + indent + "state " + stateinfo.getPreName() + " : '#AvatarPreSendState' = '#AvatarPreSendState' (\n"); - indent += indentStep; - avsysml.append(indent + "'@request' =\n"); - indent += indentStep; + avsysml.append("\n" + indentation + "state " + stateinfo.getPreName() + " : '#AvatarPreSendState' = '#AvatarPreSendState' (\n"); + indent(1); + avsysml.append(indentation + "'@request' =\n"); + indent(1); avsysml.append(setTimerRequest2SysML(1, "0", "0", timerBlockSysMLname(((AvatarSetTimer) aos).getTimer().getName()) + ".'@set'" , ((AvatarSetTimer)aos).getTimerValue()) + "\n"); - indent = indent.substring(2 * indentStepSize); - avsysml.append(indent + ");\n"); + indentation = indentation.substring(2 * indentStepSize); + avsysml.append(indentation + ");\n"); // its transition - avsysml.append("\n" + indent + "transition : '#AvatarTransition' first " + stateinfo.getPreName() + + avsysml.append("\n" + indentation + "transition : '#AvatarTransition' first " + stateinfo.getPreName() + " then " + stateinfo.getName() + endTransition(0,"","", 1)); } else if (aos instanceof AvatarResetTimer) { // preComm State - avsysml.append("\n" + indent + "state " + stateinfo.getPreName() + " : '#AvatarPreSendState' = '#AvatarPreSendState' (\n"); - indent += indentStep; - avsysml.append(indent + "'@request' =\n"); - indent += indentStep; + avsysml.append("\n" + indentation + "state " + stateinfo.getPreName() + " : '#AvatarPreSendState' = '#AvatarPreSendState' (\n"); + indent(1); + avsysml.append(indentation + "'@request' =\n"); + indent(1); avsysml.append(resetTimerRequest2SysML(1, "0", "0", timerBlockSysMLname(((AvatarResetTimer) aos).getTimer().getName()) + ".'@reset'" ) + "\n"); - indent = indent.substring(2 * indentStepSize); - avsysml.append(indent + ");\n"); + indentation = indentation.substring(2 * indentStepSize); + avsysml.append(indentation + ");\n"); // its transition - avsysml.append("\n" + indent + "transition : '#AvatarTransition' first " + stateinfo.getPreName() + + avsysml.append("\n" + indentation + "transition : '#AvatarTransition' first " + stateinfo.getPreName() + " then " + stateinfo.getName() + endTransition(0,"","", 1)); } else if (aos instanceof AvatarExpireTimer) { - avsysml.append("\n" + indent + "state " + stateinfo.getPreName() + " : '#AvatarPreReceiveState' = '#AvatarPreReceiveState' (\n"); - indent += indentStep; - avsysml.append(indent + "'@request' =\n"); - indent += indentStep; + avsysml.append("\n" + indentation + "state " + stateinfo.getPreName() + " : '#AvatarPreReceiveState' = '#AvatarPreReceiveState' (\n"); + indent(1); + avsysml.append(indentation + "'@request' =\n"); + indent(1); avsysml.append(expireTimerRequest2SysML(1, "0", "0", timerBlockSysMLname(((AvatarExpireTimer) aos).getTimer().getName()) + ".'@expire'" ) + "\n"); - indent = indent.substring(2 * indentStepSize); - avsysml.append(indent + ");\n"); + indentation = indentation.substring(2 * indentStepSize); + avsysml.append(indentation + ");\n"); // its transition - avsysml.append("\n" + indent + "transition : '#AvatarTransition' first " + stateinfo.getPreName() + + avsysml.append("\n" + indentation + "transition : '#AvatarTransition' first " + stateinfo.getPreName() + endTransition(0,"","", 1)); - indent += indentStep; - avsysml.append(indent + "then " + stateinfo.getName() + ";\n"); - indent = indent.substring(indentStepSize); + indent(1); + avsysml.append(indentation + "then " + stateinfo.getName() + ";\n"); + unindent(1); } } } @@ -871,18 +988,18 @@ public class Avatar2SysML { String endTransition(int delayDistributionLaw, String delayExtra1, String delayExtra2, double probability){ if (delayDistributionLaw == DELAY_UNIFORM_LAW && probability == 1) return ";\n"; StringBuffer result = new StringBuffer(" {\n"); - indent += indentStep; - result.append(indent + "attribute '@delayDistributionLaw' : String = \"" + DISTRIBUTION_LAWS[delayDistributionLaw] + "\";\n"); + indent(1); + result.append(indentation + "attribute '@delayDistributionLaw' : String = \"" + DISTRIBUTION_LAWS[delayDistributionLaw] + "\";\n"); if (probability != 1) - result.append(indent + "attribute '@weight' : Real = " + probability + ";\n"); + result.append(indentation + "attribute '@weight' : Real = " + probability + ";\n"); if (NB_OF_EXTRA_ATTRIBUTES[delayDistributionLaw] > 0) - result.append(indent + "attribute '" + LABELS_OF_EXTRA_ATTRIBUTES_1[delayDistributionLaw] + "' : String = \"" + result.append(indentation + "attribute '" + LABELS_OF_EXTRA_ATTRIBUTES_1[delayDistributionLaw] + "' : String = \"" + delayExtra1 + "\";\n"); if (NB_OF_EXTRA_ATTRIBUTES[delayDistributionLaw] > 1) - result.append(indent + "attribute '" + LABELS_OF_EXTRA_ATTRIBUTES_2[delayDistributionLaw] + "' : String = \"" + result.append(indentation + "attribute '" + LABELS_OF_EXTRA_ATTRIBUTES_2[delayDistributionLaw] + "' : String = \"" + delayExtra2 + "\";\n"); - indent = indent.substring(indentStepSize); - result.append(indent + "}\n"); + unindent(1); + result.append(indentation + "}\n"); return result.toString(); } void transitionsAndRequests(String srcName, List<AvatarStateMachineElement> nexts, String poolName) { @@ -891,22 +1008,22 @@ public class Avatar2SysML { sysMLrequests.delete(0, sysMLrequests.length()); int nb = nexts.size(); if (nb == 0) { - sysMLrequests.append(indent + poolName + " = null\n"); + sysMLrequests.append(indentation + poolName + " = null\n"); return; } if (nb == 1) { - indent += indentStep; + indent(1); transitionAndRequest(srcName, (AvatarTransition)nexts.get(0), 0); - indent = indent.substring(indentStepSize); + unindent(1); if(sysMLrequests.toString().trim().equals("'#immediate_request'")) { sysMLrequests.delete(0, sysMLrequests.length()); return; } - sysMLrequests.insert(0, indent + poolName + " =\n"); + sysMLrequests.insert(0, indentation + poolName + " =\n"); return; } - indent += indentStep; + indent(1); for(int i=0; i<nb; i++){ transitionAndRequest(srcName, (AvatarTransition)nexts.get(i), i+1); if(i != nb-1) @@ -914,9 +1031,9 @@ public class Avatar2SysML { else sysMLrequests.append("\n"); } - indent = indent.substring(indentStepSize); - sysMLrequests.insert(0, indent + poolName + " = (\n"); - sysMLrequests.append(indent + ")"); + unindent(1); + sysMLrequests.insert(0, indentation + poolName + " = (\n"); + sysMLrequests.append(indentation + ")"); } private String clean_guard(String _guard) { int open = _guard.indexOf('['); @@ -958,9 +1075,9 @@ public class Avatar2SysML { // computing request if (guarded) { System.out.println("§§§§§§§§§§§§§§§§§§ " + clean_guard(((AvatarTransition)at).getOriginalGuard()) + " §§§§§§§§§§§§§§§"); - sysMLrequests.append(indent + "if " + + sysMLrequests.append(indentation + "if " + expr2SysML(clean_guard(((AvatarTransition)at).getOriginalGuard())) + " ?\n"); - indent += indentStep; + indent(1); } String minDelay = ( at.getOriginalMinDelay().length()==0 ? "0" : expr2SysML(at.getOriginalMinDelay()) ); String maxDelay = ( at.getOriginalMaxDelay().length()==0 ? "0" : expr2SysML(at.getOriginalMaxDelay()) ); @@ -996,173 +1113,173 @@ public class Avatar2SysML { maxDelay, timerBlockSysMLname(((AvatarTimerOperator) target).getTimer().getName()) + ".'@expire'" )); if(guarded) { - indent = indent.substring(indentStepSize); - sysMLrequests.append("\n" + indent + "else '#nok_request'(" + transindex + ")"); + unindent(1); + sysMLrequests.append("\n" + indentation + "else '#nok_request'(" + transindex + ")"); } // computing transition - indent = indent.substring(2 * indentStepSize); + indentation = indentation.substring(2 * indentStepSize); String doAction; - indent += indentStep; + indent(1); if(requestType == 2) doAction = receiveActions2SysML(methodMap.get(((AvatarActionOnSignal)target).getSignal()), ((AvatarActionOnSignal)target).getOriginalValues()); else doAction = transitionActions2SysML(at); - indent = indent.substring(indentStepSize); + unindent(1); - sysMLtransitions.append("\n" + indent + "transition : '#AvatarTransition' first " + srcName); + sysMLtransitions.append("\n" + indentation + "transition : '#AvatarTransition' first " + srcName); if(index > 0) sysMLtransitions.append(" if '@index' == " + index + "\n"); else sysMLtransitions.append("\n"); - indent += indentStep; + indent(1); if (doAction == null || doAction.length() == 0) - sysMLtransitions.append(indent + "then " + tgtName + + sysMLtransitions.append(indentation + "then " + tgtName + endTransition(at.getDelayDistributionLaw(), at.getDelayExtra1(), at.getDelayExtra2(), at.getProbability())); else { sysMLtransitions.append(doAction); sysMLtransitions.append(" then " + tgtName + endTransition(at.getDelayDistributionLaw(),at.getDelayExtra1(),at.getDelayExtra2(), at.getProbability())); } - indent += indentStep; + indent(1); } String trivialRequest2SysML(int index, String min, String max) { if (max.equals("0")) if (min.equals("0")) if (index == 1) - return indent + "'#immediate_request'"; + return indentation + "'#immediate_request'"; else - return indent + "'#TrivialRequest'('@index' = " + index + ")"; + return indentation + "'#TrivialRequest'('@index' = " + index + ")"; else if (index == 1) - return indent + "'#TrivialRequest'('@delay' = " + min + ")"; + return indentation + "'#TrivialRequest'('@delay' = " + min + ")"; else - return indent + "'#TrivialRequest'('@index' = " + index + ", '@delay' = " + min + ")"; + return indentation + "'#TrivialRequest'('@index' = " + index + ", '@delay' = " + min + ")"; else if (max.trim().equals(min.trim())) if(index == 1) - return indent + "'#TrivialRequest'('@delay' = " + min + ")"; + return indentation + "'#TrivialRequest'('@delay' = " + min + ")"; else - return indent + "'#TrivialRequest'('@index' = " + index + ", '@delay' = " + min + ")"; + return indentation + "'#TrivialRequest'('@index' = " + index + ", '@delay' = " + min + ")"; else if(index == 1) - return indent + "'#TrivialRequest'('@delay' = '#bound_random'(" + min + ", " + max + "))"; + return indentation + "'#TrivialRequest'('@delay' = '#bound_random'(" + min + ", " + max + "))"; else - return indent + "'#TrivialRequest'('@index' = " + index + ", '@delay' = '#bound_random'(" + min + ", " + max + "))"; + return indentation + "'#TrivialRequest'('@index' = " + index + ", '@delay' = '#bound_random'(" + min + ", " + max + "))"; } String sendRequest2SysML(int index, String min, String max, MethodInfo signalInfo, List<String> values) { - StringBuffer result = new StringBuffer(indent + "'#SendRequest'(\n"); - indent += indentStep; + StringBuffer result = new StringBuffer(indentation + "'#SendRequest'(\n"); + indent(1); if (index != 1) - result.append(indent + "'@index' = " + index + ",\n"); - result.append(indent + "'@channel'= " + signalInfo.getName() + ",\n"); + result.append(indentation + "'@index' = " + index + ",\n"); + result.append(indentation + "'@channel'= " + signalInfo.getName() + ",\n"); if (max.equals("0")) { if (!min.equals("0")) - result.append(indent + "'@delay' = " + min + ",\n"); + result.append(indentation + "'@delay' = " + min + ",\n"); } else if (max.trim().equals(min.trim())) - result.append(indent + "'@delay' = " + min + ",\n"); + result.append(indentation + "'@delay' = " + min + ",\n"); else - result.append(indent + "'@delay' = '#bound_random'(" + min + ", " + max + "),\n"); + result.append(indentation + "'@delay' = '#bound_random'(" + min + ", " + max + "),\n"); int nbFields = signalInfo.getArity(); if (nbFields == 0) - result.append(indent + "'@payload' = " + signalInfo.getMessageType() + "()\n"); + result.append(indentation + "'@payload' = " + signalInfo.getMessageType() + "()\n"); else { - result.append(indent + "'@payload' = " + signalInfo.getMessageType() + "(\n"); - indent += indentStep; + result.append(indentation + "'@payload' = " + signalInfo.getMessageType() + "(\n"); + indent(1); int j = 0; while (j < nbFields) { //for(String vl : values) - result.append(indent + expr2SysML(values.get(j)) + ",\n"); + result.append(indentation + expr2SysML(values.get(j)) + ",\n"); j++; } result.replace(result.length()-2, result.length(), " )\n"); - indent = indent.substring(indentStepSize); + unindent(1); } - indent = indent.substring(indentStepSize); - result.append(indent + ")"); + unindent(1); + result.append(indentation + ")"); return result.toString(); } String setTimerRequest2SysML(int index, String min, String max, String chname, String value) { - StringBuffer result = new StringBuffer(indent + "'#AvatarSetTimerRequest'(\n"); - indent += indentStep; + StringBuffer result = new StringBuffer(indentation + "'#AvatarSetTimerRequest'(\n"); + indent(1); if (index != 1) - result.append(indent + "'@index' = " + index + ",\n"); - result.append(indent + "'@channel'= " + chname + ",\n"); + result.append(indentation + "'@index' = " + index + ",\n"); + result.append(indentation + "'@channel'= " + chname + ",\n"); if (max.equals("0")) { if (!min.equals("0")) - result.append(indent + "'@delay' = " + min + ",\n"); + result.append(indentation + "'@delay' = " + min + ",\n"); } else if (max.equals(min)) - result.append(indent + "'@delay' = " + min + ",\n"); + result.append(indentation + "'@delay' = " + min + ",\n"); else - result.append(indent + "'@delay' = '#bound_random'(" + min + ", " + max + "),\n"); + result.append(indentation + "'@delay' = '#bound_random'(" + min + ", " + max + "),\n"); - result.append(indent + "'@payload' = '#TimerSetMsg'(" + value + ")\n"); + result.append(indentation + "'@payload' = '#TimerSetMsg'(" + value + ")\n"); - indent = indent.substring(indentStepSize); - result.append(indent + ")"); + unindent(1); + result.append(indentation + ")"); return result.toString(); } String resetTimerRequest2SysML(int index, String min, String max, String chname) { - StringBuffer result = new StringBuffer(indent + "'#AvatarResetTimerRequest'(\n"); - indent += indentStep; + StringBuffer result = new StringBuffer(indentation + "'#AvatarResetTimerRequest'(\n"); + indent(1); if (index != 1) - result.append(indent + "'@index' = " + index + ",\n"); - result.append(indent + "'@channel'= " + chname + ",\n"); + result.append(indentation + "'@index' = " + index + ",\n"); + result.append(indentation + "'@channel'= " + chname + ",\n"); if (max.equals("0")) { if (!min.equals("0")) - result.append(indent + "'@delay' = " + min + ",\n"); + result.append(indentation + "'@delay' = " + min + ",\n"); } else if (max.equals(min)) - result.append(indent + "'@delay' = " + min + ",\n"); + result.append(indentation + "'@delay' = " + min + ",\n"); else - result.append(indent + "'@delay' = '#bound_random'(" + min + ", " + max + "),\n"); + result.append(indentation + "'@delay' = '#bound_random'(" + min + ", " + max + "),\n"); - result.append(indent + "'@payload' = '#TimerResetMsg'()\n"); + result.append(indentation + "'@payload' = '#TimerResetMsg'()\n"); - indent = indent.substring(indentStepSize); - result.append(indent + ")"); + unindent(1); + result.append(indentation + ")"); return result.toString(); } String receiveRequest2SysML(int index, String min, String max, MethodInfo chinfo) { - StringBuffer result = new StringBuffer(indent + "'#ReceiveRequest'(\n"); - indent += indentStep; + StringBuffer result = new StringBuffer(indentation + "'#ReceiveRequest'(\n"); + indent(1); if (index != 1) - result.append(indent + "'@index' = " + index + ",\n"); - result.append(indent + "'@channel'= " + chinfo.getName()); + result.append(indentation + "'@index' = " + index + ",\n"); + result.append(indentation + "'@channel'= " + chinfo.getName()); if (max.equals("0")) if (!min.equals("0")) - result.append(",\n" + indent + "'@delay' = " + min + "\n"); + result.append(",\n" + indentation + "'@delay' = " + min + "\n"); else result.append("\n"); else if (max.equals(min)) - result.append(indent + "'@delay' = " + min + ",\n"); + result.append(indentation + "'@delay' = " + min + ",\n"); else - result.append(",\n" + indent + "'@delay' = '#bound_random'(" + min + ", " + max + ")\n"); - indent = indent.substring(indentStepSize); - result.append(indent + ")"); + result.append(",\n" + indentation + "'@delay' = '#bound_random'(" + min + ", " + max + ")\n"); + unindent(1); + result.append(indentation + ")"); return result.toString(); } String expireTimerRequest2SysML(int index, String min, String max, String chname) { - StringBuffer result = new StringBuffer(indent + "'#AvatarExpireTimerRequest'(\n"); - indent += indentStep; + StringBuffer result = new StringBuffer(indentation + "'#AvatarExpireTimerRequest'(\n"); + indent(1); if (index != 1) - result.append(indent + "'@index' = " + index + ",\n"); - result.append(indent + "'@channel'= " + chname); + result.append(indentation + "'@index' = " + index + ",\n"); + result.append(indentation + "'@channel'= " + chname); if (max.equals("0")) if (!min.equals("0")) - result.append(",\n" + indent + "'@delay' = " + min + "\n"); + result.append(",\n" + indentation + "'@delay' = " + min + "\n"); else result.append("\n"); else if (max.equals(min)) - result.append(indent + "'@delay' = " + min + ",\n"); + result.append(indentation + "'@delay' = " + min + ",\n"); else - result.append(",\n" + indent + "'@delay' = '#bound_random'(" + min + ", " + max + ")\n"); - indent = indent.substring(indentStepSize); - result.append(indent + ")"); + result.append(",\n" + indentation + "'@delay' = '#bound_random'(" + min + ", " + max + ")\n"); + unindent(1); + result.append(indentation + ")"); return result.toString(); } @@ -1173,42 +1290,42 @@ public class Avatar2SysML { StringBuffer result; int size = at.getNbOfAction(); if (size == 0) return null; - result = new StringBuffer(indent + "do action : '#TransitionAction' {\n" + indent + indentStep + "first start;\n"); - indent += indentStep; + result = new StringBuffer(indentation + "do action : '#TransitionAction' {\n" + indentation + indentStep + "first start;\n"); + indent(1); for(int i = 0; i < size; i++) { String ac = at.getOriginalAction(i); int eq = ac.indexOf("="); if(eq != -1) { String lh = leftHandSysMLname(ac.substring(0,eq).trim()); String rh = expr2SysML(ac.substring(eq+1).trim()); - result.append(indent + "then assign " + lh + ":= " + rh + ";\n"); + result.append(indentation + "then assign " + lh + ":= " + rh + ";\n"); } else { - result.append(indent + "then action = " + expr2SysML(ac) + ";\n"); + result.append(indentation + "then action = " + expr2SysML(ac) + ";\n"); } } - result.append(indent + "then done;\n"); - indent = indent.substring(indentStepSize); - result.append(indent + "}"); + result.append(indentation + "then done;\n"); + unindent(1); + result.append(indentation + "}"); return result.toString(); } String receiveActions2SysML(MethodInfo signalInfo, List<String> values) { if (values == null || values.size() == 0) return ""; - StringBuffer result = new StringBuffer(indent + "do action : '#ReceiveAction' {\n"); - indent += indentStep; - result.append(indent + "item '@msg' : " + signalInfo.getMessageType() + " = '@payload' as " + signalInfo.getMessageType() + - ";\n" + indent + "first start;\n"); + StringBuffer result = new StringBuffer(indentation + "do action : '#ReceiveAction' {\n"); + indent(1); + result.append(indentation + "item '@msg' : " + signalInfo.getMessageType() + " = '@payload' as " + signalInfo.getMessageType() + + ";\n" + indentation + "first start;\n"); int nbFields = signalInfo.getArity(); int j = 0; while (j < nbFields) { - result.append(indent + "then assign " + leftHandSysMLname(values.get(j)) + + result.append(indentation + "then assign " + leftHandSysMLname(values.get(j)) + " := '@msg'." + signalInfo.getFieldName(j) + ";\n"); j++; } - result.append(indent + "then done;\n"); - indent = indent.substring(indentStepSize); - result.append(indent + "}"); + result.append(indentation + "then done;\n"); + unindent(1); + result.append(indentation + "}"); return result.toString(); } }