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

/**
 * @production CompUnit : {@link ASTNode} ::= <span class="component">&lt;packageName:String&gt;</span> <span class="component">{@link ClassDecl}*</span>;
 * @ast node
 * @declaredat JavaDemoNames.ast:2
 */
public class CompUnit extends ASTNode<ASTNode> implements Cloneable {
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public CompUnit clone() throws CloneNotSupportedException {
    CompUnit node = (CompUnit) super.clone();
    node.topLevelType_String_visited = null;
    node.topLevelType_String_values = null;
    node.extra_visited = -1;
    node.unknownType_visited = -1;
    node.unknownType_computed = false;
    node.unknownType_value = null;
    node.lookupVariable_String_visited = null;
    node.lookupVariable_String_values = null;
    node.lookupType_String_visited = null;
    node.lookupType_String_values = null;
    node.lookupCanonical_String_String_visited = null;
    node.lookupCanonical_String_String_values = null;
    node.kind_visited = -1;
    node.kind_computed = false;
    node.kind_value = null;
    node.hasPackage_String_visited = null;
    node.hasPackage_String_values = null;
    node.in$Circle(false);
    node.is$Final(false);
    return node;
  }
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public CompUnit copy() {
    try {
      CompUnit node = (CompUnit) 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 CompUnit fullCopy() {
    CompUnit tree = (CompUnit) 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 CompUnit() {
    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 CompUnit(String p0, List<ClassDecl> p1) {
    setpackageName(p0);
    setChild(p1, 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();
        topLevelType_String_visited = null;
    topLevelType_String_values = null;
    extra_visited = -1;
    unknownType_visited = -1;
    unknownType_computed = false;
    unknownType_value = null;
    lookupVariable_String_visited = null;
    lookupVariable_String_values = null;
    lookupType_String_visited = null;
    lookupType_String_values = null;
    lookupCanonical_String_String_visited = null;
    lookupCanonical_String_String_values = null;
    kind_visited = -1;
    kind_computed = false;
    kind_value = null;
    hasPackage_String_visited = null;
    hasPackage_String_values = null;
  }
  /**
   * 
      * @apilevel internal
      
   * @ast method
   * 
   */

  public void flushCollectionCache() {
    super.flushCollectionCache();
      }
  /**
   * 
     * Replaces the lexeme packageName.
     * @param value The new value for the lexeme packageName.
     * @apilevel high-level
     
   * @ast method
   * 
   */

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

  

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

  public String getpackageName() {
    return tokenString_packageName != null ? tokenString_packageName : "";
  }
  /**
   * 
     * Replaces the ClassDecl list.
     * @param list The new list node to be used as the ClassDecl list.
     * @apilevel high-level
     
   * @ast method
   * 
   */

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

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

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

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

  public void addClassDecl(ClassDecl node) {
    List<ClassDecl> list = (parent == null || state == null) ? getClassDeclListNoTransform() : getClassDeclList();
    list.addChild(node);
  }
  /**
   * 
     * @apilevel low-level
     
   * @ast method
   * 
   */

  public void addClassDeclNoTransform(ClassDecl node) {
    List<ClassDecl> list = getClassDeclListNoTransform();
    list.addChild(node);
  }
  /**
   * 
     * Replaces the ClassDecl 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 setClassDecl(ClassDecl node, int i) {
    List<ClassDecl> list = getClassDeclList();
    list.setChild(node, i);
  }
  /**
   * 
     * Retrieves the ClassDecl list.
     * @return The node representing the ClassDecl list.
     * @apilevel high-level
     
   * @ast method
   * 
   */

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

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

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

  public List<ClassDecl> getClassDeclsNoTransform() {
    return getClassDeclListNoTransform();
  }
  /**
   * @apilevel internal
   */
  protected java.util.Map topLevelType_String_visited;
  protected java.util.Map topLevelType_String_values;
  /**
   * @attribute syn
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:82
   */

  public ClassDecl topLevelType(String name) {
    Object _parameters = name;
    if(topLevelType_String_visited == null) topLevelType_String_visited = new java.util.HashMap(4);
    if(topLevelType_String_values == null) topLevelType_String_values = new java.util.HashMap(4);
    

    
if(topLevelType_String_values.containsKey(_parameters)) {
  return (ClassDecl)topLevelType_String_values.get(_parameters); 
}

    ASTNode$State state = state();
    if (Integer.valueOf(state().boundariesCrossed).equals(topLevelType_String_visited.get(_parameters))) {
      throw new RuntimeException("Circular definition of attr: topLevelType in class: ast.AST.SynDecl");
    }
                
    topLevelType_String_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed));
          
    int num = state.boundariesCrossed;
    boolean isFinal = this.is$Final();
    ClassDecl topLevelType_String_value = topLevelType_compute(name);
      if(isFinal && num == state().boundariesCrossed){ topLevelType_String_values.put(_parameters, topLevelType_String_value); }
    topLevelType_String_visited.remove(_parameters);
        return topLevelType_String_value;
  }
  /**
   * @apilevel internal
   */
  private ClassDecl topLevelType_compute(String name) {
      for(int i = 0; i < getNumClassDecl(); i++)
        if(getClassDecl(i).getname().equals(name))
          return getClassDecl(i);
      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 ", packageName: " + getpackageName();  }
    finally {
      extra_visited = -1;
    }
  }
  /**
   * @attribute inh
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:21
   */

  public ClassDecl unknownType() {
    

    
if(unknownType_computed) {
  return unknownType_value;
}

    ASTNode$State state = state();
    if (unknownType_visited == state().boundariesCrossed) {
      throw new RuntimeException("Circular definition of attr: unknownType in class: ast.AST.InhDecl");
    }
          
    unknownType_visited = state().boundariesCrossed;
      
    int num = state.boundariesCrossed;
    boolean isFinal = this.is$Final();
    unknownType_value = getParent().Define_ClassDecl_unknownType(this, null);
      if(isFinal && num == state().boundariesCrossed){ unknownType_computed = true; }
    unknownType_visited = -1;
        return unknownType_value;
  }
  /**
   * @apilevel internal
   */
  protected int unknownType_visited = -1;
  /**
   * @apilevel internal
   */
  protected boolean unknownType_computed = false;
  /**
   * @apilevel internal
   */
  protected ClassDecl unknownType_value;
  /**
   * @attribute inh
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:34
   */

  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:72
   */

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

  public ClassDecl lookupCanonical(String pack, String type) {
    java.util.List _parameters = new java.util.ArrayList(2);
    _parameters.add(pack);
    _parameters.add(type);
    if(lookupCanonical_String_String_visited == null) lookupCanonical_String_String_visited = new java.util.HashMap(4);
    if(lookupCanonical_String_String_values == null) lookupCanonical_String_String_values = new java.util.HashMap(4);
    

    
if(lookupCanonical_String_String_values.containsKey(_parameters)) {
  return (ClassDecl)lookupCanonical_String_String_values.get(_parameters); 
}

    ASTNode$State state = state();
    if (Integer.valueOf(state().boundariesCrossed).equals(lookupCanonical_String_String_visited.get(_parameters))) {
      throw new RuntimeException("Circular definition of attr: lookupCanonical in class: ast.AST.InhDecl");
    }
                
    lookupCanonical_String_String_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed));
          
    int num = state.boundariesCrossed;
    boolean isFinal = this.is$Final();
    ClassDecl lookupCanonical_String_String_value = getParent().Define_ClassDecl_lookupCanonical(this, null, pack, type);
      if(isFinal && num == state().boundariesCrossed){ lookupCanonical_String_String_values.put(_parameters, lookupCanonical_String_String_value); }
    lookupCanonical_String_String_visited.remove(_parameters);
        return lookupCanonical_String_String_value;
  }
  /**
   * @apilevel internal
   */
  protected java.util.Map lookupCanonical_String_String_visited;
  protected java.util.Map lookupCanonical_String_String_values;
  /**
   * @attribute inh
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:143
   */

