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

/**
 * @production Block : {@link Stmt} ::= <span class="component">{@link Stmt}*</span>;
 * @ast node
 * @declaredat JavaDemoNames.ast:11
 */
public class Block extends Stmt implements Cloneable {
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Block clone() throws CloneNotSupportedException {
    Block node = (Block) super.clone();
    node.lookupVariable_String_visited = null;
    node.lookupVariable_String_values = null;
    node.in$Circle(false);
    node.is$Final(false);
    return node;
  }
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Block copy() {
    try {
      Block node = (Block) 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 Block fullCopy() {
    Block tree = (Block) 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
   * 
   */

  public Block() {
    super();
  }
  /**
   * 
     * 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 Block(List<Stmt> p0) {
    setChild(p0, 0);
  }
  /**
   * 
     * @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();
    lookupVariable_String_visited = null;
    lookupVariable_String_values = null;
  }
  /**
   * 
      * @apilevel internal
      
   * @ast method
   * 
   */

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

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

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

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

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

  public void addStmt(Stmt node) {
    List<Stmt> list = (parent == null || state == null) ? getStmtListNoTransform() : getStmtList();
    list.addChild(node);
  }
  /**
   * 
     * @apilevel low-level
     
   * @ast method
   * 
   */

  public void addStmtNoTransform(Stmt node) {
    List<Stmt> list = getStmtListNoTransform();
    list.addChild(node);
  }
  /**
   * 
     * Replaces the Stmt 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 setStmt(Stmt node, int i) {
    List<Stmt> list = getStmtList();
    list.setChild(node, i);
  }
  /**
   * 
     * Retrieves the Stmt list.
     * @return The node representing the Stmt list.
     * @apilevel high-level
     
   * @ast method
   * 
   */

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

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

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

  public List<Stmt> getStmtsNoTransform() {
    return getStmtListNoTransform();
  }
  /**
   * @attribute inh
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:35
   */

  public Variable lookupVariable(String name) {
    Object _parameters = name;
    if(lookupVariable_String_visited == null) lookupVariable_String_visited = new java.util.HashMap(4);
    if(lookupVariable_String_values == null) lookupVariable_String_values = new java.util.HashMap(4);
    
    
        
    if(lookupVariable_String_values.containsKey(_parameters)) {
      return (Variable)lookupVariable_String_values.get(_parameters); 
    }
    ASTNode$State state = state();
    if (Integer.valueOf(state().boundariesCrossed).equals(lookupVariable_String_visited.get(_parameters))) {
      throw new RuntimeException("Circular definition of attr: lookupVariable in class: ast.AST.InhDecl");
    }
    lookupVariable_String_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed));
    int num = state.boundariesCrossed;
    boolean isFinal = this.is$Final();
    Variable lookupVariable_String_value = getParent().Define_Variable_lookupVariable(this, null, name);
      if(isFinal && num == state().boundariesCrossed){ lookupVariable_String_values.put(_parameters, lookupVariable_String_value); }
    lookupVariable_String_visited.remove(_parameters);
        return lookupVariable_String_value;
  }
  /**
   * @apilevel internal
   */
  protected java.util.Map lookupVariable_String_visited;
  protected java.util.Map lookupVariable_String_values;
  /**
   * @declaredat JavaDemoNames.jrag:39
   * @apilevel internal
   */
  public Variable Define_Variable_lookupVariable(ASTNode caller, ASTNode child, String name) {
    if(caller == getStmtListNoTransform())  {
    int index = caller.getIndexOfChild(child);
    {
    for(int i = 0; i < index; i++)
      if(getStmt(i).isLocalVariableDecl(name))
        return (LocalVariableDecl)getStmt(i);
    return lookupVariable(name);
  }
  }
    else {      return getParent().Define_Variable_lookupVariable(this, caller, name);
    }
  }
  /**
   * @apilevel internal
   */
  public ASTNode rewriteTo() {    return super.rewriteTo();
  }}
