/* 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 AClassDecl extends PClassDecl
{
    private TTclass _tclass_;
    private TIdentifier _classname_;
    private TExtends _extends_;
    private TIdentifier _extendsname_;
    private TLBrace _lBrace_;
    private final LinkedList _fieldDecl_ = new TypedLinkedList(new FieldDecl_Cast());
    private PConstructorDecl _constructorDecl_;
    private final LinkedList _methodDecl_ = new TypedLinkedList(new MethodDecl_Cast());
    private TRBrace _rBrace_;

    public AClassDecl()
    {
    }

    public AClassDecl(
        TTclass _tclass_,
        TIdentifier _classname_,
        TExtends _extends_,
        TIdentifier _extendsname_,
        TLBrace _lBrace_,
        List _fieldDecl_,
        PConstructorDecl _constructorDecl_,
        List _methodDecl_,
        TRBrace _rBrace_)
    {
        setTclass(_tclass_);

        setClassname(_classname_);

        setExtends(_extends_);

        setExtendsname(_extendsname_);

        setLBrace(_lBrace_);

        {
            this._fieldDecl_.clear();
            this._fieldDecl_.addAll(_fieldDecl_);
        }

        setConstructorDecl(_constructorDecl_);

        {
            this._methodDecl_.clear();
            this._methodDecl_.addAll(_methodDecl_);
        }

        setRBrace(_rBrace_);

    }

    public AClassDecl(
        TTclass _tclass_,
        TIdentifier _classname_,
        TExtends _extends_,
        TIdentifier _extendsname_,
        TLBrace _lBrace_,
        XPFieldDecl _fieldDecl_,
        PConstructorDecl _constructorDecl_,
        XPMethodDecl _methodDecl_,
        TRBrace _rBrace_)
    {
        setTclass(_tclass_);

        setClassname(_classname_);

        setExtends(_extends_);

        setExtendsname(_extendsname_);

        setLBrace(_lBrace_);

        if(_fieldDecl_ != null)
        {
            while(_fieldDecl_ instanceof X1PFieldDecl)
            {
                this._fieldDecl_.addFirst(((X1PFieldDecl) _fieldDecl_).getPFieldDecl());
                _fieldDecl_ = ((X1PFieldDecl) _fieldDecl_).getXPFieldDecl();
            }
            this._fieldDecl_.addFirst(((X2PFieldDecl) _fieldDecl_).getPFieldDecl());
        }

        setConstructorDecl(_constructorDecl_);

        if(_methodDecl_ != null)
        {
            while(_methodDecl_ instanceof X1PMethodDecl)
            {
                this._methodDecl_.addFirst(((X1PMethodDecl) _methodDecl_).getPMethodDecl());
                _methodDecl_ = ((X1PMethodDecl) _methodDecl_).getXPMethodDecl();
            }
            this._methodDecl_.addFirst(((X2PMethodDecl) _methodDecl_).getPMethodDecl());
        }

        setRBrace(_rBrace_);

    }
    public Object clone()
    {
        return new AClassDecl(
            (TTclass) cloneNode(_tclass_),
            (TIdentifier) cloneNode(_classname_),
            (TExtends) cloneNode(_extends_),
            (TIdentifier) cloneNode(_extendsname_),
            (TLBrace) cloneNode(_lBrace_),
            cloneList(_fieldDecl_),
            (PConstructorDecl) cloneNode(_constructorDecl_),
            cloneList(_methodDecl_),
            (TRBrace) cloneNode(_rBrace_));
    }

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

    public TTclass getTclass()
    {
        return _tclass_;
    }

    public void setTclass(TTclass node)
    {
        if(_tclass_ != null)
        {
            _tclass_.parent(null);
        }

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

            node.parent(this);
        }

        _tclass_ = node;
    }

    public TIdentifier getClassname()
    {
        return _classname_;
    }

    public void setClassname(TIdentifier node)
    {
        if(_classname_ != null)
        {
            _classname_.parent(null);
        }

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

            node.parent(this);
        }

        _classname_ = node;
    }

    public TExtends getExtends()
    {
        return _extends_;
    }

    public void setExtends(TExtends node)
    {
        if(_extends_ != null)
        {
            _extends_.parent(null);
        }

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

            node.parent(this);
        }

        _extends_ = node;
    }

    public TIdentifier getExtendsname()
    {
        return _extendsname_;
    }

    public void setExtendsname(TIdentifier node)
    {
        if(_extendsname_ != null)
        {
            _extendsname_.parent(null);
        }

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

            node.parent(this);
        }

        _extendsname_ = node;
    }

    public TLBrace getLBrace()
    {
        return _lBrace_;
    }

    public void setLBrace(TLBrace node)
    {
        if(_lBrace_ != null)
        {
            _lBrace_.parent(null);
        }

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

            node.parent(this);
        }

        _lBrace_ = node;
    }

    public LinkedList getFieldDecl()
    {
        return _fieldDecl_;
    }

    public void setFieldDecl(List list)
    {
        _fieldDecl_.clear();
        _fieldDecl_.addAll(list);
    }

    public PConstructorDecl getConstructorDecl()
    {
        return _constructorDecl_;
    }

    public void setConstructorDecl(PConstructorDecl node)
    {
        if(_constructorDecl_ != null)
        {
            _constructorDecl_.parent(null);
        }

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

            node.parent(this);
        }

        _constructorDecl_ = node;
    }

    public LinkedList getMethodDecl()
    {
        return _methodDecl_;
    }

    public void setMethodDecl(List list)
    {
        _methodDecl_.clear();
        _methodDecl_.addAll(list);
    }

    public TRBrace getRBrace()
    {
        return _rBrace_;
    }

    public void setRBrace(TRBrace node)
    {
        if(_rBrace_ != null)
        {
            _rBrace_.parent(null);
        }

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

            node.parent(this);
        }

        _rBrace_ = node;
    }

    public String toString()
    {
        return ""
            + toString(_tclass_)
            + toString(_classname_)
            + toString(_extends_)
            + toString(_extendsname_)
            + toString(_lBrace_)
            + toString(_fieldDecl_)
            + toString(_constructorDecl_)
            + toString(_methodDecl_)
            + toString(_rBrace_);
    }

    void removeChild(Node child)
    {
        if(_tclass_ == child)
        {
            _tclass_ = null;
            return;
        }

        if(_classname_ == child)
        {
            _classname_ = null;
            return;
        }

        if(_extends_ == child)
        {
            _extends_ = null;
            return;
        }

        if(_extendsname_ == child)
        {
            _extendsname_ = null;
            return;
        }

        if(_lBrace_ == child)
        {
            _lBrace_ = null;
            return;
        }

        if(_fieldDecl_.remove(child))
        {
            return;
        }

        if(_constructorDecl_ == child)
        {
            _constructorDecl_ = null;
            return;
        }

        if(_methodDecl_.remove(child))
        {
            return;
        }

        if(_rBrace_ == child)
        {
            _rBrace_ = null;
            return;
        }

    }

    void replaceChild(Node oldChild, Node newChild)
    {
        if(_tclass_ == oldChild)
        {
            setTclass((TTclass) newChild);
            return;
        }

        if(_classname_ == oldChild)
        {
            setClassname((TIdentifier) newChild);
            return;
        }

        if(_extends_ == oldChild)
        {
            setExtends((TExtends) newChild);
            return;
        }

        if(_extendsname_ == oldChild)
        {
            setExtendsname((TIdentifier) newChild);
            return;
        }

        if(_lBrace_ == oldChild)
        {
            setLBrace((TLBrace) newChild);
            return;
        }

        for(ListIterator i = _fieldDecl_.listIterator(); i.hasNext();)
        {
            if(i.next() == oldChild)
            {
                if(newChild != null)
                {
                    i.set(newChild);
                    oldChild.parent(null);
                    return;
                }

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

        if(_constructorDecl_ == oldChild)
        {
            setConstructorDecl((PConstructorDecl) newChild);
            return;
        }

        for(ListIterator i = _methodDecl_.listIterator(); i.hasNext();)
        {
            if(i.next() == oldChild)
            {
                if(newChild != null)
                {
                    i.set(newChild);
                    oldChild.parent(null);
                    return;
                }

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

        if(_rBrace_ == oldChild)
        {
            setRBrace((TRBrace) newChild);
            return;
        }

    }

    private class FieldDecl_Cast implements Cast
    {
        public Object cast(Object o)
        {
            PFieldDecl node = (PFieldDecl) o;

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

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

            return node;
        }
    }

    private class MethodDecl_Cast implements Cast
    {
        public Object cast(Object o)
        {
            PMethodDecl node = (PMethodDecl) o;

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

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

            return node;
        }
    }
}