  public Kind kind() {
    

    
if(kind_computed) {
  return kind_value;
}

    ASTNode$State state = state();
    if (kind_visited == state().boundariesCrossed) {
      throw new RuntimeException("Circular definition of attr: kind in class: ast.AST.InhDecl");
    }
          
    kind_visited = state().boundariesCrossed;
      
    int num = state.boundariesCrossed;
    boolean isFinal = this.is$Final();
    kind_value = getParent().Define_Kind_kind(this, null);
      if(isFinal && num == state().boundariesCrossed){ kind_computed = true; }
    kind_visited = -1;
        return kind_value;
  }
  /**
   * @apilevel internal
   */
  protected int kind_visited = -1;
  /**
   * @apilevel internal
   */
  protected boolean kind_computed = false;
  /**
   * @apilevel internal
   */
  protected Kind kind_value;
  /**
   * @attribute inh
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:184
   */

  public boolean hasPackage(String name) {
    Object _parameters = name;
    if(hasPackage_String_visited == null) hasPackage_String_visited = new java.util.HashMap(4);
    if(hasPackage_String_values == null) hasPackage_String_values = new java.util.HashMap(4);
    

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

    ASTNode$State state = state();
    if (Integer.valueOf(state().boundariesCrossed).equals(hasPackage_String_visited.get(_parameters))) {
      throw new RuntimeException("Circular definition of attr: hasPackage in class: ast.AST.InhDecl");
    }
                
    hasPackage_String_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed));
          
    int num = state.boundariesCrossed;
    boolean isFinal = this.is$Final();
    boolean hasPackage_String_value = getParent().Define_boolean_hasPackage(this, null, name);
      if(isFinal && num == state().boundariesCrossed){ hasPackage_String_values.put(_parameters, Boolean.valueOf(hasPackage_String_value)); }
    hasPackage_String_visited.remove(_parameters);
        return hasPackage_String_value;
  }
  /**
   * @apilevel internal
   */
  protected java.util.Map hasPackage_String_visited;
  protected java.util.Map hasPackage_String_values;
  /**
   * @declaredat JavaDemoNames.jrag:76
   * @apilevel internal
   */
  public ClassDecl Define_ClassDecl_lookupType(ASTNode caller, ASTNode child, String name) {
    if(caller == getClassDeclListNoTransform())  {
    int childIndex = caller.getIndexOfChild(child);
    {
    if(topLevelType(name) != null)
      return topLevelType(name);
    // declarations in same package
    return lookupCanonical(getpackageName(), name);
  }
  }
    else {      return getParent().Define_ClassDecl_lookupType(this, caller, name);
    }
  }
  /**
   * @apilevel internal
   */
  public ASTNode rewriteTo() {    return super.rewriteTo();
  }}
