/* This file was generated with JastAdd2 (http://jastadd.org) version jenkins-JastAdd2-432 */
package AST;

/**
 * @production Prog : {@link ASTNode} ::= <span class="component">{@link CompUnit}*</span>;
 * @ast node
 * @declaredat JavaDemoNames.ast:1
 */
public class Prog extends ASTNode<ASTNode> implements Cloneable {
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Prog clone() throws CloneNotSupportedException {
    Prog node = (Prog) super.clone();
    node.in$Circle(false);
    node.is$Final(false);
    return node;
  }
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Prog copy() {
    try {
      Prog node = (Prog) clone();
      node.parent = null;
      if(children != null) {
        node.children = (ASTNode[]) children.clone();
      }
      return node;
    } catch (CloneNotSupportedException e) {
      throw new Error("Error: clone not supported for " + getClass().getName());
    }
  }
  /**
   * Create a deep copy of the AST subtree at this node.
   * The copy is dangling, i.e. has no parent.
   * @return dangling copy of the subtree at this node
   * @apilevel low-level
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Prog fullCopy() {
    Prog tree = (Prog) copy();
    if (children != null) {
      for (int i = 0; i < children.length; ++i) {
        ASTNode child = (ASTNode) children[i];
        if(child != null) {
          child = child.fullCopy();
          tree.setChild(child, i);
        }
      }
    }
    return tree;
  }
  /**
   * 
   * @ast method
   * @aspect PrettyPrint
   * @declaredat PrettyPrint.jadd:3
   */

  public String printTree() {
    StringBuffer buf = new StringBuffer();
    for(int i = 0; i < getNumCompUnit(); i++) {
      buf.append(getCompUnit(i).dumpTree(0));
    }
    return buf.toString();
  }
  /**
   * 
   * @ast method
   * 
   */

  public Prog() {
    super();
    is$Final(true);
  }
  /**
   * 
     * Initializes the child array to the correct size.
     * Initializes List and Opt nta children.
     * @apilevel internal
     * @ast method
     
   * @ast method
   * 
   */

  public void init$Children() {
    children = new ASTNode[1];
    setChild(new List(), 0);
  }
  /**
   * 
   * @ast method
   * 
   */

  public Prog(List<CompUnit> p0) {
    setChild(p0, 0);
    is$Final(true);
  }
  /**
   * 
     * @apilevel low-level
     
   * @ast method
   * 
   */

  protected int numChildren() {
    return 1;
  }
  /**
   * 
     * @apilevel internal
     
   * @ast method
   * 
   */

  public boolean mayHaveRewrite() {
    return false;
  }
  /**
   * 
      * @apilevel low-level
      
   * @ast method
   * 
   */

  public void flushCache() {
    super.flushCache();
  }
  /**
   * 
      * @apilevel internal
      
   * @ast method
   * 
   */

  public void flushCollectionCache() {
    super.flushCollectionCache();
  }
  /**
   * 
     * Replaces the CompUnit list.
     * @param list The new list node to be used as the CompUnit list.
     * @apilevel high-level
     
   * @ast method
   * 
   */

  public void setCompUnitList(List<CompUnit> list) {
    setChild(list, 0);
  }
  /**
   * 
     * Retrieves the number of children in the CompUnit list.
     * @return Number of children in the CompUnit list.
     * @apilevel high-level
     
   * @ast method
   * 
   */

  public int getNumCompUnit() {
    return getCompUnitList().getNumChild();
  }
  /**
   * 
     * Retrieves the number of children in the CompUnit list.
     * Calling this method will not trigger rewrites.
     * @return Number of children in the CompUnit list.
     * @apilevel low-level
     
   * @ast method
   * 
   */

  public int getNumCompUnitNoTransform() {
    return getCompUnitListNoTransform().getNumChildNoTransform();
  }
  /**
   * 
     * Retrieves the element at index {@code i} in the CompUnit list.
     * @param i Index of the element to return.
     * @return The element at position {@code i} in the CompUnit list.
     * @apilevel high-level
     
   * @ast method
   * 
   */

  @SuppressWarnings({"unchecked", "cast"})
  public CompUnit getCompUnit(int i) {
    return (CompUnit) getCompUnitList().getChild(i);
  }
  /**
   * 
     * Append an element to the CompUnit list.
     * @param node The element to append to the CompUnit list.
     * @apilevel high-level
     
   * @ast method
   * 
   */

  public void addCompUnit(CompUnit node) {
    List<CompUnit> list = (parent == null || state == null) ? getCompUnitListNoTransform() : getCompUnitList();
    list.addChild(node);
  }
  /**
   * 
     * @apilevel low-level
     
   * @ast method
   * 
   */

  public void addCompUnitNoTransform(CompUnit node) {
    List<CompUnit> list = getCompUnitListNoTransform();
    list.addChild(node);
  }
  /**
   * 
     * Replaces the CompUnit list element at index {@code i} with the new node {@code node}.
     * @param node The new node to replace the old list element.
     * @param i The list index of the node to be replaced.
     * @apilevel high-level
     
   * @ast method
   * 
   */

