/* This file was generated by SableCC (http://www.sablecc.org/). */

package org.sablecc.sablecc.node;

import java.util.*;
import org.sablecc.sablecc.analysis.*;

public final class AGrammar extends PGrammar
{
  private final LinkedList _package_ = new TypedLinkedList(new Package_Cast());
  private PHelpers _helpers_;
  private PStates _states_;
  private PTokens _tokens_;
  private PIgnTokens _ignTokens_;
  private PProductions _productions_;
  private PAst _ast_;

  public AGrammar()
  {}

  public AGrammar(
    List _package_,
    PHelpers _helpers_,
    PStates _states_,
    PTokens _tokens_,
    PIgnTokens _ignTokens_,
    PProductions _productions_,
    PAst _ast_)
  {
    {
      this._package_.clear();
      this._package_.addAll(_package_);
    }

    setHelpers(_helpers_);

    setStates(_states_);

    setTokens(_tokens_);

    setIgnTokens(_ignTokens_);

    setProductions(_productions_);

    setAst(_ast_);

  }
  public Object clone()
  {
    return new AGrammar(
             cloneList(_package_),
             (PHelpers) cloneNode(_helpers_),
             (PStates) cloneNode(_states_),
             (PTokens) cloneNode(_tokens_),
             (PIgnTokens) cloneNode(_ignTokens_),
             (PProductions) cloneNode(_productions_),
             (PAst) cloneNode(_ast_));
  }

  public void apply(Switch sw)
  {
    ((Analysis) sw).caseAGrammar(this);
  }

  public LinkedList getPackage()
  {
    return _package_;
  }

  public void setPackage(List list)
  {
    _package_.clear();
    _package_.addAll(list);
  }

  public PHelpers getHelpers()
  {
    return _helpers_;
  }

  public void setHelpers(PHelpers node)
  {
    if(_helpers_ != null)
    {
      _helpers_.parent(null);
    }

    if(node != null)
    {
      if(node.parent() != null)
      {
        node.parent().removeChild(node);
      }

      node.parent(this);
    }

    _helpers_ = node;
  }

  public PStates getStates()
  {
    return _states_;
  }

  public void setStates(PStates node)
  {
    if(_states_ != null)
    {
      _states_.parent(null);
    }

    if(node != null)
    {
      if(node.parent() != null)
      {
        node.parent().removeChild(node);
      }

      node.parent(this);
    }

    _states_ = node;
  }

  public PTokens getTokens()
  {
    return _tokens_;
  }

  public void setTokens(PTokens node)
  {
    if(_tokens_ != null)
    {
      _tokens_.parent(null);
    }

    if(node != null)
    {
      if(node.parent() != null)
      {
        node.parent().removeChild(node);
      }

      node.parent(this);
    }

    _tokens_ = node;
  }

  public PIgnTokens getIgnTokens()
  {
    return _ignTokens_;
  }

  public void setIgnTokens(PIgnTokens node)
  {
    if(_ignTokens_ != null)
    {
      _ignTokens_.parent(null);
    }

    if(node != null)
    {
      if(node.parent() != null)
      {
        node.parent().removeChild(node);
      }

      node.parent(this);
    }

    _ignTokens_ = node;
  }

  public PProductions getProductions()
  {
    return _productions_;
  }

  public void setProductions(PProductions node)
  {
    if(_productions_ != null)
    {
      _productions_.parent(null);
    }

    if(node != null)
    {
      if(node.parent() != null)
      {
        node.parent().removeChild(node);
      }

      node.parent(this);
    }

    _productions_ = node;
  }

  public PAst getAst()
  {
    return _ast_;
  }

  public void setAst(PAst node)
  {
    if(_ast_ != null)
    {
      _ast_.parent(null);
    }

    if(node != null)
    {
      if(node.parent() != null)
      {
        node.parent().removeChild(node);
      }

      node.parent(this);
    }

    _ast_ = node;
  }

  public String toString()
  {
    return ""
           + toString(_package_)
           + toString(_helpers_)
           + toString(_states_)
           + toString(_tokens_)
           + toString(_ignTokens_)
           + toString(_productions_)
           + toString(_ast_);
  }

  void removeChild(Node child)
  {
    if(_package_.remove(child))
    {
      return;
    }

    if(_helpers_ == child)
    {
      _helpers_ = null;
      return;
    }

    if(_states_ == child)
    {
      _states_ = null;
      return;
    }

    if(_tokens_ == child)
    {
      _tokens_ = null;
      return;
    }

    if(_ignTokens_ == child)
    {
      _ignTokens_ = null;
      return;
    }

    if(_productions_ == child)
    {
      _productions_ = null;
      return;
    }

    if(_ast_ == child)
    {
      _ast_ = null;
      return;
    }

  }

  void replaceChild(Node oldChild, Node newChild)
  {
    for(ListIterator i = _package_.listIterator(); i.hasNext();)
    {
      if(i.next() == oldChild)
      {
        if(newChild != null)
        {
          i.set(newChild);
          oldChild.parent(null);
          return;
        }

        i.remove();
        oldChild.parent(null);
        return;
      }
    }

    if(_helpers_ == oldChild)
    {
      setHelpers((PHelpers) newChild);
      return;
    }

    if(_states_ == oldChild)
    {
      setStates((PStates) newChild);
      return;
    }

    if(_tokens_ == oldChild)
    {
      setTokens((PTokens) newChild);
      return;
    }

    if(_ignTokens_ == oldChild)
    {
      setIgnTokens((PIgnTokens) newChild);
      return;
    }

    if(_productions_ == oldChild)
    {
      setProductions((PProductions) newChild);
      return;
    }

    if(_ast_ == oldChild)
    {
      setAst((PAst) newChild);
      return;
    }

  }

  private class Package_Cast implements Cast
  {
    public Object cast(Object o)
    {
      TPkgId node = (TPkgId) o;

      if((node.parent() != null) &&
          (node.parent() != AGrammar.this))
      {
        node.parent().removeChild(node);
      }

      if((node.parent() == null) ||
          (node.parent() != AGrammar.this))
      {
        node.parent(AGrammar.this);
      }

      return node;
    }
  }
}
