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

package se.sics.kola.node;

import se.sics.kola.analysis.*;

@SuppressWarnings("nls")
public final class AIfThenStatement extends PIfThenStatement
{
    private PExpression _cond_;
    private PStatement _then_;

    public AIfThenStatement()
    {
        // Constructor
    }

    public AIfThenStatement(
        @SuppressWarnings("hiding") PExpression _cond_,
        @SuppressWarnings("hiding") PStatement _then_)
    {
        // Constructor
        setCond(_cond_);

        setThen(_then_);

    }

    @Override
    public Object clone()
    {
        return new AIfThenStatement(
            cloneNode(this._cond_),
            cloneNode(this._then_));
    }

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

    public PExpression getCond()
    {
        return this._cond_;
    }

    public void setCond(PExpression node)
    {
        if(this._cond_ != null)
        {
            this._cond_.parent(null);
        }

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

            node.parent(this);
        }

        this._cond_ = node;
    }

    public PStatement getThen()
    {
        return this._then_;
    }

    public void setThen(PStatement node)
    {
        if(this._then_ != null)
        {
            this._then_.parent(null);
        }

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

            node.parent(this);
        }

        this._then_ = node;
    }

    @Override
    public String toString()
    {
        return ""
            + toString(this._cond_)
            + toString(this._then_);
    }

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

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

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

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

        if(this._then_ == oldChild)
        {
            setThen((PStatement) newChild);
            return;
        }

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