  public void setCompUnit(CompUnit node, int i) {
    List<CompUnit> list = getCompUnitList();
    list.setChild(node, i);
  }
  /**
   * 
     * Retrieves the CompUnit list.
     * @return The node representing the CompUnit list.
     * @apilevel high-level
     
   * @ast method
   * 
   */

  @SuppressWarnings({"unchecked", "cast"})
  public List<CompUnit> getCompUnitList() {
    List<CompUnit> list = (List<CompUnit>) getChild(0);
    list.getNumChild();
    return list;
  }
  /**
   * 
     * Retrieves the CompUnit list.
     * <p><em>This method does not invoke AST transformations.</em></p>
     * @return The node representing the CompUnit list.
     * @apilevel low-level
     
   * @ast method
   * 
   */

  @SuppressWarnings({"unchecked", "cast"})
  public List<CompUnit> getCompUnitListNoTransform() {
    return (List<CompUnit>) getChildNoTransform(0);
  }
  /**
   * 
     * Retrieves the CompUnit list.
     * @return The node representing the CompUnit list.
     * @apilevel high-level
     
   * @ast method
   * 
   */

  public List<CompUnit> getCompUnits() {
    return getCompUnitList();
  }
  /**
   * 
     * Retrieves the CompUnit list.
     * <p><em>This method does not invoke AST transformations.</em></p>
     * @return The node representing the CompUnit list.
     * @apilevel low-level
     
   * @ast method
   * 
   */

  public List<CompUnit> getCompUnitsNoTransform() {
    return getCompUnitListNoTransform();
  }
  /**
   * @declaredat JavaDemoNames.jrag:10
   * @apilevel internal
   */
  public ClassDecl Define_ClassDecl_unknownType(ASTNode caller, ASTNode child) {
    if(caller == getCompUnitListNoTransform())  {
    int childIndex = caller.getIndexOfChild(child);
    {
    return new ClassDecl("unknown", new TypeName("Object"), new List() ) {
      public ClassDecl memberClass(String name) {
        return null;
      }
      public FieldDecl memberField(String name) {
        return null;
      }
    };
  }
  }
    else {      return getParent().Define_ClassDecl_unknownType(this, caller);
    }
  }
  /**
   * @declaredat JavaDemoNames.jrag:68
   * @apilevel internal
   */
  public Variable Define_Variable_lookupVariable(ASTNode caller, ASTNode child, String name) {
    if(caller == getCompUnitListNoTransform())  {
    int childIndex = caller.getIndexOfChild(child);
    return null;
  }
    else {      return getParent().Define_Variable_lookupVariable(this, caller, name);
    }
  }
  /**
   * @declaredat JavaDemoNames.jrag:91
   * @apilevel internal
   */
  public ClassDecl Define_ClassDecl_lookupCanonical(ASTNode caller, ASTNode child, String pack, String type) {
    if(caller == getCompUnitListNoTransform())  {
    int childIndex = caller.getIndexOfChild(child);
    {
    for(int i = 0; i < getNumCompUnit(); i++)
      if(getCompUnit(i).getpackageName().equals(pack) && 
         getCompUnit(i).topLevelType(type) != null)
        return getCompUnit(i).topLevelType(type);
    return null;
  }
  }
    else {      return getParent().Define_ClassDecl_lookupCanonical(this, caller, pack, type);
    }
  }
  /**
   * @declaredat JavaDemoNames.jrag:117
   * @apilevel internal
   */
  public ClassDecl Define_ClassDecl_lookupType(ASTNode caller, ASTNode child, String name) {
    if(caller == getCompUnitListNoTransform())  {
    int childIndex = caller.getIndexOfChild(child);
    return null;
  }
    else {      return getParent().Define_ClassDecl_lookupType(this, caller, name);
    }
  }
  /**
   * @declaredat JavaDemoNames.jrag:144
   * @apilevel internal
   */
  public Kind Define_Kind_kind(ASTNode caller, ASTNode child) {
    if(caller == getCompUnitListNoTransform())  {
    int childIndex = caller.getIndexOfChild(child);
    return Kind.AMBIGUOUS_NAME;
  }
    else {      return getParent().Define_Kind_kind(this, caller);
    }
  }
  /**
   * @declaredat JavaDemoNames.jrag:185
   * @apilevel internal
   */
  public boolean Define_boolean_hasPackage(ASTNode caller, ASTNode child, String name) {
    if(caller == getCompUnitListNoTransform())  {
    int childIndex = caller.getIndexOfChild(child);
    {
    for(int i = 0; i < getNumCompUnit(); i++)
      if(getCompUnit(i).getpackageName().equals(name))
        return true;
    return false;
  }
  }
    else {      return getParent().Define_boolean_hasPackage(this, caller, name);
    }
  }
  /**
   * @apilevel internal
   */
  public ASTNode rewriteTo() {    return super.rewriteTo();
  }}
