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

package com.google.clearsilver.jsilver.syntax.node;

import com.google.clearsilver.jsilver.syntax.analysis.*;

@SuppressWarnings("nls")
public final class AIfCommand extends PCommand
{
    private PPosition _position_;
    private PExpression _expression_;
    private PCommand _block_;
    private PCommand _otherwise_;

    public AIfCommand()
    {
        // Constructor
    }

    public AIfCommand(
        @SuppressWarnings("hiding") PPosition _position_,
        @SuppressWarnings("hiding") PExpression _expression_,
        @SuppressWarnings("hiding") PCommand _block_,
        @SuppressWarnings("hiding") PCommand _otherwise_)
    {
        // Constructor
        setPosition(_position_);

        setExpression(_expression_);

        setBlock(_block_);

        setOtherwise(_otherwise_);

    }

    @Override
    public Object clone()
    {
        return new AIfCommand(
            cloneNode(this._position_),
            cloneNode(this._expression_),
            cloneNode(this._block_),
            cloneNode(this._otherwise_));
    }

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

    public PPosition getPosition()
    {
        return this._position_;
    }

    public void setPosition(PPosition node)
    {
        if(this._position_ != null)
        {
            this._position_.parent(null);
        }

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

            node.parent(this);
        }

        this._position_ = node;
    }

    public PExpression getExpression()
    {
        return this._expression_;
    }

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

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

            node.parent(this);
        }

        this._expression_ = node;
    }

    public PCommand getBlock()
    {
        return this._block_;
    }

    public void setBlock(PCommand node)
    {
        if(this._block_ != null)
        {
            this._block_.parent(null);
        }

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

            node.parent(this);
        }

        this._block_ = node;
    }

    public PCommand getOtherwise()
    {
        return this._otherwise_;
    }

    public void setOtherwise(PCommand node)
    {
        if(this._otherwise_ != null)
        {
            this._otherwise_.parent(null);
        }

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

            node.parent(this);
        }

        this._otherwise_ = node;
    }

    @Override
    public String toString()
    {
        return ""
            + toString(this._position_)
            + toString(this._expression_)
            + toString(this._block_)
            + toString(this._otherwise_);
    }

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

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

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

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

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

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

        if(this._expression_ == oldChild)
        {
            setExpression((PExpression) newChild);
            return;
        }

        if(this._block_ == oldChild)
        {
            setBlock((PCommand) newChild);
            return;
        }

        if(this._otherwise_ == oldChild)
        {
            setOtherwise((PCommand) newChild);
            return;
        }

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