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

package uk.co.zonetora.fj.ast.node;

import java.util.*;
import uk.co.zonetora.fj.ast.analysis.*;

public final class AProg extends PProg
{
    private final LinkedList _classDecl_ = new TypedLinkedList(new ClassDecl_Cast());

    public AProg()
    {
    }

    public AProg(
        List _classDecl_)
    {
        {
            this._classDecl_.clear();
            this._classDecl_.addAll(_classDecl_);
        }

    }

    public AProg(
        XPClassDecl _classDecl_)
    {
        if(_classDecl_ != null)
        {
            while(_classDecl_ instanceof X1PClassDecl)
            {
                this._classDecl_.addFirst(((X1PClassDecl) _classDecl_).getPClassDecl());
                _classDecl_ = ((X1PClassDecl) _classDecl_).getXPClassDecl();
            }
            this._classDecl_.addFirst(((X2PClassDecl) _classDecl_).getPClassDecl());
        }

    }
    public Object clone()
    {
        return new AProg(
            cloneList(_classDecl_));
    }

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

    public LinkedList getClassDecl()
    {
        return _classDecl_;
    }

    public void setClassDecl(List list)
    {
        _classDecl_.clear();
        _classDecl_.addAll(list);
    }

    public String toString()
    {
        return ""
            + toString(_classDecl_);
    }

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

    }

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

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

    }

    private class ClassDecl_Cast implements Cast
    {
        public Object cast(Object o)
        {
            PClassDecl node = (PClassDecl) o;

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

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

            return node;
        }
    }
}
