Skip to content
Snippets Groups Projects
Commit 96cdc6dc authored by Minh Hiep Pham's avatar Minh Hiep Pham :speech_balloon:
Browse files

Update methods for checking valid port names 2

parent f7984fc4
No related branches found
No related tags found
1 merge request!101checking the valid port names
...@@ -45,6 +45,9 @@ import compiler.tmlparser.TMLExprParser; ...@@ -45,6 +45,9 @@ import compiler.tmlparser.TMLExprParser;
import compiler.tmlparser.TokenMgrError; import compiler.tmlparser.TokenMgrError;
import myutil.Conversion; import myutil.Conversion;
import myutil.TraceManager; import myutil.TraceManager;
import ui.TAttribute;
import ui.tmlcompd.TMLCPrimitiveComponent;
import ui.tmlcompd.TMLCPrimitivePort;
import java.io.StringReader; import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -387,6 +390,18 @@ public class TMLSyntaxChecking { ...@@ -387,6 +390,18 @@ public class TMLSyntaxChecking {
} }
} }
// Checking valid port names
// Minh Hiep
if (t.getReferenceObject() instanceof TMLCPrimitiveComponent) {
TMLCPrimitiveComponent tmlcpc = (TMLCPrimitiveComponent) t.getReferenceObject();
for (TMLCPrimitivePort tmlcpp : tmlcpc.getAllInternalPrimitivePorts()) {
String s = tmlcpp.getPortName();
if(!TAttribute.isAValidId(s, false, true, false)) {
addError(t, null, WRONG_VARIABLE_IDENTIFIER + ": invalid port name (" + s + ")", TMLError.ERROR_STRUCTURE);
}
}
}
int n = tactivity.nElements(); int n = tactivity.nElements();
//TraceManager.addDev("Task" + t.getName()); //TraceManager.addDev("Task" + t.getName());
......
...@@ -73,6 +73,8 @@ import ui.interactivesimulation.JFrameSimulationSDPanel; ...@@ -73,6 +73,8 @@ import ui.interactivesimulation.JFrameSimulationSDPanel;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector; import java.util.Vector;
/** /**
...@@ -159,6 +161,7 @@ public abstract class TMLCPrimitivePort extends TGCScalableWithInternalComponent ...@@ -159,6 +161,7 @@ public abstract class TMLCPrimitivePort extends TGCScalableWithInternalComponent
public int verification; public int verification;
public String oldName;
public TMLCPrimitivePort(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { public TMLCPrimitivePort(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) {
super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp);
...@@ -610,7 +613,7 @@ public abstract class TMLCPrimitivePort extends TGCScalableWithInternalComponent ...@@ -610,7 +613,7 @@ public abstract class TMLCPrimitivePort extends TGCScalableWithInternalComponent
TraceManager.addDev( "The Data flow type is: " + dataFlowType ); TraceManager.addDev( "The Data flow type is: " + dataFlowType );
TraceManager.addDev( "The Associated event is: " + associatedEvent ); TraceManager.addDev( "The Associated event is: " + associatedEvent );
String oldName = getPortName(); oldName = getPortName();
//TraceManager.addDev("old port name : " + oldName); //TraceManager.addDev("old port name : " + oldName);
if (jda.hasNewData()) { if (jda.hasNewData()) {
...@@ -637,16 +640,16 @@ public abstract class TMLCPrimitivePort extends TGCScalableWithInternalComponent ...@@ -637,16 +640,16 @@ public abstract class TMLCPrimitivePort extends TGCScalableWithInternalComponent
if (!TAttribute.isAValidId(s, false, true, false)) { if (!TAttribute.isAValidId(s, false, true, false)) {
JOptionPane.showMessageDialog(frame, JOptionPane.showMessageDialog(frame,
"Could not change the name of the port: the new name is not a valid name", "Could not change the name of the port: the new name (" + s + ") is not a valid name",
"Error", "Error",
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
return false; return false;
} }
if (oldName.compareTo(s) != 0) { if (oldName.compareTo(s) != 0) {
if (((TMLComponentTaskDiagramPanel) (tdp)).namePrimitivePortInUse(this, s)) { if (((TMLComponentTaskDiagramPanel) tdp).namePrimitivePortInUse(this, s)) {
JOptionPane.showMessageDialog(frame, JOptionPane.showMessageDialog(frame,
"Error: the name is already in use", "Error: the name (" + s + ") is already in use",
"Name modification", "Name modification",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
return false; return false;
...@@ -841,7 +844,24 @@ public abstract class TMLCPrimitivePort extends TGCScalableWithInternalComponent ...@@ -841,7 +844,24 @@ public abstract class TMLCPrimitivePort extends TGCScalableWithInternalComponent
} }
if (elt.getTagName().equals("Prop")) { if (elt.getTagName().equals("Prop")) {
commName = elt.getAttribute("commName"); // checking the valid port name
oldName = getPortName();
String s = elt.getAttribute("commName");
//TraceManager.addDev("port name : " + s);
if ((s != null) && (s.length() > 0)) {
// Check whether this name is already in use, or not
if (!TAttribute.isAValidId(s, false, false, false)) {
JOptionPane.showMessageDialog(null,
"Could not change the name of the port: the new name (" + s + ") is not a valid name",
"Error : " + s,
JOptionPane.INFORMATION_MESSAGE);
setPortName(s);
makeValue();
}
commName = s;
}
try { try {
// //
typep = Integer.decode(elt.getAttribute("commType")).intValue(); typep = Integer.decode(elt.getAttribute("commType")).intValue();
...@@ -1183,7 +1203,4 @@ public abstract class TMLCPrimitivePort extends TGCScalableWithInternalComponent ...@@ -1183,7 +1203,4 @@ public abstract class TMLCPrimitivePort extends TGCScalableWithInternalComponent
typePort = 2; typePort = 2;
return typePort; return typePort;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment