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

/**
 * @production AmbiguousName : {@link Name};
 * @ast node
 * @declaredat JavaDemoNames.ast:23
 */
public class AmbiguousName extends Name implements Cloneable {
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public AmbiguousName clone() throws CloneNotSupportedException {
    AmbiguousName node = (AmbiguousName) super.clone();
    node.predKind_visited = -1;
    node.predKind_computed = false;
    node.predKind_value = null;
    node.in$Circle(false);
    node.is$Final(false);
    return node;
  }
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public AmbiguousName copy() {
    try {
      AmbiguousName node = (AmbiguousName) 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 AmbiguousName fullCopy() {
    AmbiguousName tree = (AmbiguousName) 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 AmbiguousName() {
    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() {
  }
  /**
   * 
   * @ast method
   * 
   */

  public AmbiguousName(String p0) {
    setname(p0);
  }
  /**
   * 
     * @apilevel low-level
     
   * @ast method
   * 
   */

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

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

  public void flushCache() {
    super.flushCache();
    predKind_visited = -1;
    predKind_computed = false;
    predKind_value = 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;
  }
  /**
   * 
     * 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 : "";
  }
  /**
   * @apilevel internal
   */
  protected int predKind_visited = -1;
  /**
   * @apilevel internal
   */
  protected boolean predKind_computed = false;
  /**
   * @apilevel internal
   */
  protected Kind predKind_value;
  /**
   * @attribute syn
   * @aspect JavaDemoNames
   * @declaredat JavaDemoNames.jrag:160
   */

  public Kind predKind() {
    
    
        
    if(predKind_computed) {
      return predKind_value;
    }
    ASTNode$State state = state();
    if (predKind_visited == state().boundariesCrossed) {
      throw new RuntimeException("Circular definition of attr: predKind in class: ast.AST.SynDecl");
    }
    predKind_visited = state().boundariesCrossed;
    int num = state.boundariesCrossed;
    boolean isFinal = this.is$Final();
    predKind_value = predKind_compute();
      if(isFinal && num == state().boundariesCrossed){ predKind_computed = true; }
    predKind_visited = -1;
        return predKind_value;
  }
  /**
   * @apilevel internal
   */
  private Kind predKind_compute() {  return Kind.AMBIGUOUS_NAME;  }
  /**
   * @apilevel internal
   */
  public ASTNode rewriteTo() {    // Declared at @declaredat JavaDemoNames.jrag:170
    if (lookupVariable(getname()) != null) {
      state().duringJavaDemoNames++;
      ASTNode result = rewriteRule0();
      state().duringJavaDemoNames--;
      return result;
    }    // Declared at @declaredat JavaDemoNames.jrag:172
    if (lookupType(getname()) != null) {
      state().duringJavaDemoNames++;
      ASTNode result = rewriteRule1();
      state().duringJavaDemoNames--;
      return result;
    }    // Declared at @declaredat JavaDemoNames.jrag:174
    if (hasPackage(getname())) {
      state().duringJavaDemoNames++;
      ASTNode result = rewriteRule2();
      state().duringJavaDemoNames--;
      return result;
    }    return super.rewriteTo();
  }  /**
   * @declaredat @declaredat JavaDemoNames.jrag:170
   * @apilevel internal
   */  private Name rewriteRule0() {
    return new ExpressionName(getname());
  }
  /**
   * @declaredat @declaredat JavaDemoNames.jrag:172
   * @apilevel internal
   */  private Name rewriteRule1() {
    return new TypeName(getname());
  }
  /**
   * @declaredat @declaredat JavaDemoNames.jrag:174
   * @apilevel internal
   */  private Name rewriteRule2() {
    return new PackageName(getname());
  }
}
