Search in sources :

Example 6 with SyntaxError

use of net.sf.sdedit.error.SyntaxError in project abstools by abstools.

the class TextHandler method getEventAssociation.

/**
 * If the current line specifies an association of a note to the current
 * vertical position of a lifeline, this method returns a pair consisting of
 * the lifeline and the note number.
 *
 * @return a pair of a lifeline and a note number, if the current line
 *         specifies and association between the note and the lifeline,
 *         otherwise <tt>null</tt>
 */
public Pair<Lifeline, Integer> getEventAssociation() throws SyntaxError {
    if (section == 0) {
        throw new IllegalStateException("not all objects have been read");
    }
    if (currentLine == null) {
        throw new IllegalStateException("nothing to read");
    }
    String[] parts = Grep.parse("\\((\\d+)\\)\\s*(\\w+)", currentLine);
    if (parts == null) {
        return null;
    }
    int number = Integer.parseInt(parts[0]);
    String obj = parts[1];
    Lifeline line = diagram.getLifeline(obj);
    if (line == null) {
        throw new SyntaxError(this, obj + " does not exist");
    }
    return new Pair<Lifeline, Integer>(line, number);
}
Also used : SyntaxError(net.sf.sdedit.error.SyntaxError) Lifeline(net.sf.sdedit.diagram.Lifeline) Pair(net.sf.sdedit.util.Pair)

Example 7 with SyntaxError

use of net.sf.sdedit.error.SyntaxError in project abstools by abstools.

the class TextHandler method getNote.

/**
 * If there is a note specified at the current line and the subsequent
 * lines, a {@linkplain Note} representation is returned, otherwise
 * <tt>null</tt>
 *
 * @return a note, if one is specified at the current position in text,
 *         otherwise <tt>null</tt>
 */
public Note getNote() throws SyntaxError {
    if (section == 0) {
        throw new IllegalStateException("not all objects have been read");
    }
    if (currentLine == null) {
        throw new IllegalStateException("nothing to read");
    }
    String[] parts = Grep.parse("\\s*(\\*|\\+)(\\d+)\\s*(.+)", currentLine);
    if (parts == null) {
        return null;
    }
    boolean consuming = parts[0].equals("+");
    int number = -1;
    try {
        number = Integer.parseInt(parts[1]);
    } catch (NumberFormatException nfe) {
    /* empty */
    }
    if (number < 0) {
        throw new SyntaxError(this, "bad note number: " + parts[1]);
    }
    String obj = parts[2];
    Lifeline line = diagram.getLifeline(obj);
    if (line == null) {
        throw new SyntaxError(this, obj + " does not exist");
    }
    int oldBegin = lineBegin;
    int oldEnd = lineEnd;
    line = line.getRightmost();
    List<String> desc = new LinkedList<String>();
    boolean more;
    do {
        if (!advance(false)) {
            lineBegin = oldBegin;
            lineEnd = oldEnd;
            throw new SyntaxError(this, "The note is not closed.");
        }
        more = !currentLine.trim().equals(parts[0] + parts[1]);
    } while (more && desc.add(currentLine));
    if (desc.size() == 0) {
        lineBegin = oldBegin;
        lineEnd = oldEnd;
        throw new SyntaxError(this, "The note is empty.");
    }
    String[] noteText = desc.toArray(new String[0]);
    URI link = null;
    if (noteText.length == 1) {
        String linkString = noteText[0].trim();
        if (linkString.startsWith("link:")) {
            try {
                linkString = linkString.substring(5).trim();
                link = new URI(linkString);
                if (link.getPath() == null) {
                    throw new SyntaxError(this, "Empty path in URI: " + linkString);
                }
                noteText[0] = link.getPath();
            } catch (URISyntaxException e) {
                throw new SyntaxError(this, "Bad URI syntax: " + e.getMessage());
            }
        }
    }
    Note note = new Note(line, number, noteText, consuming);
    note.setLink(link);
    return note;
}
Also used : Lifeline(net.sf.sdedit.diagram.Lifeline) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) LinkedList(java.util.LinkedList) SyntaxError(net.sf.sdedit.error.SyntaxError) Note(net.sf.sdedit.drawable.Note)

Aggregations

SyntaxError (net.sf.sdedit.error.SyntaxError)7 Lifeline (net.sf.sdedit.diagram.Lifeline)3 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Configuration (net.sf.sdedit.config.Configuration)1 PrintConfiguration (net.sf.sdedit.config.PrintConfiguration)1 MessageData (net.sf.sdedit.diagram.MessageData)1 Fragment (net.sf.sdedit.drawable.Fragment)1 Note (net.sf.sdedit.drawable.Note)1 SemanticError (net.sf.sdedit.error.SemanticError)1 BroadcastMessage (net.sf.sdedit.message.BroadcastMessage)1 ForwardMessage (net.sf.sdedit.message.ForwardMessage)1 MultipageExporter (net.sf.sdedit.multipage.MultipageExporter)1 Pair (net.sf.sdedit.util.Pair)1