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

/**
 * @production ClassDecl : {@link ASTNode} ::= <span class="component">&lt;name:String&gt;</span> <span class="component">Super:{@link Name}</span> <span class="component">{@link BodyDecl}*</span>;
 * @ast node
 * @declaredat JavaDemoNames.ast:3
 */
public class ClassDecl extends ASTNode<ASTNode> implements Cloneable {
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public ClassDecl clone() throws CloneNotSupportedException {
    ClassDecl node = (ClassDecl) super.clone();
    node.memberField_String_visited = null;
    node.memberField_String_values = null;
    node.memberClass_String_visited = null;
    node.memberClass_String_values = null;
    node.extra_visited = -1;
    node.lookupVariable_String_visited = null;
    node.lookupVariable_String_values = null;
    node.lookupType_String_visited = null;
    node.lookupType_String_values = null;
    node.in$Circle(false);
    node.is$Final(false);
    return node;
  }
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public ClassDecl copy() {
    try {
      ClassDecl node = (ClassDecl) 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 ClassDecl fullCopy() {
    ClassDecl tree = (ClassDecl) 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 ClassDecl() {
    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];
    setChild(new List(), 1);
  }
  /**
   * 
   * @ast method
   * 
   */

  public ClassDecl(String p0, Name p1, List<BodyDecl> p2) {
    setname(p0);
    setChild(p1, 0);
    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();
    if (((Object)tokenString_name) instanceof ASTNode) {
      tokenString_name = null;
    }
    memberField_String_visited = null;
    memberField_String_values = null;
    memberClass_String_visited = null;
    memberClass_String_values = null;
    extra_visited = -1;
    lookupVariable_String_visited = null;
    lookupVariable_String_values = null;
    lookupType_String_visited = null;
    lookupType_String_values = null;
  }
  /**
   * 
      * @apilevel internal
      
   * @ast method
   * 
   */

  public void flushCollectionCache() {
    super.flushCollectionCache();
  }
  /**
   * 
     * 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 Super child.
     * @param node The new node to replace the Super child.
     * @apilevel high-level
     
   * @ast method
   * 
   */

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

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

  public Name getSuperNoTransform() {
    return (Name) getChildNoTransform(0);
  }
  /**
   * 
     * Replaces the BodyDecl list.
     * @param list The new list node to be used as the BodyDecl list.
     * @apilevel high-level
     
   * @ast method
   * 
   */

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

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

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

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

  public void addBodyDecl(BodyDecl node) {
    List<BodyDecl> list = (parent == null || state == null) ? getBodyDeclListNoTransform() : getBodyDeclList();
    list.addChild(node);
  }
  /**
   * 
     * @apilevel low-level
     
   * @ast method
   * 
   */

  public void addBodyDeclNoTransform(BodyDecl node) {
    List<BodyDecl> list = getBodyDeclListNoTransform();
    list.addChild(node);
  }
  /**
   * 
     * Replaces the BodyDecl 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 setBodyDecl(BodyDecl node, int i) {
    List<BodyDecl> list = getBodyDeclList();
    list.setChild(node, i);
  }
  /**
   * 
     * Retrieves the BodyDecl list.
     * @return The node representing the BodyDecl list.
     * @apilevel high-level
     
   * @ast method
   * 
   */

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

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

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

  public List<BodyDecl> getBodyDeclsNoTransform() {
    return getBodyDeclListNoTransform();
  }
  /**
   * @apilevel internal
   */
  protected java.util.Map memberField_String_visited;
  protected java.util.Map memberField_String_values;
  /**
   * @attribute syn
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:56
   */

  public FieldDecl memberField(String name) {
    Object _parameters = name;
    if(memberField_String_visited == null) memberField_String_visited = new java.util.HashMap(4);
    if(memberField_String_values == null) memberField_String_values = new java.util.HashMap(4);
    
    
        
    if(memberField_String_values.containsKey(_parameters)) {
      return (FieldDecl)memberField_String_values.get(_parameters); 
    }
    ASTNode$State state = state();
    if (Integer.valueOf(state().boundariesCrossed).equals(memberField_String_visited.get(_parameters))) {
      throw new RuntimeException("Circular definition of attr: memberField in class: ast.AST.SynDecl");
    }
    memberField_String_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed));
    int num = state.boundariesCrossed;
    boolean isFinal = this.is$Final();
    FieldDecl memberField_String_value = memberField_compute(name);
      if(isFinal && num == state().boundariesCrossed){ memberField_String_values.put(_parameters, memberField_String_value); }
    memberField_String_visited.remove(_parameters);
        return memberField_String_value;
  }
  /**
   * @apilevel internal
   */
  private FieldDecl memberField_compute(String name) {
      for(int i = 0; i < getNumBodyDecl(); i++)
        if(getBodyDecl(i).isField(name))
          return (FieldDecl)getBodyDecl(i);
      if(!getname().equals("Object") && getSuper().type().memberField(name) != null)
        return getSuper().type().memberField(name);
      return null;
    }
  /**
   * @apilevel internal
   */
  protected java.util.Map memberClass_String_visited;
  protected java.util.Map memberClass_String_values;
  /**
   * @attribute syn
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:105
   */

