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

package MONAViewer.monalanguage.node;

import java.util.*;
import MONAViewer.monalanguage.analysis.*;

public final class AStart extends PStart
{
    private PHeader _header_;
    private final LinkedList _declaration_ = new TypedLinkedList(new Declaration_Cast());

    public AStart ()
    {
    }

    public AStart (
            PHeader _header_,
            List _declaration_
    )
    {
        setHeader (_header_);
        this._declaration_.clear();
        this._declaration_.addAll(_declaration_);
    }

    public Object clone()
    {
        return new AStart (
            (PHeader)cloneNode (_header_),
            cloneList (_declaration_)
        );
    }

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

    public PHeader getHeader ()
    {
        return _header_;
    }

    public void setHeader (PHeader node)
    {
        if(_header_ != null)
        {
            _header_.parent(null);
        }

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

            node.parent(this);
        }

        _header_ = node;
    }
    public LinkedList getDeclaration ()
    {
        return _declaration_;
    }

    public void setDeclaration (List list)
    {
        _declaration_.clear();
        _declaration_.addAll(list);
    }

    public String toString()
    {
        return ""
            + toString (_header_)
            + toString (_declaration_)
        ;
    }

    void removeChild(Node child)
    {
        if ( _header_ == child )
        {
            _header_ = null;
            return;
        }
        if ( _declaration_.remove(child))
        {
            return;
        }
    }

    void replaceChild(Node oldChild, Node newChild)
    {
        if ( _header_ == oldChild )
        {
            setHeader ((PHeader) newChild);
            return;
        }
        for(ListIterator i = _declaration_.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 Declaration_Cast implements Cast
    {
        public Object cast(Object o)
        {
            PDeclaration node = (PDeclaration) o;

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

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

            return node;
        }
    }
}
