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

package org.sablecc.sablecc.node;

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

@SuppressWarnings("nls")
public final class ANewTerm extends PTerm
{
    private PProdName _prodName_;
    private TLPar _lPar_;
    private final LinkedList<PTerm> _params_ = new LinkedList<PTerm>();

    public ANewTerm()
    {
        // Constructor
    }

    public ANewTerm(
        @SuppressWarnings("hiding") PProdName _prodName_,
        @SuppressWarnings("hiding") TLPar _lPar_,
        @SuppressWarnings("hiding") List<?> _params_)
    {
        // Constructor
        setProdName(_prodName_);

        setLPar(_lPar_);

        setParams(_params_);

    }

    @Override
    public Object clone()
    {
        return new ANewTerm(
            cloneNode(this._prodName_),
            cloneNode(this._lPar_),
            cloneList(this._params_));
    }

    @Override
    public void apply(Switch sw)
    {
        ((Analysis) sw).caseANewTerm(this);
    }

    public PProdName getProdName()
    {
        return this._prodName_;
    }

    public void setProdName(PProdName node)
    {
        if(this._prodName_ != null)
        {
            this._prodName_.parent(null);
        }

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

            node.parent(this);
        }

        this._prodName_ = node;
    }

    public TLPar getLPar()
    {
        return this._lPar_;
    }

    public void setLPar(TLPar node)
    {
        if(this._lPar_ != null)
        {
            this._lPar_.parent(null);
        }

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

            node.parent(this);
        }

        this._lPar_ = node;
    }

    public LinkedList<PTerm> getParams()
    {
        return this._params_;
    }

    public void setParams(List<?> list)
    {
        for(PTerm e : this._params_)
        {
            e.parent(null);
        }
        this._params_.clear();

        for(Object obj_e : list)
        {
            PTerm e = (PTerm) obj_e;
            if(e.parent() != null)
            {
                e.parent().removeChild(e);
            }

            e.parent(this);
            this._params_.add(e);
        }
    }

    @Override
    public String toString()
    {
        return ""
            + toString(this._prodName_)
            + toString(this._lPar_)
            + toString(this._params_);
    }

    @Override
    void removeChild(@SuppressWarnings("unused") Node child)
    {
        // Remove child
        if(this._prodName_ == child)
        {
            this._prodName_ = null;
            return;
        }

        if(this._lPar_ == child)
        {
            this._lPar_ = null;
            return;
        }

        if(this._params_.remove(child))
        {
            return;
        }

        throw new RuntimeException("Not a child.");
    }

    @Override
    void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild)
    {
        // Replace child
        if(this._prodName_ == oldChild)
        {
            setProdName((PProdName) newChild);
            return;
        }

        if(this._lPar_ == oldChild)
        {
            setLPar((TLPar) newChild);
            return;
        }

        for(ListIterator<PTerm> i = this._params_.listIterator(); i.hasNext();)
        {
            if(i.next() == oldChild)
            {
                if(newChild != null)
                {
                    i.set((PTerm) newChild);
                    newChild.parent(this);
                    oldChild.parent(null);
                    return;
                }

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

        throw new RuntimeException("Not a child.");
    }
}
