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

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

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

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

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

  public Name getFieldTypeNoTransform() {
    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:30
   */

  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 getFieldType().type();  }
  /**
   * @apilevel internal
   */
  protected java.util.Map isField_String_visited;
  protected java.util.Map isField_String_values;
  /**
   * @attribute syn
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:65
   */

  public boolean isField(String name) {
    Object _parameters = name;
    if(isField_String_visited == null) isField_String_visited = new java.util.HashMap(4);
    if(isField_String_values == null) isField_String_values = new java.util.HashMap(4);
    

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

    ASTNode$State state = state();
    if (Integer.valueOf(state().boundariesCrossed).equals(isField_String_visited.get(_parameters))) {
      throw new RuntimeException("Circular definition of attr: isField in class: ast.AST.SynDecl");
    }
                
    isField_String_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed));
          
    int num = state.boundariesCrossed;
    boolean isFinal = this.is$Final();
    boolean isField_String_value = isField_compute(name);
      if(isFinal && num == state().boundariesCrossed){ isField_String_values.put(_parameters, Boolean.valueOf(isField_String_value)); }
    isField_String_visited.remove(_parameters);
        return isField_String_value;
  }
  /**
   * @apilevel internal
   */
  private boolean isField_compute(String name) {  return getname().equals(name);  }
  /**
   * @apilevel internal
   */
  protected int extra_visited = -1;
    /**
     * @attribute syn
     * @aspect PrettyPrint
     * @declaredat PrettyPrint.jadd:23
     */
  public String extra() {
    ASTNode$State state = state();
    if (extra_visited == state().boundariesCrossed) {
      throw new RuntimeException("Circular definition of attr: extra in class: ast.AST.SynDecl");
    }
          
    extra_visited = state().boundariesCrossed;
      
    try {  return ", fieldDecl: " + getname();  }
    finally {
      extra_visited = -1;
    }
  }
  /**
   * @declaredat JavaDemoNames.jrag:147
   * @apilevel internal
   */
  public Kind Define_Kind_kind(ASTNode caller, ASTNode child) {
    if(caller == getExprNoTransform()) {
      return Kind.EXPRESSION_NAME;
    }
    else if(caller == getFieldTypeNoTransform()) {
      return Kind.TYPE_NAME;
    }
    else {      return getParent().Define_Kind_kind(this, caller);
    }
  }
  /**
   * @apilevel internal
   */
  public ASTNode rewriteTo() {    return super.rewriteTo();
  }}
