/** * Returns the {@linkplain Lifeline} object made from the current line}. * * @return the {@linkplain Lifeline} object made from the current line * @throws SyntaxError if the next object declaration is not well-formed */ public Lifeline nextObject() throws SyntaxError { if (section == 1) { throw new IllegalStateException("reading objects has already been finished"); } if (currentLine() == null) { throw new IllegalStateException("nothing to read"); } if (currentLine().indexOf(':') == -1) { throw new SyntaxError(this, "not a valid object declaration - ':' missing"); } ArrayList<Region> regions = new ArrayList<Region>(); String[] parts = grep.parse("(\\/?.+?):([^\\[\\]]+?)\\s*(\\[.*?\\]|)\\s*(\".*\"|)", currentLine(), regions); 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); } setCurrentLine(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 process = flags.indexOf('p') >= 0; boolean hasThread = flags.indexOf('t') >= 0; boolean autoDestroy = flags.indexOf('x') >= 0; boolean external = flags.indexOf('e') >= 0; boolean saveSpace = reuseSpace && flags.indexOf('f') == -1; 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, false, false, autoDestroy, external, saveSpace, 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, process, hasThread, autoDestroy, external, false, diagram); } lifeline.setNameRegion(regions.get(0)); 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; }