  public ClassDecl memberClass(String name) {
    Object _parameters = name;
    if(memberClass_String_visited == null) memberClass_String_visited = new java.util.HashMap(4);
    if(memberClass_String_values == null) memberClass_String_values = new java.util.HashMap(4);
    
    
        
    if(memberClass_String_values.containsKey(_parameters)) {
      return (ClassDecl)memberClass_String_values.get(_parameters); 
    }
    ASTNode$State state = state();
    if (Integer.valueOf(state().boundariesCrossed).equals(memberClass_String_visited.get(_parameters))) {
      throw new RuntimeException("Circular definition of attr: memberClass in class: ast.AST.SynDecl");
    }
    memberClass_String_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed));
    int num = state.boundariesCrossed;
    boolean isFinal = this.is$Final();
    ClassDecl memberClass_String_value = memberClass_compute(name);
      if(isFinal && num == state().boundariesCrossed){ memberClass_String_values.put(_parameters, memberClass_String_value); }
    memberClass_String_visited.remove(_parameters);
        return memberClass_String_value;
  }
  /**
   * @apilevel internal
   */
  private ClassDecl memberClass_compute(String name) {
      for(int i = 0; i < getNumBodyDecl(); i++)
        if(getBodyDecl(i).isMemberClass(name))
          return ((MemberClassDecl)getBodyDecl(i)).getClassDecl();
      if(!getname().equals("Object") && getSuper().type().memberClass(name) != null)
        return getSuper().type().memberClass(name);
      return null;
    }
  /**
   * @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 ", classDecl: " + getname();  }
    finally {
      extra_visited = -1;
    }
  }
  /**
   * @attribute inh
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:36
   */

  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;
  /**
   * @attribute inh
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:73
   */

  public ClassDecl lookupType(String name) {
    Object _parameters = name;
    if(lookupType_String_visited == null) lookupType_String_visited = new java.util.HashMap(4);
    if(lookupType_String_values == null) lookupType_String_values = new java.util.HashMap(4);
    
    
        
    if(lookupType_String_values.containsKey(_parameters)) {
      return (ClassDecl)lookupType_String_values.get(_parameters); 
    }
    ASTNode$State state = state();
    if (Integer.valueOf(state().boundariesCrossed).equals(lookupType_String_visited.get(_parameters))) {
      throw new RuntimeException("Circular definition of attr: lookupType in class: ast.AST.InhDecl");
    }
    lookupType_String_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed));
    int num = state.boundariesCrossed;
    boolean isFinal = this.is$Final();
    ClassDecl lookupType_String_value = getParent().Define_ClassDecl_lookupType(this, null, name);
      if(isFinal && num == state().boundariesCrossed){ lookupType_String_values.put(_parameters, lookupType_String_value); }
    lookupType_String_visited.remove(_parameters);
        return lookupType_String_value;
  }
  /**
   * @apilevel internal
   */
  protected java.util.Map lookupType_String_visited;
  protected java.util.Map lookupType_String_values;
  /**
   * @declaredat JavaDemoNames.jrag:50
   * @apilevel internal
   */
  public Variable Define_Variable_lookupVariable(ASTNode caller, ASTNode child, String name) {
    if(caller == getBodyDeclListNoTransform())  {
    int childIndex = caller.getIndexOfChild(child);
    {
    if(memberField(name) != null)
      return memberField(name);
    return lookupVariable(name);
  }
  }
    else {      return getParent().Define_Variable_lookupVariable(this, caller, name);
    }
  }
  /**
   * @declaredat JavaDemoNames.jrag:99
   * @apilevel internal
   */
  public ClassDecl Define_ClassDecl_lookupType(ASTNode caller, ASTNode child, String name) {
    if(caller == getBodyDeclListNoTransform())  {
    int childIndex = caller.getIndexOfChild(child);
    {
    if(memberClass(name) != null)
      return memberClass(name);
    return lookupType(name);
  }
  }
    else {      return getParent().Define_ClassDecl_lookupType(this, caller, name);
    }
  }
  /**
   * @declaredat JavaDemoNames.jrag:145
   * @apilevel internal
   */
  public Kind Define_Kind_kind(ASTNode caller, ASTNode child) {
    if(caller == getSuperNoTransform()) {
      return Kind.PACKAGE_NAME;
    }
    else {      return getParent().Define_Kind_kind(this, caller);
    }
  }
  /**
   * @apilevel internal
   */
  public ASTNode rewriteTo() {    return super.rewriteTo();
  }}
