SimpleNode.java :  » Code-Analyzer » beautyJ » de » gulden » util » javasource » jjt » Java Open Source

Java Open Source » Code Analyzer » beautyJ 
beautyJ » de » gulden » util » javasource » jjt » SimpleNode.java
/* Generated By:JJTree: Do not edit this line. SimpleNode.java */

package de.gulden.util.javasource.jjt;

public class SimpleNode implements Node {
  protected Node parent;
  protected Node[] children;
  protected int id;
  protected Parser parser;

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

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

  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;
  }

  /* 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 ParserTreeConstants.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 + " ");
  }
      }
    }
  }


  /*** added by Jens *********************************************************/

  private final static Node[] EMPTY=new Node[0];
  
  protected String value;
  protected Token[] tokenRange=new Token[2];
  protected TextImage textImage;
  protected String source;

  public int getId()
  {
    return id;
  }
  
  /**
   * Get first child with id.
   */
  public Node getChild(int id)
  {
    if (children!=null)
      {
      for (int i=0;i<children.length;i++)
      {
        if (children[i].getId()==id)
        {
          return children[i];
        }
      }
    }
    return null;
  }
  
  public boolean hasChild(int id)
  {
    return (getChild(id)!=null);
  }
  
  public Node[] getChildren(int id)
  {
    if (children!=null)
    {
      java.util.Vector v=new java.util.Vector(5);
      for (int i=0;i<children.length;i++)
      {
        if (children[i].getId()==id)
        {
          v.addElement(children[i]);
        }
      }
      Node[] n=new Node[v.size()];
      v.copyInto(n);
      return n;
    }
    else
    {
      return EMPTY;
    }
  }
  
  public Node[] getAllChildren()
  {
    if (children!=null)
    {
      return children;
    }
    else
    {
      return EMPTY;
    }
  }
  
  public String getValue()
  {
    return value;
  }
  
  public void setValue(String v)
  {
//System.out.print(v+" ");    
    value=v;
  }
  
  public String getName()
  {
    Node node=getChild(ParserTreeConstants.JJT_NAME);
    if (node!=null)
    {
      return node.retrieveName();
    }
    else
    {
      return null;
    }
  }
  
  public String retrieveName()
  {
    String name;
    int num=jjtGetNumChildren();
    if (num==1) // optimization: single child node _IDENTIFIER
    {
      Node n=jjtGetChild(0);
      name=n.getValue();      
    }
    else // general case: name identifiers joined by dots
    {
      StringBuffer sb=new StringBuffer();
      for (int i=0;i<num;i+=2)
      {
        //Node child=node.jjtGetChild(i).getValue();
        String n=jjtGetChild(i).getValue();
        sb.append(n);
        if (i+1<num)
        {
          // next one must be _DOT
          sb.append(".");
        }
      }
      name=sb.toString();
    }
    return name;
  }
  
  public void setStartToken(Token t)
  {
    tokenRange[0]=t;
  }  
  
  public void setEndToken(Token t)
  {
    tokenRange[1]=t;
  }
  
  public Token getStartToken()
  {
    return tokenRange[0];
  }
  
  public Token getEndToken()
  {
    return tokenRange[1];
  }  
  
  public void setTextImage(TextImage ti)
  {
    textImage=ti;
  }
  
  public TextImage getTextImage()
  {
    return textImage;
  }
  
  public String getSource()
  {
    return source;
  }
  
  public void setSource(String source)
  {
    this.source=source;
  }
  
  public int[] getSourcePosition()
  {
    int[] pos={getStartToken().beginLine,getStartToken().beginColumn};
    return pos;
  }
}

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.