From 11f575c7aa22ea69de22b489423d83b14089418b Mon Sep 17 00:00:00 2001 From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr> Date: Mon, 8 Dec 2014 16:49:57 +0000 Subject: [PATCH] Update on splitting ADs --- Makefile | 7 +- src/tmltranslator/TMLCP.java | 46 +- src/tmltranslator/TMLCPSyntaxChecking.java | 1118 ++++++++--------- .../tmlcp/TMLCPActivityDiagram.java | 161 +-- src/tmltranslator/tmlcp/TMLCPElement.java | 8 + src/ui/GTMLModeling.java | 57 +- .../AvatarSpecificationSimulationSDPanel.java | 61 +- 7 files changed, 772 insertions(+), 686 deletions(-) diff --git a/Makefile b/Makefile index d644430d18..7c495fc1f7 100755 --- a/Makefile +++ b/Makefile @@ -78,11 +78,14 @@ RELEASE_STD_FILES_LICENSES = LICENSE LICENSE_CECILL_ENG LICENSE_CECILL_FR -all: +all: basic jar + + +svn: date svn update build.txt src/ui/DefaultText.java $(JAVA) -jar $(BUILDER) $(BUILD_INFO) $(BUILD_TO_MODIFY) - svn commit build.txt src/ui/DefaultText.java -m 'update on build version: builder.txt' + svn --username apvrille commit build.txt src/ui/DefaultText.java -m 'update on build version: builder.txt' $(JAVAC) $(CLASSPATH) $(TTOOL_SRC) $(TTOOL_SRC)/*.java basicsvnapvrille: diff --git a/src/tmltranslator/TMLCP.java b/src/tmltranslator/TMLCP.java index abcf4941ad..b8b32010be 100755 --- a/src/tmltranslator/TMLCP.java +++ b/src/tmltranslator/TMLCP.java @@ -312,28 +312,28 @@ public class TMLCP extends TMLElement { } public void generateNexts() { - mainCP.generateNexts(); - for(TMLCPActivityDiagram diag: otherCPs) { - diag.generateNexts(); - } - + mainCP.generateNexts(); + for(TMLCPActivityDiagram diag: otherCPs) { + diag.generateNexts(); + } + } public void removeADConnectors() { - mainCP.removeADConnectors(); - for(TMLCPActivityDiagram diag: otherCPs) { - diag.removeADConnectors(); - } + mainCP.removeADConnectors(); + for(TMLCPActivityDiagram diag: otherCPs) { + diag.removeADConnectors(); + } } public void splitADs() { - ArrayList<TMLCPActivityDiagram> all = new ArrayList<TMLCPActivityDiagram>(); - all.addAll(mainCP.splitADs()); - for(TMLCPActivityDiagram diag: otherCPs) { - all.addAll(diag.splitADs()); - } - otherCPs.addAll(all); + ArrayList<TMLCPActivityDiagram> all = new ArrayList<TMLCPActivityDiagram>(); + all.addAll(mainCP.splitADs()); + for(TMLCPActivityDiagram diag: otherCPs) { + all.addAll(diag.splitADs()); + } + otherCPs.addAll(all); } public void printDataStructure() { @@ -361,9 +361,9 @@ public class TMLCP extends TMLElement { //Print attributes System.out.printf( "\tAttributes:\n"); for( j = 0; j < listAttributes.size(); j++ ) { - attr = listAttributes.get( j ); - System.out.printf( "\t\t%s\t%s\t%s\n", attr.getName(), attr.getType(), attr.getInitialValue() ); - }*/ + attr = listAttributes.get( j ); + System.out.printf( "\t\t%s\t%s\t%s\n", attr.getName(), attr.getType(), attr.getInitialValue() ); + }*/ //Print list of AD sections ArrayList<String> ADList; @@ -449,14 +449,14 @@ public class TMLCP extends TMLElement { public String toString() { String s = "\n*** Communication Pattern: " + getName() + "***\n"; - s += mainCP.toString(); + s += mainCP.toString(); - for( tmltranslator.tmlcp.TMLCPActivityDiagram diag: otherCPs) { - s += diag.toString(); - } + for( tmltranslator.tmlcp.TMLCPActivityDiagram diag: otherCPs) { + s += diag.toString(); + } for( tmltranslator.tmlcp.TMLCPSequenceDiagram diag: sds ) { - s += sds.toString(); + s += sds.toString(); } return s; } diff --git a/src/tmltranslator/TMLCPSyntaxChecking.java b/src/tmltranslator/TMLCPSyntaxChecking.java index 019e5d47ba..3b402d6391 100755 --- a/src/tmltranslator/TMLCPSyntaxChecking.java +++ b/src/tmltranslator/TMLCPSyntaxChecking.java @@ -57,562 +57,562 @@ import tmltranslator.tmlcp.*; public class TMLCPSyntaxChecking { - - private final String WRONG_ORIGIN_CHANNEL = "is not declared as an origin channel of the task"; - private final String WRONG_DESTINATION_CHANNEL = "is not declared as a destination channel of the task"; - private final String WRONG_ORIGIN_EVENT = "is not declared as an origin event of the task"; - private final String WRONG_DESTINATION_EVENT = "is not declared as a destination event of the task"; - private final String WRONG_ORIGIN_REQUEST = "is not declared as an origin request of the task"; - private final String SYNTAX_ERROR = "syntax error"; - private final String WRONG_VARIABLE_IDENTIFIER = "forbidden variable's name"; - private final String VARIABLE_ERROR = "variable is not used according to its type"; - private final String UNDECLARED_VARIABLE = "unknown variable"; - private final String SYNTAX_ERROR_VARIABLE_EXPECTED = "syntax error (variable expected)"; - private final String TIME_UNIT_ERROR = "unknown time unit"; - - - private ArrayList<TMLCPError> errors; - private ArrayList<TMLCPError> warnings; - private TMLCP tmlcp; - private TMLMapping mapping; - - - public TMLCPSyntaxChecking( TMLCP _tmlcp ) { - tmlcp = _tmlcp; - } - - /*public TMLCPSyntaxChecking(TMLMapping _mapping) { - mapping = _mapping; - tmlm = mapping.getTMLModeling(); - }*/ - - //Checking the syntax of Activity and Sequence Diagrams - public void checkSyntax() { - - errors = new ArrayList<TMLCPError>(); - warnings = new ArrayList<TMLCPError>(); - - /*checkMainCP();*/ - checkActivityDiagrams(); - checkSequenceDiagrams(); - } - - //Check that all diagrams, forks, joins and choices are connected by retrieving the list - //of elements and checking if they appear as start or end name in the list of connectors. - //First check the mainCP then check the other Activity Diagrams - private void checkActivityDiagrams() { - - ArrayList<TMLCPActivityDiagram> junctionsList = new ArrayList<TMLCPActivityDiagram>(); - - TMLCPActivityDiagram mainCP = tmlcp.getMainCP(); - - //Checking mainCP - ArrayList<TMLCPElement> currentListOfElements = mainCP.getElements(); - checkStartState( currentListOfElements, mainCP ); - checkDisconnectedSubParts( currentListOfElements, mainCP ); - checkDiagramsBetweenForkAndJoin( currentListOfElements, mainCP ); - - //Checking the other ActivityDiagrams - ArrayList<TMLCPActivityDiagram> listADs = tmlcp.getCPActivityDiagrams(); - //TraceManager.addDev( "The list of ADs contains: " + listADs.toString() ); - for( TMLCPActivityDiagram diag: listADs ) { - currentListOfElements = diag.getElements(); - checkStartState( currentListOfElements, diag ); - TraceManager.addDev( "DIAGRAM UNDER EXAMINATION IS: " + diag.getName() ); - checkDisconnectedSubParts( currentListOfElements, diag ); - checkDiagramsBetweenForkAndJoin( currentListOfElements, diag ); - } - /*for( TMLCPElement elem: listElements ) { - if( elem instanceof tmltranslator.tmlcp.TMLCPRefAD ) { - listElementsToCheck.add(((tmltranslator.tmlcp.TMLCPRefAD)elem).getName() ); - } - if( elem instanceof tmltranslator.tmlcp.TMLCPRefSD ) { - listElementsToCheck.add(((tmltranslator.tmlcp.TMLCPRefSD)elem).getName() ); - } - if( elem instanceof TMLCPConnector ) { - listConnectorsStartEndNames.add( ((TMLCPConnector)elem).getEndName() ); - listConnectorsStartEndNames.add( ((TMLCPConnector)elem).getStartName() ); - } - if( elem instanceof tmltranslator.tmlcp.TMLCPChoice ) { - ArrayList<String> guards = ( (tmltranslator.tmlcp.TMLCPChoice)elem ).getGuards(); - listElementsToCheck.add( ((tmltranslator.tmlcp.TMLCPChoice)elem).getName() ); - //TraceManager.addDev( "PRINTING GUARDS: " + guards.toString() ); - } - if( elem instanceof tmltranslator.tmlcp.TMLCPFork ) { - //ArrayList<String> guards = ( (tmltranslator.tmlcp.TMLCPFork)elem ).getGuards(); - listElementsToCheck.add( ((tmltranslator.tmlcp.TMLCPFork)elem).getName() ); - //TraceManager.addDev( "PRINTING GUARDS: " + guards.toString() ); - } - if( elem instanceof tmltranslator.tmlcp.TMLCPJoin ) { - //ArrayList<String> guards = ( (tmltranslator.tmlcp.TMLCPFork)elem ).getGuards(); - listElementsToCheck.add( ((tmltranslator.tmlcp.TMLCPJoin)elem).getName() ); - //TraceManager.addDev( "PRINTING GUARDS: " + guards.toString() ); - } - } - - for( String s: listElementsToCheck ) { - if( !listConnectorsStartEndNames.contains(s) ) { - //TraceManager.addDev( "Diagram " + s + " in diagram " + mainCP.getName() " is not connected" ); - addError( "Element <<" + s + ">> in diagram <<" + mainCP.getName() + ">> is not connected", TMLCPError.ERROR_STRUCTURE ); - } - }*/ - } - - //Check that there is one and only one TMLCPStartState, if no start state or multiple start states, an error is raised - private void checkStartState( ArrayList<TMLCPElement> listElements, TMLCPActivityDiagram diag ) { - - int startCounter = 0; - for( TMLCPElement elem: diag.getElements() ) { - //TraceManager.addDev( "ELEMENT in AD: " + elem ); - if( elem instanceof TMLCPStart ) { - startCounter++; - } - } - if( startCounter > 1 ) { - addError( "Multiple start states in diagram <<" + diag.getName() + ">>", TMLCPError.ERROR_STRUCTURE ); - } - if( startCounter == 0 ) { - addError( "No start state has been detected in diagram <<" + diag.getName() + ">>", TMLCPError.ERROR_STRUCTURE ); - } - } - - //Look for disconnected sub-graphs by detecting elements which do not appear in the field next of any other element in the list - //of elements - private void checkDisconnectedSubParts( ArrayList<TMLCPElement> currentListOfElements, TMLCPActivityDiagram diag ) { - - ArrayList<TMLCPElement> listOfElementsToCheck = currentListOfElements; - int counter = 0; - - for( TMLCPElement currentElement: currentListOfElements ) { - if( !(currentElement instanceof TMLCPStart) ) { - for( TMLCPElement element: listOfElementsToCheck ) { - ArrayList<TMLCPElement> nextElements = element.getNextElements(); - if( !nextElements.contains( currentElement ) ) { //counting how many times currentElement is NOT present as a next element - counter++; - } - } - } - //If currentElement is NEVER present as a next element it means its head is not connected - if( counter == currentListOfElements.size() ) { - addError( "Element <<" + currentElement.toString()+ ">> in diagram <<" + diag.getName() + ">> is not correctly connected", TMLCPError.ERROR_STRUCTURE ); - } - counter = 0; - } - } - - private void checkDiagramsBetweenForkAndJoin( ArrayList<TMLCPElement> currentListOfElements, TMLCPActivityDiagram diag ) { - - ArrayList<TMLCPFork> listOfForks = new ArrayList<TMLCPFork>(); - ArrayList<TMLCPJoin> listOfJoins = new ArrayList<TMLCPJoin>(); - - for( TMLCPElement element: currentListOfElements ) { - if( element instanceof TMLCPFork ) { - listOfForks.add( (TMLCPFork) element ); - } - } - for( TMLCPFork fork: listOfForks ) { - for( TMLCPElement element: fork.getNextElements() ) { - TMLCPJoin joinNode = explorePath( element); - if( joinNode == null ) { - addError( "Error in fork node <<" + element.toString() + ">> in diagram <<" + diag.getName(), TMLCPError.ERROR_STRUCTURE ); - } - else { - listOfJoins.add( joinNode ); - if( Collections.frequency( listOfJoins, listOfJoins.get(0)) != listOfJoins.size() ) { - addError( "Error element <<" + element.toString() + ">> in diagram <<" + diag.getName() + ">> is not connected to the right join node", TMLCPError.ERROR_STRUCTURE ); - break; - } - } - } - listOfJoins.clear(); - } - } - - //Recursive function that explores the path from an element until a join node - private TMLCPJoin explorePath( TMLCPElement element ) { - - TMLCPJoin joinNode = new TMLCPJoin( element.toString(), element ); - //TraceManager.addDev( "explorePath from element " + element.toString() ); - if( element instanceof TMLCPJoin ) { //stop condition - //TraceManager.addDev( "returning from explorePath with element " + element.toString() ); - joinNode = (TMLCPJoin) element; - } - else if( (element instanceof TMLCPRefSD) || (element instanceof TMLCPRefAD) ) { - //TraceManager.addDev( "continuing in explorePath with element " + element.getNextElements().get(0).toString() ); - joinNode = explorePath( element.getNextElements().get(0) ); - } - else { - joinNode = null; - } - return joinNode; - } - - //Check that all diagrams are connected by retrieving the list of diagrams and checking if they appear as start or end name in - //the list of connectors of the AD diagram under examination - //At the same time, get the list of guards of choice elements - private void checkActivityDiagramsOLD() { - - ArrayList<TMLCPActivityDiagram> listADs = tmlcp.getCPActivityDiagrams(); - ArrayList<TMLCPSequenceDiagram> listSDs = tmlcp.getCPSequenceDiagrams(); - ArrayList<String> listConnectorsStartEndNames = new ArrayList<String>(); - ArrayList<String> listDiagramNames = new ArrayList<String>(); - ArrayList<String> localListOfSDDiagrams = new ArrayList<String>(); - //check that all diagrams are connected - - for( TMLCPActivityDiagram diag: listADs ) { - ArrayList<TMLCPElement> listElements = diag.getElements(); - for( TMLCPElement elem : listElements ) { - if( elem instanceof tmltranslator.tmlcp.TMLCPRefAD ) { - listDiagramNames.add(((tmltranslator.tmlcp.TMLCPRefAD)elem).getName() ); - } - if( elem instanceof tmltranslator.tmlcp.TMLCPRefSD ) { - listDiagramNames.add(((tmltranslator.tmlcp.TMLCPRefSD)elem).getName() ); - localListOfSDDiagrams.add( ( (tmltranslator.tmlcp.TMLCPRefSD)elem ).getName() ); - } - if( elem instanceof TMLCPConnector ) { - listConnectorsStartEndNames.add( ((TMLCPConnector)elem).getEndName() ); - listConnectorsStartEndNames.add( ((TMLCPConnector)elem).getStartName() ); - } - if( elem instanceof tmltranslator.tmlcp.TMLCPChoice ) { - ArrayList<String> guards = ( (tmltranslator.tmlcp.TMLCPChoice)elem ).getGuards(); - HashSet<String> variableList = new HashSet<String>(); - for( String guard: guards ) { - guard = guard.replaceAll("\\s+",""); - if( guard.length() > 0 ) { - String[] token = guard.split( "\\[" ); - if( token[1].equals("]") ) { - break; - } - String[] token1 = token[1].split("="); - if( token1.length > 1 ) { - variableList.add( token1[0] ); - } - else { - String[] token2 = token1[0].split("<"); - if( token2.length > 1 ) { - variableList.add( token2[0] ); - } - else { - String[] token3 = token2[0].split(">"); - variableList.add( token3[0] ); - } - } - } - } - checkChoiceGuards( listSDs, variableList, localListOfSDDiagrams, diag.getName() ); - //check if they have been declared in the instances of a SD diagram - TraceManager.addDev( "AD DIAGRAM " + diag.getName() ); - TraceManager.addDev( "variableList: " + variableList.toString() ); - TraceManager.addDev( "localListOfSDDiagrams: " + localListOfSDDiagrams.toString() ); - localListOfSDDiagrams = new ArrayList<String>(); - variableList = new HashSet(); - /*for( TMLCPSequenceDiagram diagram: listSDDiagrams ) { - TraceManager.addDev( "NAME OF DIAGRAM: " + listSDDiagrams.toString() ); - ArrayList<TMLAttribute> listAttributes = diagram.getAttributes(); - for( TMLAttribute attr: listAttributes ) { - if( !variableList.contains( attr.getName() ) ) { - addError( "Variable <<" + attr.getName() + ">> is not declared in any diagram of <<" + diag.getName() + ">>", - TMLCPError.ERROR_STRUCTURE ); - } - } - }*/ - } //endOfLoop over elements - - } - for( String s: listDiagramNames ) { - if( !listConnectorsStartEndNames.contains(s) ) { - //TraceManager.addDev( "Diagram " + s + " is not connected in diagram " + diag.getName() ); - addError( "Diagram <<" + s + ">> in diagram <<" + diag.getName() + ">> is not connected", TMLCPError.ERROR_STRUCTURE ); - } - } - listConnectorsStartEndNames = new ArrayList<String>(); - listDiagramNames = new ArrayList<String>(); - } - } - - public void checkChoiceGuards( ArrayList<TMLCPSequenceDiagram> listSDs, HashSet<String> variableList, - ArrayList<String> localListOfSDDiagrams, String diagName ) { - - ArrayList<TMLAttribute> attributeList = new ArrayList<TMLAttribute>(); - for( String s: localListOfSDDiagrams ) { - for( TMLCPSequenceDiagram sdDiagram: listSDs ) { - if( sdDiagram.getName().equals( s ) ) { - attributeList = sdDiagram.getAttributes(); - TraceManager.addDev( "In diagram: " + diagName + "found SD diagram " + sdDiagram.getName() - + " with corresponding attributes " + attributeList.toString() ); - } - } - } - for( TMLAttribute attr: attributeList ) { - if( !variableList.contains( attr.getName() ) ) { - addError( "Attribute <<" + attr.getName() + ">> is not declared in diagram <<" + diagName + ">>", TMLCPError.ERROR_STRUCTURE ); - } - } - } - - //For each sequence diagram, check: - // - that the parameters of messages have been declared as attributes of the instances - // - that actions are syntactically correct (no arit operations on boolean, etc.) - // - that no 2 or more instances have the same name - private void checkSequenceDiagrams() { - ArrayList<TMLCPSequenceDiagram> listSDs = tmlcp.getCPSequenceDiagrams(); - - for( TMLCPSequenceDiagram diag: listSDs ) { - ArrayList<TMLAttribute> attributes = diag.getAttributes(); - //checkUniquenessOfAttributesNames( diag ); // already done in the GUI when declaring attributes - checkActions( diag, attributes ); // actions must be done on variables that have - checkMessages( diag ); // check that attributes have been declared been declared and coherently boolean = boolean + 6 is not allowed - checkInstances( diag ); // instances within the same SD must all have different names - } - } - - private void checkActions( TMLCPSequenceDiagram diag, ArrayList<TMLAttribute> attributes ) { - ArrayList<TMLSDAction> actions = diag.getActions(); - //boolean exists = false; - for( TMLSDAction action: actions ) { - String[] array = action.toString().split("="); - String temp = array[0].replaceAll("\\s+",""); - //TraceManager.addDev( "CHECKING ACTIONS: " + temp + " of length " + temp.length() ); - for( TMLAttribute attribute: attributes ) { - //TraceManager.addDev( "PRINTING ATTRIBUTE NAMES: " + attribute.getName() ); - if( attribute.getName().equals( temp ) ) { - if( attribute.isBool() ) { - parsing( "assbool", action.toString() ); - //TraceManager.addDev( "Found that the action is on a boolean variable: " + temp ); - //exists = true; - break; - } - if( attribute.isNat() ) { - parsing( "assnat", action.toString() ); - //TraceManager.addDev( "Found that the action is on a natural variable: " + temp ); - //exists = true; - break; - } - } - } - } - } - - // Check that for each message parameter, the corresponding attribute has been declared in both the sender - // and the receiver instances with the same name - private void checkMessages( TMLCPSequenceDiagram diag ) { - - ArrayList<TMLSDMessage> messagesList = diag.getMessages(); - - for( TMLSDMessage message: messagesList ) { - String senderInstance = message.getSenderName(); - String receiverInstance = message.getReceiverName(); - ArrayList<TMLAttribute> parametersList = message.getAttributes(); - for( TMLAttribute parameter: parametersList ) { - if( !isParameterDeclared( parameter, senderInstance, diag ) ) { - addError( "Parameter <<" + parameter.getName() + ">> has not been declared in instance <<" + senderInstance + ">> in diagram <<" + diag.getName() + ">>", TMLCPError.ERROR_STRUCTURE ); - } - if( !isParameterDeclared( parameter, receiverInstance, diag ) ) { - addError( "Parameter <<" + parameter.getName() + ">> has not been declared in instance <<" + receiverInstance + ">> in diagram <<" + diag.getName() + ">>", TMLCPError.ERROR_STRUCTURE ); - } - if( !checkTypeCoherency( parameter, senderInstance, receiverInstance, diag ) ) { - addError( "Parameter <<" + parameter.getName() + ">> is declared with different types in instance <<" + senderInstance + ">> and in instance <<" + receiverInstance + ">> in diagram <<" + diag.getName() + ">>", TMLCPError.ERROR_STRUCTURE ); - } - } - } - } - - //Check that the parameter has been declared in the instance corresponding to instanceName - private boolean isParameterDeclared( TMLAttribute parameter, String instanceName, TMLCPSequenceDiagram diag ) { - - for( TMLSDInstance instance: diag.getInstances() ) { - if( instance.getName().equals( instanceName ) ) { - for( TMLAttribute attribute: instance.getAttributes() ) { //don't use contains() as parameter is created with some partial attributes - if( attribute.getName().equals( parameter.getName() ) ) { - return true; - } - } - } - } - return false; - } - - //Check that the type of parameter is the samein both sender and receiver instances - private boolean checkTypeCoherency( TMLAttribute parameter, String senderInstance, String receiverInstance, TMLCPSequenceDiagram diag ) { - - int typeOfAttributeInSenderInstance = 0; - int typeOfAttributeInReceiverInstance = 0; - - for( TMLSDInstance instance: diag.getInstances() ) { - if( instance.getName().equals( senderInstance ) ) { - for( TMLAttribute attribute: instance.getAttributes() ) { //don't use contains() as parameter is created with some partial attributes - if( attribute.getName().equals( parameter.getName() ) ) { - typeOfAttributeInSenderInstance = attribute.getType().getType(); - break; - } - } - } - if( instance.getName().equals( receiverInstance ) ) { - for( TMLAttribute attribute: instance.getAttributes() ) { //don't use contains() as parameter is created with some partial attributes - if( attribute.getName().equals( parameter.getName() ) ) { - typeOfAttributeInReceiverInstance = attribute.getType().getType(); - break; - } - } - } - } - return ( typeOfAttributeInSenderInstance == typeOfAttributeInReceiverInstance ); - } - - private void checkInstances( TMLCPSequenceDiagram diag ) { - ArrayList<TMLSDInstance> instances = diag.getInstances(); - HashSet hash = new HashSet(); - for( TMLSDInstance instance: instances ) { - if( !hash.contains( instance.getName() ) ) { - hash.add( instance.getName() ); - } - else { - //TraceManager.addDev( "Error double instance name " + instance.getName() + " in diagram " + diag.getName() ); - addError( "Instance <<" + instance.getName() + ">> is declared multiple times in diagram <<" + diag.getName() + ">>", - TMLCPError.ERROR_STRUCTURE ); - } - } - } - - public int hasErrors() { - if( errors == null ) { - return 0; - } - return errors.size(); - } - - public int hasWarnings() { - if( warnings == null ) { - return 0; - } - return warnings.size(); - } - - public ArrayList<TMLCPError> getErrors() { - return errors; - } - - public ArrayList<TMLCPError> getWarnings() { - return warnings; - } - -/* public void addError( TMLTask t, TMLActivityElement elt, String message, int type ) { - TMLError error = new TMLError( type ); - error.message = message; - error.task = t; - error.element = elt; - errors.add( error ); - }*/ - - public void addError( String message, int type ) { - TMLCPError error = new TMLCPError( type ); - error.message = message; - errors.add( error ); - } - - public String printSummary() { - String ret = ""; - if( errors.size() == 0 ) { - ret += printWarnings(); - ret += "Syntax checking: successful\n"; - ret += "No error, " + warnings.size() + " warning(s)\n"; - } - else { - ret += printErrors() + printWarnings(); - ret += "Syntax checking: failed\n"; - ret += errors.size() + " error(s), "+ warnings.size() + " warning(s)\n"; - } - return ret; - } - - public String printErrors() { - String ret = "*** ERRORS:"; - for( TMLCPError error: errors ) { - ret += "ERROR: " + error.message; - } - return ret; - } - - public String printWarnings() { - String ret = ""; - for( TMLCPError error: warnings ) { - ret += "ERROR / task " + error.task.getName() + " / element: " + error.element.getName() + ": " + error.message + "\n"; - } - return ret; - } - - public void parsing( String parseCmd, String action) { - TMLExprParser parser; - SimpleNode root; - - // First parsing - TraceManager.addDev("-------- Parsing of " + (parseCmd + " " + action)); - parser = new TMLExprParser(new StringReader(parseCmd + " " + action)); - try { - //System.out.println("\nParsing :" + parseCmd + " " + action); - root = parser.CompilationUnit(); - //root.dump("pref="); - //System.out.println("Parse ok"); - } catch (ParseException e) { - //System.out.println("ParseException --------> Parse error in :" + parseCmd + " " + action); - addError( SYNTAX_ERROR + " in expression " + action, TMLError.ERROR_BEHAVIOR); - return; - } catch (TokenMgrError tke ) { - //System.out.println("TokenMgrError --------> Parse error in :" + parseCmd + " " + action); - addError( SYNTAX_ERROR + " in expression " + action, TMLError.ERROR_BEHAVIOR); - return; - } - - // Second parsing - // We only replace variables values after the "=" sign - if (parseCmd.compareTo("natnumeral") == 0) { - return; - } - - int index = action.indexOf('='); - String modif = action; - - if ((parseCmd.compareTo("assnat") ==0) || (parseCmd.compareTo("assbool") ==0)) { - if (index != -1) { - modif = action.substring(index+1, action.length()); - } - - if (parseCmd.compareTo("assnat") ==0) { - parseCmd = "actionnat"; - } else { - parseCmd = "actionbool"; - } - } - - if (parseCmd.compareTo("natid") == 0) { - parseCmd = "natnumeral"; - } - - /*for(TMLAttribute attr: t.getAttributes()) { - modif = tmlm.putAttributeValueInString(modif, attr); - }*/ - parser = new TMLExprParser(new StringReader(parseCmd + " " + modif)); - try { - //System.out.println("\nParsing :" + parseCmd + " " + modif); - root = parser.CompilationUnit(); - //root.dump("pref="); - //System.out.println("Parse ok"); - } catch (ParseException e) { - //System.out.println("ParseException --------> Parse error in :" + parseCmd + " " + action); - addError( VARIABLE_ERROR + " in expression " + action, TMLError.ERROR_BEHAVIOR); - return; - } catch (TokenMgrError tke ) { - //System.out.println("TokenMgrError --------> Parse error in :" + parseCmd + " " + action); - addError( VARIABLE_ERROR + " in expression " + action, TMLError.ERROR_BEHAVIOR); - return; - } - - // Tree analysis: if the tree contains a variable, then, this variable has not been declared - ArrayList<String> vars = root.getVariables(); - TraceManager.addDev( "PRINTING VARS IN PARSING(): " + vars.toString() ); - for(String s: vars) { - addError( UNDECLARED_VARIABLE + " :" + s + " in expression " + action, TMLError.ERROR_BEHAVIOR); - } - - } -} //End of class + + private final String WRONG_ORIGIN_CHANNEL = "is not declared as an origin channel of the task"; + private final String WRONG_DESTINATION_CHANNEL = "is not declared as a destination channel of the task"; + private final String WRONG_ORIGIN_EVENT = "is not declared as an origin event of the task"; + private final String WRONG_DESTINATION_EVENT = "is not declared as a destination event of the task"; + private final String WRONG_ORIGIN_REQUEST = "is not declared as an origin request of the task"; + private final String SYNTAX_ERROR = "syntax error"; + private final String WRONG_VARIABLE_IDENTIFIER = "forbidden variable's name"; + private final String VARIABLE_ERROR = "variable is not used according to its type"; + private final String UNDECLARED_VARIABLE = "unknown variable"; + private final String SYNTAX_ERROR_VARIABLE_EXPECTED = "syntax error (variable expected)"; + private final String TIME_UNIT_ERROR = "unknown time unit"; + + + private ArrayList<TMLCPError> errors; + private ArrayList<TMLCPError> warnings; + private TMLCP tmlcp; + private TMLMapping mapping; + + + public TMLCPSyntaxChecking( TMLCP _tmlcp ) { + tmlcp = _tmlcp; + } + + /*public TMLCPSyntaxChecking(TMLMapping _mapping) { + mapping = _mapping; + tmlm = mapping.getTMLModeling(); + }*/ + + //Checking the syntax of Activity and Sequence Diagrams + public void checkSyntax() { + + errors = new ArrayList<TMLCPError>(); + warnings = new ArrayList<TMLCPError>(); + + /*checkMainCP();*/ + checkActivityDiagrams(); + checkSequenceDiagrams(); + } + + //Check that all diagrams, forks, joins and choices are connected by retrieving the list + //of elements and checking if they appear as start or end name in the list of connectors. + //First check the mainCP then check the other Activity Diagrams + private void checkActivityDiagrams() { + + ArrayList<TMLCPActivityDiagram> junctionsList = new ArrayList<TMLCPActivityDiagram>(); + + TMLCPActivityDiagram mainCP = tmlcp.getMainCP(); + + //Checking mainCP + ArrayList<TMLCPElement> currentListOfElements = mainCP.getElements(); + checkStartState( currentListOfElements, mainCP ); + checkDisconnectedSubParts( currentListOfElements, mainCP ); + checkDiagramsBetweenForkAndJoin( currentListOfElements, mainCP ); + + //Checking the other ActivityDiagrams + ArrayList<TMLCPActivityDiagram> listADs = tmlcp.getCPActivityDiagrams(); + //TraceManager.addDev( "The list of ADs contains: " + listADs.toString() ); + for( TMLCPActivityDiagram diag: listADs ) { + currentListOfElements = diag.getElements(); + checkStartState( currentListOfElements, diag ); + TraceManager.addDev( "DIAGRAM UNDER EXAMINATION IS: " + diag.getName() ); + checkDisconnectedSubParts( currentListOfElements, diag ); + checkDiagramsBetweenForkAndJoin( currentListOfElements, diag ); + } + /*for( TMLCPElement elem: listElements ) { + if( elem instanceof tmltranslator.tmlcp.TMLCPRefAD ) { + listElementsToCheck.add(((tmltranslator.tmlcp.TMLCPRefAD)elem).getName() ); + } + if( elem instanceof tmltranslator.tmlcp.TMLCPRefSD ) { + listElementsToCheck.add(((tmltranslator.tmlcp.TMLCPRefSD)elem).getName() ); + } + if( elem instanceof TMLCPConnector ) { + listConnectorsStartEndNames.add( ((TMLCPConnector)elem).getEndName() ); + listConnectorsStartEndNames.add( ((TMLCPConnector)elem).getStartName() ); + } + if( elem instanceof tmltranslator.tmlcp.TMLCPChoice ) { + ArrayList<String> guards = ( (tmltranslator.tmlcp.TMLCPChoice)elem ).getGuards(); + listElementsToCheck.add( ((tmltranslator.tmlcp.TMLCPChoice)elem).getName() ); + //TraceManager.addDev( "PRINTING GUARDS: " + guards.toString() ); + } + if( elem instanceof tmltranslator.tmlcp.TMLCPFork ) { + //ArrayList<String> guards = ( (tmltranslator.tmlcp.TMLCPFork)elem ).getGuards(); + listElementsToCheck.add( ((tmltranslator.tmlcp.TMLCPFork)elem).getName() ); + //TraceManager.addDev( "PRINTING GUARDS: " + guards.toString() ); + } + if( elem instanceof tmltranslator.tmlcp.TMLCPJoin ) { + //ArrayList<String> guards = ( (tmltranslator.tmlcp.TMLCPFork)elem ).getGuards(); + listElementsToCheck.add( ((tmltranslator.tmlcp.TMLCPJoin)elem).getName() ); + //TraceManager.addDev( "PRINTING GUARDS: " + guards.toString() ); + } + } + + for( String s: listElementsToCheck ) { + if( !listConnectorsStartEndNames.contains(s) ) { + //TraceManager.addDev( "Diagram " + s + " in diagram " + mainCP.getName() " is not connected" ); + addError( "Element <<" + s + ">> in diagram <<" + mainCP.getName() + ">> is not connected", TMLCPError.ERROR_STRUCTURE ); + } + }*/ + } + + //Check that there is one and only one TMLCPStartState, if no start state or multiple start states, an error is raised + private void checkStartState( ArrayList<TMLCPElement> listElements, TMLCPActivityDiagram diag ) { + + int startCounter = 0; + for( TMLCPElement elem: diag.getElements() ) { + //TraceManager.addDev( "ELEMENT in AD: " + elem ); + if( elem instanceof TMLCPStart ) { + startCounter++; + } + } + if( startCounter > 1 ) { + addError( "Multiple start states in diagram <<" + diag.getName() + ">>", TMLCPError.ERROR_STRUCTURE ); + } + if( startCounter == 0 ) { + addError( "No start state has been detected in diagram <<" + diag.getName() + ">>", TMLCPError.ERROR_STRUCTURE ); + } + } + + //Look for disconnected sub-graphs by detecting elements which do not appear in the field next of any other element in the list + //of elements + private void checkDisconnectedSubParts( ArrayList<TMLCPElement> currentListOfElements, TMLCPActivityDiagram diag ) { + + ArrayList<TMLCPElement> listOfElementsToCheck = currentListOfElements; + int counter = 0; + + for( TMLCPElement currentElement: currentListOfElements ) { + if( !(currentElement instanceof TMLCPStart) ) { + for( TMLCPElement element: listOfElementsToCheck ) { + ArrayList<TMLCPElement> nextElements = element.getNextElements(); + if( !nextElements.contains( currentElement ) ) { //counting how many times currentElement is NOT present as a next element + counter++; + } + } + } + //If currentElement is NEVER present as a next element it means its head is not connected + if( counter == currentListOfElements.size() ) { + addError( "Element <<" + currentElement.toString()+ ">> in diagram <<" + diag.getName() + ">> is not correctly connected", TMLCPError.ERROR_STRUCTURE ); + } + counter = 0; + } + } + + private void checkDiagramsBetweenForkAndJoin( ArrayList<TMLCPElement> currentListOfElements, TMLCPActivityDiagram diag ) { + + ArrayList<TMLCPFork> listOfForks = new ArrayList<TMLCPFork>(); + ArrayList<TMLCPJoin> listOfJoins = new ArrayList<TMLCPJoin>(); + + for( TMLCPElement element: currentListOfElements ) { + if( element instanceof TMLCPFork ) { + listOfForks.add( (TMLCPFork) element ); + } + } + for( TMLCPFork fork: listOfForks ) { + for( TMLCPElement element: fork.getNextElements() ) { + TMLCPJoin joinNode = explorePath( element); + if( joinNode == null ) { + addError( "Error in fork node <<" + element.toString() + ">> in diagram <<" + diag.getName(), TMLCPError.ERROR_STRUCTURE ); + } + else { + listOfJoins.add( joinNode ); + if( Collections.frequency( listOfJoins, listOfJoins.get(0)) != listOfJoins.size() ) { + addError( "Error element <<" + element.toString() + ">> in diagram <<" + diag.getName() + ">> is not connected to the right join node", TMLCPError.ERROR_STRUCTURE ); + break; + } + } + } + listOfJoins.clear(); + } + } + + //Recursive function that explores the path from an element until a join node + private TMLCPJoin explorePath( TMLCPElement element ) { + + TMLCPJoin joinNode = new TMLCPJoin( element.toString(), element ); + //TraceManager.addDev( "explorePath from element " + element.toString() ); + if( element instanceof TMLCPJoin ) { //stop condition + //TraceManager.addDev( "returning from explorePath with element " + element.toString() ); + joinNode = (TMLCPJoin) element; + } + else if( (element instanceof TMLCPRefSD) || (element instanceof TMLCPRefAD) ) { + //TraceManager.addDev( "continuing in explorePath with element " + element.getNextElements().get(0).toString() ); + joinNode = explorePath( element.getNextElements().get(0) ); + } + else { + joinNode = null; + } + return joinNode; + } + + //Check that all diagrams are connected by retrieving the list of diagrams and checking if they appear as start or end name in + //the list of connectors of the AD diagram under examination + //At the same time, get the list of guards of choice elements + private void checkActivityDiagramsOLD() { + + ArrayList<TMLCPActivityDiagram> listADs = tmlcp.getCPActivityDiagrams(); + ArrayList<TMLCPSequenceDiagram> listSDs = tmlcp.getCPSequenceDiagrams(); + ArrayList<String> listConnectorsStartEndNames = new ArrayList<String>(); + ArrayList<String> listDiagramNames = new ArrayList<String>(); + ArrayList<String> localListOfSDDiagrams = new ArrayList<String>(); + //check that all diagrams are connected + + for( TMLCPActivityDiagram diag: listADs ) { + ArrayList<TMLCPElement> listElements = diag.getElements(); + for( TMLCPElement elem : listElements ) { + if( elem instanceof tmltranslator.tmlcp.TMLCPRefAD ) { + listDiagramNames.add(((tmltranslator.tmlcp.TMLCPRefAD)elem).getName() ); + } + if( elem instanceof tmltranslator.tmlcp.TMLCPRefSD ) { + listDiagramNames.add(((tmltranslator.tmlcp.TMLCPRefSD)elem).getName() ); + localListOfSDDiagrams.add( ( (tmltranslator.tmlcp.TMLCPRefSD)elem ).getName() ); + } + if( elem instanceof TMLCPConnector ) { + listConnectorsStartEndNames.add( ((TMLCPConnector)elem).getEndName() ); + listConnectorsStartEndNames.add( ((TMLCPConnector)elem).getStartName() ); + } + if( elem instanceof tmltranslator.tmlcp.TMLCPChoice ) { + ArrayList<String> guards = ( (tmltranslator.tmlcp.TMLCPChoice)elem ).getGuards(); + HashSet<String> variableList = new HashSet<String>(); + for( String guard: guards ) { + guard = guard.replaceAll("\\s+",""); + if( guard.length() > 0 ) { + String[] token = guard.split( "\\[" ); + if( token[1].equals("]") ) { + break; + } + String[] token1 = token[1].split("="); + if( token1.length > 1 ) { + variableList.add( token1[0] ); + } + else { + String[] token2 = token1[0].split("<"); + if( token2.length > 1 ) { + variableList.add( token2[0] ); + } + else { + String[] token3 = token2[0].split(">"); + variableList.add( token3[0] ); + } + } + } + } + checkChoiceGuards( listSDs, variableList, localListOfSDDiagrams, diag.getName() ); + //check if they have been declared in the instances of a SD diagram + TraceManager.addDev( "AD DIAGRAM " + diag.getName() ); + TraceManager.addDev( "variableList: " + variableList.toString() ); + TraceManager.addDev( "localListOfSDDiagrams: " + localListOfSDDiagrams.toString() ); + localListOfSDDiagrams = new ArrayList<String>(); + variableList = new HashSet(); + /*for( TMLCPSequenceDiagram diagram: listSDDiagrams ) { + TraceManager.addDev( "NAME OF DIAGRAM: " + listSDDiagrams.toString() ); + ArrayList<TMLAttribute> listAttributes = diagram.getAttributes(); + for( TMLAttribute attr: listAttributes ) { + if( !variableList.contains( attr.getName() ) ) { + addError( "Variable <<" + attr.getName() + ">> is not declared in any diagram of <<" + diag.getName() + ">>", + TMLCPError.ERROR_STRUCTURE ); + } + } + }*/ + } //endOfLoop over elements + + } + for( String s: listDiagramNames ) { + if( !listConnectorsStartEndNames.contains(s) ) { + //TraceManager.addDev( "Diagram " + s + " is not connected in diagram " + diag.getName() ); + addError( "Diagram <<" + s + ">> in diagram <<" + diag.getName() + ">> is not connected", TMLCPError.ERROR_STRUCTURE ); + } + } + listConnectorsStartEndNames = new ArrayList<String>(); + listDiagramNames = new ArrayList<String>(); + } + } + + public void checkChoiceGuards( ArrayList<TMLCPSequenceDiagram> listSDs, HashSet<String> variableList, + ArrayList<String> localListOfSDDiagrams, String diagName ) { + + ArrayList<TMLAttribute> attributeList = new ArrayList<TMLAttribute>(); + for( String s: localListOfSDDiagrams ) { + for( TMLCPSequenceDiagram sdDiagram: listSDs ) { + if( sdDiagram.getName().equals( s ) ) { + attributeList = sdDiagram.getAttributes(); + TraceManager.addDev( "In diagram: " + diagName + "found SD diagram " + sdDiagram.getName() + + " with corresponding attributes " + attributeList.toString() ); + } + } + } + for( TMLAttribute attr: attributeList ) { + if( !variableList.contains( attr.getName() ) ) { + addError( "Attribute <<" + attr.getName() + ">> is not declared in diagram <<" + diagName + ">>", TMLCPError.ERROR_STRUCTURE ); + } + } + } + + //For each sequence diagram, check: + // - that the parameters of messages have been declared as attributes of the instances + // - that actions are syntactically correct (no arit operations on boolean, etc.) + // - that no 2 or more instances have the same name + private void checkSequenceDiagrams() { + ArrayList<TMLCPSequenceDiagram> listSDs = tmlcp.getCPSequenceDiagrams(); + + for( TMLCPSequenceDiagram diag: listSDs ) { + ArrayList<TMLAttribute> attributes = diag.getAttributes(); + //checkUniquenessOfAttributesNames( diag ); // already done in the GUI when declaring attributes + checkActions( diag, attributes ); // actions must be done on variables that have + checkMessages( diag ); // check that attributes have been declared been declared and coherently boolean = boolean + 6 is not allowed + checkInstances( diag ); // instances within the same SD must all have different names + } + } + + private void checkActions( TMLCPSequenceDiagram diag, ArrayList<TMLAttribute> attributes ) { + ArrayList<TMLSDAction> actions = diag.getActions(); + //boolean exists = false; + for( TMLSDAction action: actions ) { + String[] array = action.toString().split("="); + String temp = array[0].replaceAll("\\s+",""); + //TraceManager.addDev( "CHECKING ACTIONS: " + temp + " of length " + temp.length() ); + for( TMLAttribute attribute: attributes ) { + //TraceManager.addDev( "PRINTING ATTRIBUTE NAMES: " + attribute.getName() ); + if( attribute.getName().equals( temp ) ) { + if( attribute.isBool() ) { + parsing( "assbool", action.toString() ); + //TraceManager.addDev( "Found that the action is on a boolean variable: " + temp ); + //exists = true; + break; + } + if( attribute.isNat() ) { + parsing( "assnat", action.toString() ); + //TraceManager.addDev( "Found that the action is on a natural variable: " + temp ); + //exists = true; + break; + } + } + } + } + } + + // Check that for each message parameter, the corresponding attribute has been declared in both the sender + // and the receiver instances with the same name + private void checkMessages( TMLCPSequenceDiagram diag ) { + + ArrayList<TMLSDMessage> messagesList = diag.getMessages(); + + for( TMLSDMessage message: messagesList ) { + String senderInstance = message.getSenderName(); + String receiverInstance = message.getReceiverName(); + ArrayList<TMLAttribute> parametersList = message.getAttributes(); + for( TMLAttribute parameter: parametersList ) { + if( !isParameterDeclared( parameter, senderInstance, diag ) ) { + addError( "Parameter <<" + parameter.getName() + ">> has not been declared in instance <<" + senderInstance + ">> in diagram <<" + diag.getName() + ">>", TMLCPError.ERROR_STRUCTURE ); + } + if( !isParameterDeclared( parameter, receiverInstance, diag ) ) { + addError( "Parameter <<" + parameter.getName() + ">> has not been declared in instance <<" + receiverInstance + ">> in diagram <<" + diag.getName() + ">>", TMLCPError.ERROR_STRUCTURE ); + } + if( !checkTypeCoherency( parameter, senderInstance, receiverInstance, diag ) ) { + addError( "Parameter <<" + parameter.getName() + ">> is declared with different types in instance <<" + senderInstance + ">> and in instance <<" + receiverInstance + ">> in diagram <<" + diag.getName() + ">>", TMLCPError.ERROR_STRUCTURE ); + } + } + } + } + + //Check that the parameter has been declared in the instance corresponding to instanceName + private boolean isParameterDeclared( TMLAttribute parameter, String instanceName, TMLCPSequenceDiagram diag ) { + + for( TMLSDInstance instance: diag.getInstances() ) { + if( instance.getName().equals( instanceName ) ) { + for( TMLAttribute attribute: instance.getAttributes() ) { //don't use contains() as parameter is created with some partial attributes + if( attribute.getName().equals( parameter.getName() ) ) { + return true; + } + } + } + } + return false; + } + + //Check that the type of parameter is the samein both sender and receiver instances + private boolean checkTypeCoherency( TMLAttribute parameter, String senderInstance, String receiverInstance, TMLCPSequenceDiagram diag ) { + + int typeOfAttributeInSenderInstance = 0; + int typeOfAttributeInReceiverInstance = 0; + + for( TMLSDInstance instance: diag.getInstances() ) { + if( instance.getName().equals( senderInstance ) ) { + for( TMLAttribute attribute: instance.getAttributes() ) { //don't use contains() as parameter is created with some partial attributes + if( attribute.getName().equals( parameter.getName() ) ) { + typeOfAttributeInSenderInstance = attribute.getType().getType(); + break; + } + } + } + if( instance.getName().equals( receiverInstance ) ) { + for( TMLAttribute attribute: instance.getAttributes() ) { //don't use contains() as parameter is created with some partial attributes + if( attribute.getName().equals( parameter.getName() ) ) { + typeOfAttributeInReceiverInstance = attribute.getType().getType(); + break; + } + } + } + } + return ( typeOfAttributeInSenderInstance == typeOfAttributeInReceiverInstance ); + } + + private void checkInstances( TMLCPSequenceDiagram diag ) { + ArrayList<TMLSDInstance> instances = diag.getInstances(); + HashSet hash = new HashSet(); + for( TMLSDInstance instance: instances ) { + if( !hash.contains( instance.getName() ) ) { + hash.add( instance.getName() ); + } + else { + //TraceManager.addDev( "Error double instance name " + instance.getName() + " in diagram " + diag.getName() ); + addError( "Instance <<" + instance.getName() + ">> is declared multiple times in diagram <<" + diag.getName() + ">>", + TMLCPError.ERROR_STRUCTURE ); + } + } + } + + public int hasErrors() { + if( errors == null ) { + return 0; + } + return errors.size(); + } + + public int hasWarnings() { + if( warnings == null ) { + return 0; + } + return warnings.size(); + } + + public ArrayList<TMLCPError> getErrors() { + return errors; + } + + public ArrayList<TMLCPError> getWarnings() { + return warnings; + } + + /* public void addError( TMLTask t, TMLActivityElement elt, String message, int type ) { + TMLError error = new TMLError( type ); + error.message = message; + error.task = t; + error.element = elt; + errors.add( error ); + }*/ + + public void addError( String message, int type ) { + TMLCPError error = new TMLCPError( type ); + error.message = message; + errors.add( error ); + } + + public String printSummary() { + String ret = ""; + if( errors.size() == 0 ) { + ret += printWarnings(); + ret += "Syntax checking: successful\n"; + ret += "No error, " + warnings.size() + " warning(s)\n"; + } + else { + ret += printErrors() + printWarnings(); + ret += "Syntax checking: failed\n"; + ret += errors.size() + " error(s), "+ warnings.size() + " warning(s)\n"; + } + return ret; + } + + public String printErrors() { + String ret = "*** ERRORS:"; + for( TMLCPError error: errors ) { + ret += "ERROR: " + error.message; + } + return ret; + } + + public String printWarnings() { + String ret = ""; + for( TMLCPError error: warnings ) { + ret += "ERROR / task " + error.task.getName() + " / element: " + error.element.getName() + ": " + error.message + "\n"; + } + return ret; + } + + public void parsing( String parseCmd, String action) { + TMLExprParser parser; + SimpleNode root; + + // First parsing + TraceManager.addDev("-------- Parsing of " + (parseCmd + " " + action)); + parser = new TMLExprParser(new StringReader(parseCmd + " " + action)); + try { + //System.out.println("\nParsing :" + parseCmd + " " + action); + root = parser.CompilationUnit(); + //root.dump("pref="); + //System.out.println("Parse ok"); + } catch (ParseException e) { + //System.out.println("ParseException --------> Parse error in :" + parseCmd + " " + action); + addError( SYNTAX_ERROR + " in expression " + action, TMLError.ERROR_BEHAVIOR); + return; + } catch (TokenMgrError tke ) { + //System.out.println("TokenMgrError --------> Parse error in :" + parseCmd + " " + action); + addError( SYNTAX_ERROR + " in expression " + action, TMLError.ERROR_BEHAVIOR); + return; + } + + // Second parsing + // We only replace variables values after the "=" sign + if (parseCmd.compareTo("natnumeral") == 0) { + return; + } + + int index = action.indexOf('='); + String modif = action; + + if ((parseCmd.compareTo("assnat") ==0) || (parseCmd.compareTo("assbool") ==0)) { + if (index != -1) { + modif = action.substring(index+1, action.length()); + } + + if (parseCmd.compareTo("assnat") ==0) { + parseCmd = "actionnat"; + } else { + parseCmd = "actionbool"; + } + } + + if (parseCmd.compareTo("natid") == 0) { + parseCmd = "natnumeral"; + } + + /*for(TMLAttribute attr: t.getAttributes()) { + modif = tmlm.putAttributeValueInString(modif, attr); + }*/ + parser = new TMLExprParser(new StringReader(parseCmd + " " + modif)); + try { + //System.out.println("\nParsing :" + parseCmd + " " + modif); + root = parser.CompilationUnit(); + //root.dump("pref="); + //System.out.println("Parse ok"); + } catch (ParseException e) { + //System.out.println("ParseException --------> Parse error in :" + parseCmd + " " + action); + addError( VARIABLE_ERROR + " in expression " + action, TMLError.ERROR_BEHAVIOR); + return; + } catch (TokenMgrError tke ) { + //System.out.println("TokenMgrError --------> Parse error in :" + parseCmd + " " + action); + addError( VARIABLE_ERROR + " in expression " + action, TMLError.ERROR_BEHAVIOR); + return; + } + + // Tree analysis: if the tree contains a variable, then, this variable has not been declared + ArrayList<String> vars = root.getVariables(); + TraceManager.addDev( "PRINTING VARS IN PARSING(): " + vars.toString() ); + for(String s: vars) { + addError( UNDECLARED_VARIABLE + " :" + s + " in expression " + action, TMLError.ERROR_BEHAVIOR); + } + + } +} //End of class diff --git a/src/tmltranslator/tmlcp/TMLCPActivityDiagram.java b/src/tmltranslator/tmlcp/TMLCPActivityDiagram.java index 7690981bd2..0a2398f3ae 100755 --- a/src/tmltranslator/tmlcp/TMLCPActivityDiagram.java +++ b/src/tmltranslator/tmlcp/TMLCPActivityDiagram.java @@ -108,12 +108,12 @@ public class TMLCPActivityDiagram extends TMLElement { public int getSize() { return elements.size();} public TMLCPElement getElementByReference(Object referenceObject) { - for(TMLCPElement elt: elements) { - if (elt.getReferenceObject() == referenceObject) { - return elt; - } - } - return null; + for(TMLCPElement elt: elements) { + if (elt.getReferenceObject() == referenceObject) { + return elt; + } + } + return null; } /*public boolean checkVariableNoType( TMLAttribute _attr ) { @@ -184,7 +184,7 @@ public class TMLCPActivityDiagram extends TMLElement { } public boolean contains(TMLCPElement elt) { - return elements.contains(elt); + return elements.contains(elt); } public TMLCPElement getElementByName(String name) { @@ -213,7 +213,7 @@ public class TMLCPActivityDiagram extends TMLElement { } public TMLCPElement getStartElement() { - return start; + return start; } public void addTMLCPElement(TMLCPElement _elt) { @@ -311,97 +311,116 @@ public class TMLCPActivityDiagram extends TMLElement { int id = 0; TMLCPActivityDiagram diag; - TraceManager.addDev("Splitting AD: " + getName()); + TraceManager.addDev("Splitting AD: " + getName()); // For each junction, we create a new AD ArrayList<TMLCPJunction> junctions = new ArrayList<TMLCPJunction>(); - ArrayList<TMLCPRefAD> refsAD = new ArrayList<TMLCPRefAD>(); - ArrayList<TMLCPElement> toBeRemoved = new ArrayList<TMLCPElement>(); + ArrayList<TMLCPRefAD> refsAD = new ArrayList<TMLCPRefAD>(); + ArrayList<TMLCPElement> toBeRemoved = new ArrayList<TMLCPElement>(); HashMap<TMLCPJunction, TMLCPActivityDiagram> refs = new HashMap<TMLCPJunction, TMLCPActivityDiagram>(); for(TMLCPElement elt: elements) { if (elt instanceof TMLCPJunction) { junctions.add((TMLCPJunction)elt); diag = new TMLCPActivityDiagram(elt.getName() + "_" + id, referenceObject); - TMLCPStart start = new TMLCPStart("StartFrom_" + elt.getName(), elt.getReferenceObject()); - diag.setStartElement(start); - diag.addTMLCPElement(start); + TMLCPStart start = new TMLCPStart("StartFrom_" + elt.getName(), elt.getReferenceObject()); + diag.setStartElement(start); + diag.addTMLCPElement(start); refs.put((TMLCPJunction)elt, diag); - TraceManager.addDev("Adding a new diag named: " + diag.getName()); + TraceManager.addDev("Adding a new diag named: " + diag.getName()); } } - // We replace all junctions by a call to the corresponding ref AD, keeping the same nexts - for(TMLCPJunction junction: junctions) { - TMLCPActivityDiagram toAD = refs.get(junction); - TMLCPRefAD ref = new TMLCPRefAD(toAD, toAD.getName(), junction.getReferenceObject()); - refsAD.add(ref); - elements.remove(junction); - elements.add(ref); - for(TMLCPElement elt: elements) { - elt.replaceNext(junction, ref); - } - ref.setNexts(junction.getNextElements()); - } + // We replace all elements leading to a junction by a call to the corresponding ref AD, keeping the same nexts + for(TMLCPJunction junction: junctions) { + TMLCPActivityDiagram toAD = refs.get(junction); + //TMLCPRefAD ref = new TMLCPRefAD(toAD, toAD.getName(), junction.getReferenceObject()); + //refsAD.add(ref); + elements.remove(junction); + //elements.add(ref); + + // Replacing next to junction by new refs + int index; + int ID = 0; + for(TMLCPElement elt: elements) { + while(((index = elt.getNextElements().indexOf(junction)) != -1)) { + TMLCPRefAD ref = new TMLCPRefAD(toAD, toAD.getName() + "_" + ID, junction.getReferenceObject()); + ID ++; + refsAD.add(ref); + //elements.add(ref); + elt.setNextElementAtIndex(ref, index); + /*TMLCPStop stop = new TMLCPStop(ref.getName() + "__stop_after_ref_" + ID, ref.getReferenceObject()); + elements.add(stop); + ref.addNextElement(stop);*/ + } + //ref.setNexts(junction.getNextElements()); + } + } + + // Removing nexts in new refs, and putting a stop + for(TMLCPRefAD ref: refsAD) { + ref.clearNexts(); + elements.add(ref); + TMLCPStop stop = new TMLCPStop(ref.getName() + "__stop_after_ref", ref.getReferenceObject()); + elements.add(stop); + ref.addNextElement(stop); + } // Moving elements from old AD to split ADs - int cpt = 0; + int cpt = 0; for(TMLCPJunction junction: junctions) { - diag = refs.get(junction); - TMLCPRefAD refAD = refsAD.get(cpt); - cpt++; - - // To be modified-> add elements from RefADs - // Also, avoid to add already met elements + diag = refs.get(junction); + //TMLCPRefAD refAD = refsAD.get(cpt); + //cpt++; + + // To be modified-> add elements from RefADs + // Also, avoid to add already met elements addElementsFromJunction(junction, diag.getStartElement(), diag, refs, toBeRemoved); } - // Removing elements from main diagram - for(TMLCPElement elt: toBeRemoved) { - elements.remove(elt); - } + // Removing elements from main diagram + for(TMLCPElement elt: toBeRemoved) { + elements.remove(elt); + } - // Removing nexts in new refs - for(TMLCPRefAD ref: refsAD) { - ref.clearNexts(); - } + // Returns new elements return refs.values(); } private void addElementsFromJunction(TMLCPElement originInOld, TMLCPElement originInNew, TMLCPActivityDiagram newDiag, HashMap<TMLCPJunction, TMLCPActivityDiagram> refs, ArrayList<TMLCPElement> toBeRemoved) { - if (originInOld.getNextElements() == null) { - return; - } - - for(TMLCPElement elt: originInOld.getNextElements()) { - TraceManager.addDev("Exploring elt (0):" + elt.getName()); - if (elt instanceof TMLCPJunction) { - // Must replace the junction by a ref to an AD - TMLCPActivityDiagram toAD = refs.get((TMLCPJunction)elt); - TMLCPRefAD ref = new TMLCPRefAD(toAD, toAD.getName(), elt.getReferenceObject()); - newDiag.addTMLCPElement(ref); - originInNew.setNextElement(ref); - } else { - TraceManager.addDev("Exploring elt (1):" + elt.getName()); - if (originInOld != originInNew) { - originInNew.addNextElement(elt); - } - if (!newDiag.contains(elt)) { - newDiag.addTMLCPElement(elt); - toBeRemoved.add(elt); - addElementsFromJunction(elt, elt, newDiag, refs, toBeRemoved); - } - } - } + if (originInOld.getNextElements() == null) { + return; + } + + for(TMLCPElement elt: originInOld.getNextElements()) { + TraceManager.addDev("Exploring elt (0):" + elt.getName()); + if (elt instanceof TMLCPJunction) { + // Must replace the junction by a ref to an AD + TMLCPActivityDiagram toAD = refs.get((TMLCPJunction)elt); + TMLCPRefAD ref = new TMLCPRefAD(toAD, toAD.getName(), elt.getReferenceObject()); + newDiag.addTMLCPElement(ref); + originInNew.setNextElement(ref); + } else { + TraceManager.addDev("Exploring elt (1):" + elt.getName()); + if (originInOld != originInNew) { + originInNew.addNextElement(elt); + } + if (!newDiag.contains(elt)) { + newDiag.addTMLCPElement(elt); + toBeRemoved.add(elt); + addElementsFromJunction(elt, elt, newDiag, refs, toBeRemoved); + } + } + } } public String toString() { - String s = "*** Activity diagram " + getName() + "\n"; - for(TMLCPElement elt: elements) { - s += elt.toString(); - } - return s + "\n"; + String s = "*** Activity diagram " + getName() + "\n"; + for(TMLCPElement elt: elements) { + s += elt.toString(); + } + return s + "\n"; } } //End of class diff --git a/src/tmltranslator/tmlcp/TMLCPElement.java b/src/tmltranslator/tmlcp/TMLCPElement.java index ee2bd5d157..e09b613c2e 100755 --- a/src/tmltranslator/tmlcp/TMLCPElement.java +++ b/src/tmltranslator/tmlcp/TMLCPElement.java @@ -78,6 +78,10 @@ public abstract class TMLCPElement extends TMLElement { nexts.clear(); addNextElement(_elt); } + + public void setNextElementAtIndex(TMLCPElement _elt, int _index) { + nexts.set(_index, _elt); + } public void clearNexts() { nexts.clear(); @@ -99,6 +103,10 @@ public abstract class TMLCPElement extends TMLElement { } + + + + public String toShortString() { return getClass().getCanonicalName() + " " + getName() + "\n"; } diff --git a/src/ui/GTMLModeling.java b/src/ui/GTMLModeling.java index 0754a2fbb6..f02b4ab809 100755 --- a/src/ui/GTMLModeling.java +++ b/src/ui/GTMLModeling.java @@ -1928,23 +1928,23 @@ public class GTMLModeling { TGComponent tgc; if( syntax.hasErrors() > 0 ) { - for( TMLCPError error: syntax.getErrors() ) { - if( error.type == TMLCPError.ERROR_STRUCTURE ) { - type = CheckingError.STRUCTURE_ERROR; - } - else { - type = CheckingError.BEHAVIOR_ERROR; - } - ce = new CheckingError( type, error.message ); - tgc = listE.getTG( error.element ); - if ( tgc != null ) { - ce.setTDiagramPanel( tgc.getTDiagramPanel() ); - ce.setTGComponent( tgc ); - } - ce.setTMLTask( error.task ); - checkingErrors.add( ce ); - } - } + for( TMLCPError error: syntax.getErrors() ) { + if( error.type == TMLCPError.ERROR_STRUCTURE ) { + type = CheckingError.STRUCTURE_ERROR; + } + else { + type = CheckingError.BEHAVIOR_ERROR; + } + ce = new CheckingError( type, error.message ); + tgc = listE.getTG( error.element ); + if ( tgc != null ) { + ce.setTDiagramPanel( tgc.getTDiagramPanel() ); + ce.setTGComponent( tgc ); + } + ce.setTMLTask( error.task ); + checkingErrors.add( ce ); + } + } /*makeCPDataStructure(); if (!makeTMLModeling()) { @@ -2201,13 +2201,14 @@ public class GTMLModeling { //TraceManager.addDev( "PANEL number: " + panelCounter + " " + panelList.get( panelCounter ) ); } - TraceManager.addDev( "Before correcting references. The list of ADs contains: " + tmlcp.getCPActivityDiagrams().toString() ); + TraceManager.addDev( "Before correcting references. The list of ADs contains: " + tmlcp.getCPActivityDiagrams().toString() ); tmlcp.correctReferences(); //Update references to the right activity and sequence diagrams - TraceManager.addDev( "After correcting references and before splitting ADs. The list of ADs contains: " + tmlcp.getCPActivityDiagrams().toString() ); + TraceManager.addDev( "After correcting references and before splitting ADs. The list of ADs contains: " + tmlcp.getCPActivityDiagrams().toString() ); //tmlcp.generateNexts(); // Add nexts elements to CPElements //tmlcp.removeADConnectors(); // Remove connectors since nexts have been filled tmlcp.splitADs(); // Splitting ADs so as to remove junctions -> new ADs are introduced for each junction inside an AD - TraceManager.addDev( "After splitting ADs. The list of ADs contains: " + tmlcp.getCPActivityDiagrams().toString() ); + TraceManager.addDev( "After splitting ADs. OriginalCP:" + tmlcp.toString() ); + TraceManager.addDev( "After splitting ADs. The list of ADs contains: " + tmlcp.getCPActivityDiagrams().toString() ); for( TMLCPSequenceDiagram seqDiag: tmlcp.getCPSequenceDiagrams() ) { TraceManager.addDev( "**********" ); @@ -2390,8 +2391,8 @@ public class GTMLModeling { LinkedList elemList = panel.getComponentList(); //TraceManager.addDev("Adding to the data structure the elements of: " + panel.getName() ); //order messages according to the inverse of Y coordinate - int j; - TGComponent elem; + int j; + TGComponent elem; for(j = 0; j < elemList.size(); j++ ) { elem = (TGComponent) elemList.get(j); //include the package name of the class to avoid confusion with the graphical TMLSDInstance @@ -2470,11 +2471,11 @@ public class GTMLModeling { } SD.addInstance( instance ); } - + } //End of for over internal elements - for(j = 0; j < elemList.size(); j++ ) { - elem = (TGComponent) elemList.get(j); - if( elem instanceof TGConnectorMessageTMLSD ) { + for(j = 0; j < elemList.size(); j++ ) { + elem = (TGComponent) elemList.get(j); + if( elem instanceof TGConnectorMessageTMLSD ) { TraceManager.addDev("Analyzing message:" + elem); connector = (TGConnectorMessageTMLSD) elemList.get(j); String sender = connector.getTGConnectingPointP1().getFather().getName(); @@ -2494,8 +2495,8 @@ public class GTMLModeling { } } } - - } + + } return SD; }//End else name does not exist yet } //End of method createSequenceDiagramDataStructure diff --git a/src/ui/avatarinteractivesimulation/AvatarSpecificationSimulationSDPanel.java b/src/ui/avatarinteractivesimulation/AvatarSpecificationSimulationSDPanel.java index f78ec51442..f7ac4f470b 100644 --- a/src/ui/avatarinteractivesimulation/AvatarSpecificationSimulationSDPanel.java +++ b/src/ui/avatarinteractivesimulation/AvatarSpecificationSimulationSDPanel.java @@ -114,9 +114,16 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous private Vector<Point> points; private Vector<AvatarSimulationTransaction> transactionsOfPoints; + // Saving states + private class StateYCd { + public String stateName; + public int y; + } + + private HashMap<AvatarSimulationBlock, ArrayList<StateYCd>> statesMap = new HashMap<AvatarSimulationBlock, ArrayList<StateYCd>>(); + // Graphics private Graphics2D lastGraphics; - private boolean trace = true; @@ -166,6 +173,8 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous return; } + statesMap.clear(); + //TraceManager.addDev("Painting components"); lastGraphics = (Graphics2D)g; super.paintComponent(g); @@ -290,6 +299,17 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous if (ast.executedElement instanceof AvatarState) { if ((showHiddenStates) || (!((AvatarState)ast.executedElement).isHidden())) { newCurrentY = drawState(g, ast, (AvatarState)(ast.executedElement), xOfBlock, currentY); + ArrayList<StateYCd> states = null; + if (statesMap.containsKey(ast.asb)) { + states = statesMap.get(ast.asb); + } else { + states = new ArrayList<StateYCd>(); + statesMap.put(ast.asb, states); + } + StateYCd ycd = new StateYCd(); + ycd.stateName = ((AvatarState)(ast.executedElement)).getName(); + ycd.y = currentY + verticalLink; + states.add(ycd); } } else if (ast.executedElement instanceof AvatarTransition) { newCurrentY = drawTransition(g, (AvatarTransition)(ast.executedElement), ast, xOfBlock, currentY); @@ -700,6 +720,27 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous drawInfo = false; } + private String getNameOfState(AvatarSimulationBlock block, int y) { + if (!(statesMap.containsKey(block))) { + return null; + } + + String name = null; + ArrayList<StateYCd> ycd = statesMap.get(block); + if (ycd == null) { + return name; + } + + for(StateYCd st: ycd) { + if (st.y > y) { + return name; + } + name = st.stateName; + } + + return name; + } + private void drawInfo(Graphics g) { String timeValue = "@" + clockValueMouse; Color c = g.getColor(); @@ -709,7 +750,7 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous g.drawString(timeValue, maxX-spaceAtEnd + 1, yMouse+g.getFontMetrics().getHeight()/2); - TraceManager.addDev("yMouse=" + yMouse); + //TraceManager.addDev("yMouse=" + yMouse); /*if (minIdValueMouse == maxIdValueMouse) { g.drawString("ID: " + minIdValueMouse, 10, yMouse+(g.getFontMetrics().getHeight()/2)+12); @@ -722,6 +763,9 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous Vector<AvatarSimulationBlock> blocks = ass.getSelectedSimulationBlocks(); int x = spaceAtEnd; + Font normal = g.getFont(); + Font it = normal.deriveFont(Font.ITALIC); + for(AvatarSimulationBlock block: blocks) { name = block.getBlock().getName(); w = g.getFontMetrics().stringWidth(name); @@ -729,7 +773,18 @@ public class AvatarSpecificationSimulationSDPanel extends JPanel implements Mous // Write the name of the current state - + name = getNameOfState(block, yMouse); + if (name == null) { + name = "start state"; + } else { + name = "state: " + name; + } + + g.setFont(it); + w = g.getFontMetrics().stringWidth(name); + g.drawString(name, x + ((spaceBetweenLifeLines-w)/2), yMouse + (6 * spaceVerticalText)); + g.setFont(normal); + // Add the space between lifelines x += spaceBetweenLifeLines; } -- GitLab