use of net.sf.sdedit.error.SyntaxError in project abstools by abstools.
the class FragmentManager method closeRecentFragment.
private void closeRecentFragment() throws SyntaxError {
if (openFragments.isEmpty()) {
throw new SyntaxError(diagram.getDataProvider(), "There is no open comment");
}
Fragment comment = openFragments.removeLast();
closingFragments.addLast(comment);
}
use of net.sf.sdedit.error.SyntaxError in project abstools by abstools.
the class TextHandler method nextMessage.
/**
* Returns the {@linkplain MessageData} object made from the current line.
*
* @return the {@linkplain MessageData} object made from the current line
* @throws SyntaxError
* if the next message cannot be parsed
*/
public MessageData nextMessage() throws SyntaxError {
if (section == 0) {
throw new IllegalStateException("not all objects have been read");
}
if (currentLine == null) {
throw new IllegalStateException("nothing to read");
}
MessageData data;
try {
data = new TextBasedMessageData(currentLine);
} catch (SyntaxError e) {
e.setProvider(this);
throw e;
}
currentLine = null;
return data;
}
use of net.sf.sdedit.error.SyntaxError in project abstools by abstools.
the class TextHandler method nextObjectIntern.
private Lifeline nextObjectIntern() throws SyntaxError {
if (currentLine == null) {
throw new IllegalStateException("nothing to read");
}
if (currentLine.indexOf(':') == -1) {
throw new SyntaxError(this, "not a valid object declaration - ':' missing");
}
String[] parts = Grep.parse("(\\/?.+?):([^\\[\\]]+?)\\s*(\\[.*?\\]|)\\s*(\".*\"|)", currentLine);
if (parts == null || parts.length != 4) {
String msg;
if (currentLine.indexOf('.') >= 0) {
msg = "not a valid object declaration, perhaps you forgot to " + "enter an empty line before the message section";
} else {
msg = "not a valid object declaration";
}
throw new SyntaxError(this, msg);
}
currentLine = null;
String name = parts[0];
String type = parts[1];
String flags = parts[2];
String label = parts[3];
if (!label.equals("")) {
label = label.substring(1, label.length() - 1);
}
boolean anon = flags.indexOf('a') >= 0;
boolean role = flags.indexOf('r') >= 0;
boolean active = flags.indexOf('v') >= 0;
boolean process = flags.indexOf('p') >= 0;
boolean hasThread = flags.indexOf('t') >= 0;
boolean autoDestroy = flags.indexOf('x') >= 0;
boolean external = flags.indexOf('e') >= 0;
Lifeline lifeline;
if (external && !process) {
throw new SyntaxError(this, "only processes can be declared external");
}
if (name.startsWith("/")) {
if (type.equals("Actor") || process) {
throw new SyntaxError(this, "processes and actors must be visible");
}
if (hasThread) {
throw new SyntaxError(this, "invisible objects cannot have their own thread");
}
lifeline = new Lifeline(name.substring(1), type, label, false, anon, role, active, false, false, autoDestroy, external, diagram);
} else {
if (type.equals("Actor")) {
if (anon) {
throw new SyntaxError(this, "actors cannot be anonymous");
}
}
if ((type.equals("Actor") || process) && hasThread) {
throw new SyntaxError(this, "actors cannot have their own thread");
}
if ((type.equals("Actor") || process) && autoDestroy) {
throw new SyntaxError(this, "actors cannot be (automatically) destroyed");
}
lifeline = new Lifeline(parts[0], parts[1], label, true, anon, role, active, process, hasThread, autoDestroy, external, diagram);
}
int cmt = rawLine.indexOf("#!");
if (cmt >= 0 && cmt + 2 < rawLine.length() - 1) {
String annotation = rawLine.substring(cmt + 2).trim();
annotations.put(lifeline, annotation);
}
return lifeline;
}
use of net.sf.sdedit.error.SyntaxError in project abstools by abstools.
the class PrintDialog method reinitialize.
private void reinitialize() {
String source = ui.getCode();
Configuration configuration = ui.getConfiguration().getDataObject();
exporter = new MultipageExporter(printerProperties.getDataObject(), source, configuration);
try {
exporter.init();
} catch (RuntimeException re) {
throw re;
} catch (SemanticError se) {
/* ignored */
} catch (SyntaxError se) {
/* ignored */
}
int scale = (int) (100 * exporter.getScale());
scaleLabel.setText("Zoom factor: " + scale + " %");
preview.setViewportView(exporter);
}
use of net.sf.sdedit.error.SyntaxError in project abstools by abstools.
the class Diagram method readNextMessage.
private void readNextMessage() throws SyntaxError, SemanticError {
MessageData data = provider.nextMessage();
noteManager.closeNote(data.getCaller());
String[] callees = data.getCallees();
if (callees.length == 1) {
throw new SyntaxError(provider, "A broadcast message must have at least two receivers");
}
if (callees.length >= 2) {
if (data.isSpawnMessage()) {
throw new SyntaxError(provider, "Broadcast messages are spawning by default");
}
Set<String> calleeSet = new HashSet<String>();
Lifeline[] allButLast = new Lifeline[callees.length - 1];
for (int i = 0; i < callees.length; i++) {
String callee = callees[i];
if (callee.length() == 0) {
throw new SyntaxError(provider, "Malformed broadcast message");
}
if (!calleeSet.add(callee)) {
throw new SyntaxError(provider, "Duplicate receiver: " + callee);
}
if (callee.equals(data.getCaller())) {
throw new SyntaxError(provider, "The sender " + callee + " cannot be a " + "receiver of the broadcast message");
}
noteManager.closeNote(callee);
MessageData part = new MessageData();
// TODO mnemonics
part.setCaller(data.getCaller());
part.setCallee(callee);
part.setLevel(data.getLevel());
part.setThread(data.getThread());
if (getLifeline(data.getCaller()) != null) {
if (!getLifeline(data.getCaller()).isAlwaysActive()) {
part.setSpawnMessage(true);
}
}
part.setReturnsInstantly(data.returnsInstantly());
if (i == 0) {
part.setNoteNumber(data.getNoteNumber());
part.setMessage(data.getMessage());
part.setBroadcastType(BroadcastMessage.FIRST);
} else if (i == callees.length - 1) {
part.setBroadcastType(BroadcastMessage.LAST);
} else {
part.setBroadcastType(BroadcastMessage.OTHER);
}
BroadcastMessage msg = (BroadcastMessage) processor.processMessage(part);
if (i < callees.length - 1) {
allButLast[i] = msg.getCallee();
} else {
msg.setOtherCallees(allButLast);
}
processor.execute(msg);
}
} else {
noteManager.closeNote(data.getCallee());
ForwardMessage msg = processor.processMessage(data);
processor.execute(msg);
}
fragmentManager.clearLabels();
}
Aggregations