All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javacc-7.0.4.classes.templates.SimpleNode.template Maven / Gradle / Ivy

#if SUPPORT_CLASS_VISIBILITY_PUBLIC
public
#fi
#if NODE_EXTENDS
class SimpleNode extends ${NODE_EXTENDS} implements Node {
#else
class SimpleNode implements Node {
#fi

  protected Node parent;
  protected Node[] children;
  protected int id;
  protected Object value;
  protected ${PARSER_NAME} parser;
#if TRACK_TOKENS
  protected Token firstToken;
  protected Token lastToken;
#fi

  public SimpleNode(int i) {
    id = i;
  }

  public SimpleNode(${PARSER_NAME} p, int i) {
    this(i);
    parser = p;
  }

#if NODE_FACTORY
  public static Node jjtCreate(int id) {
    return new SimpleNode(id);
  }

  public static Node jjtCreate(${PARSER_NAME} p, int id) {
    return new SimpleNode(p, id);
  }

#fi
  public void jjtOpen() {
  }

  public void jjtClose() {
  }

  public void jjtSetParent(Node n) { parent = n; }
  public Node jjtGetParent() { return parent; }

  public void jjtAddChild(Node n, int i) {
    if (children == null) {
      children = new Node[i + 1];
    } else if (i >= children.length) {
      Node c[] = new Node[i + 1];
      System.arraycopy(children, 0, c, 0, children.length);
      children = c;
    }
    children[i] = n;
  }

  public Node jjtGetChild(int i) {
    return children[i];
  }

  public int jjtGetNumChildren() {
    return (children == null) ? 0 : children.length;
  }

  public void jjtSetValue(Object value) { this.value = value; }
  public Object jjtGetValue() { return value; }

#if TRACK_TOKENS
  public Token jjtGetFirstToken() { return firstToken; }
  public void jjtSetFirstToken(Token token) { this.firstToken = token; }
  public Token jjtGetLastToken() { return lastToken; }
  public void jjtSetLastToken(Token token) { this.lastToken = token; }

#fi
#if VISITOR
  /** Accept the visitor. **/
  public ${VISITOR_RETURN_TYPE} jjtAccept(${PARSER_NAME}Visitor visitor, ${VISITOR_DATA_TYPE:-Object} data)
#if VISITOR_EXCEPTION
     throws ${VISITOR_EXCEPTION}
#fi
{
#if VISITOR_RETURN_TYPE_VOID
    visitor.visit(this, data);
#else
    return visitor.visit(this, data);
#fi
  }

  /** Accept the visitor. **/
  public Object childrenAccept(${PARSER_NAME}Visitor visitor, ${VISITOR_DATA_TYPE:-Object} data)
#if VISITOR_EXCEPTION
     throws ${VISITOR_EXCEPTION}
#fi
{
    if (children != null) {
      for (int i = 0; i < children.length; ++i) {
        children[i].jjtAccept(visitor, data);
      }
    }
    return data;
  }

#fi
  /* You can override these two methods in subclasses of SimpleNode to
     customize the way the node appears when the tree is dumped.  If
     your output uses more than one line you should override
     toString(String), otherwise overriding toString() is probably all
     you need to do. */

  public String toString() {
    return ${PARSER_NAME}TreeConstants.jjtNodeName[id];
  }
  public String toString(String prefix) { return prefix + toString(); }

  /* Override this method if you want to customize how the node dumps
     out its children. */

  public void dump(String prefix) {
    System.out.println(toString(prefix));
    if (children != null) {
      for (int i = 0; i < children.length; ++i) {
        SimpleNode n = (SimpleNode)children[i];
        if (n != null) {
          n.dump(prefix + " ");
        }
      }
    }
  }

  public int getId() {
    return id;
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy