Пример #1
0
  /**
   * Executes the commands waiting in the command queue, then inserts the proper location
   * information into the current NodeToken.
   *
   * <p>If there are any special tokens preceding this token, they will be given the current
   * location information. The token will follow on the next line, at the proper indentation level.
   * If this is not the behavior you want from special tokens, feel free to modify this method.
   */
  public void visit(NodeToken n) {
    for (Enumeration<FormatCommand> e = cmdQueue.elements(); e.hasMoreElements(); ) {
      FormatCommand cmd = e.nextElement();
      switch (cmd.getCommand()) {
        case FormatCommand.FORCE:
          curLine += cmd.getNumCommands();
          curColumn = curIndent + 1;
          break;
        case FormatCommand.INDENT:
          curIndent += indentAmt * cmd.getNumCommands();
          break;
        case FormatCommand.OUTDENT:
          if (curIndent >= indentAmt) curIndent -= indentAmt * cmd.getNumCommands();
          break;
        case FormatCommand.SPACE:
          curColumn += cmd.getNumCommands();
          break;
        default:
          throw new TreeFormatterException("Invalid value in command queue.");
      }
    }

    cmdQueue.removeAllElements();

    //
    // Handle all special tokens preceding this NodeToken
    //
    if (n.numSpecials() > 0)
      for (Enumeration<NodeToken> e = n.specialTokens.elements(); e.hasMoreElements(); ) {
        NodeToken special = e.nextElement();

        //
        // -Place the token.
        // -Move cursor to next line after the special token.
        // -Don't update curColumn--want to keep current indent level.
        //
        placeToken(special, curLine, curColumn);
        curLine = special.endLine + 1;
      }

    placeToken(n, curLine, curColumn);
    curLine = n.endLine;
    curColumn = n.endColumn;
  }
Пример #2
0
 protected void processList(NodeListInterface n, FormatCommand cmd) {
   for (Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
     e.nextElement().accept(this);
     if (cmd != null && e.hasMoreElements()) cmdQueue.addElement(cmd);
   }
 }
Пример #3
0
 /**
  * Use this method to add FormatCommands to the command queue to be executed when the next token
  * in the tree is visited.
  */
 protected void add(FormatCommand cmd) {
   cmdQueue.addElement(cmd);
 }