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

/**
 * @production LocalVariableDecl : {@link Stmt} ::= <span class="component">VarType:{@link Name}</span> <span class="component">&lt;name:String&gt;</span> <span class="component">{@link Expr}</span>;
 * @ast node
 * @declaredat JavaDemoNames.ast:12
 */
public class LocalVariableDecl extends Stmt implements Cloneable, Variable {
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public LocalVariableDecl clone() throws CloneNotSupportedException {
    LocalVariableDecl node = (LocalVariableDecl) super.clone();
    node.type_visited = -1;
    node.type_computed = false;
    node.type_value = null;
    node.isLocalVariableDecl_String_visited = null;
    node.isLocalVariableDecl_String_values = null;
    node.in$Circle(false);
    node.is$Final(false);
    return node;
  }
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public LocalVariableDecl copy() {
    try {
      LocalVariableDecl node = (LocalVariableDecl) 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 LocalVariableDecl fullCopy() {
    LocalVariableDecl tree = (LocalVariableDecl) 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 LocalVariableDecl() {
    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[2];
  }
  /**
   * 
   * @ast method
   * 
   */

  public LocalVariableDecl(Name p0, String p1, Expr p2) {
    setChild(p0, 0);
    setname(p1);
    setChild(p2, 1);
  }
  /**
   * 
     * @apilevel low-level
     
   * @ast method
   * 
   */

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

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

  public void flushCache() {
    super.flushCache();
        type_visited = -1;
    type_computed = false;
    type_value = null;
    isLocalVariableDecl_String_visited = null;
    isLocalVariableDecl_String_values = null;
  }
  /**
   * 
      * @apilevel internal
      
   * @ast method
   * 
   */

  public void flushCollectionCache() {
    super.flushCollectionCache();
      }
  /**
   * 
     * Replaces the VarType child.
     * @param node The new node to replace the VarType child.
     * @apilevel high-level
     
   * @ast method
   * 
   */

  public void setVarType(Name node) {
    setChild(node, 0);
  }
  /**
   * 
     * Retrieves the VarType child.
     * @return The current node used as the VarType child.
     * @apilevel high-level
     
   * @ast method
   * 
   */

  public Name getVarType() {
    return (Name) getChild(0);
  }
  /**
   * 
     * Retrieves the VarType child.
     * <p><em>This method does not invoke AST transformations.</em></p>
     * @return The current node used as the VarType child.
     * @apilevel low-level
     
   * @ast method
   * 
   */

  public Name getVarTypeNoTransform() {
    return (Name) getChildNoTransform(0);
  }
  /**
   * 
     * Replaces the lexeme name.
     * @param value The new value for the lexeme name.
     * @apilevel high-level
     
   * @ast method
   * 
   */

  public void setname(String value) {
    tokenString_name = value;
  }
  /**
   * 
     * @apilevel internal
     
   * @ast method
   * 
   */

  

  /**
   * @apilevel internal
   */
  protected String tokenString_name;
  /**
   * 
     * Retrieves the value for the lexeme name.
     * @return The value for the lexeme name.
     * @apilevel high-level
     
   * @ast method
   * 
   */

  public String getname() {
    return tokenString_name != null ? tokenString_name : "";
  }
  /**
   * 
     * Replaces the Expr child.
     * @param node The new node to replace the Expr child.
     * @apilevel high-level
     
   * @ast method
   * 
   */

  public void setExpr(Expr node) {
    setChild(node, 1);
  }
  /**
   * 
     * Retrieves the Expr child.
     * @return The current node used as the Expr child.
     * @apilevel high-level
     
   * @ast method
   * 
   */

  public Expr getExpr() {
    return (Expr) getChild(1);
  }
  /**
   * 
     * Retrieves the Expr child.
     * <p><em>This method does not invoke AST transformations.</em></p>
     * @return The current node used as the Expr child.
     * @apilevel low-level
     
   * @ast method
   * 
   */

  public Expr getExprNoTransform() {
    return (Expr) getChildNoTransform(1);
  }
  /**
   * @apilevel internal
   */
  protected int type_visited = -1;
  /**
   * @apilevel internal
   */
  protected boolean type_computed = false;
  /**
   * @apilevel internal
   */
  protected ClassDecl type_value;
  /**
   * @attribute syn
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:29
   */

  public ClassDecl type() {
    

    
if(type_computed) {
  return type_value;
}

    ASTNode$State state = state();
    if (type_visited == state().boundariesCrossed) {
      throw new RuntimeException("Circular definition of attr: type in class: ast.AST.SynDecl");
    }
          
    type_visited = state().boundariesCrossed;
      
    int num = state.boundariesCrossed;
    boolean isFinal = this.is$Final();
    type_value = type_compute();
      if(isFinal && num == state().boundariesCrossed){ type_computed = true; }
    type_visited = -1;
        return type_value;
  }
  /**
   * @apilevel internal
   */
  private ClassDecl type_compute() {  return getVarType().type();  }
  /**
   * @apilevel internal
   */
  protected java.util.Map isLocalVariableDecl_String_visited;
  protected java.util.Map isLocalVariableDecl_String_values;
  /**
   * @attribute syn
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:46
   */

  public boolean isLocalVariableDecl(String name) {
    Object _parameters = name;
    if(isLocalVariableDecl_String_visited == null) isLocalVariableDecl_String_visited = new java.util.HashMap(4);
    if(isLocalVariableDecl_String_values == null) isLocalVariableDecl_String_values = new java.util.HashMap(4);
    

    
if(isLocalVariableDecl_String_values.containsKey(_parameters)) {
  return ((Boolean)isLocalVariableDecl_String_values.get(_parameters)).booleanValue(); 
}

    ASTNode$State state = state();
    if (Integer.valueOf(state().boundariesCrossed).equals(isLocalVariableDecl_String_visited.get(_parameters))) {
      throw new RuntimeException("Circular definition of attr: isLocalVariableDecl in class: ast.AST.SynDecl");
    }
                
    isLocalVariableDecl_String_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed));
          
    int num = state.boundariesCrossed;
    boolean isFinal = this.is$Final();
    boolean isLocalVariableDecl_String_value = isLocalVariableDecl_compute(name);
      if(isFinal && num == state().boundariesCrossed){ isLocalVariableDecl_String_values.put(_parameters, Boolean.valueOf(isLocalVariableDecl_String_value)); }
    isLocalVariableDecl_String_visited.remove(_parameters);
        return isLocalVariableDecl_String_value;
  }
  /**
   * @apilevel internal
   */
  private boolean isLocalVariableDecl_compute(String name) {  return getname().equals(name);  }
  /**
   * @declaredat JavaDemoNames.jrag:149
   * @apilevel internal
   */
  public Kind Define_Kind_kind(ASTNode caller, ASTNode child) {
    if(caller == getExprNoTransform()) {
      return Kind.EXPRESSION_NAME;
    }
    else if(caller == getVarTypeNoTransform()) {
      return Kind.TYPE_NAME;
    }
    else {      return getParent().Define_Kind_kind(this, caller);
    }
  }
  /**
   * @apilevel internal
   */
  public ASTNode rewriteTo() {    return super.rewriteTo();
  }}
