Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

AMethodDeclarator.java

00001 package edu.ksu.cis.bandera.jjjc.node;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1998-2001 SAnToS Laboratories (santos@cis.ksu.edu)  *
00006 
00007  * All rights reserved.                                              *
00008  *                                                                   *
00009  * This work was done as a project in the SAnToS Laboratory,         *
00010  * Department of Computing and Information Sciences, Kansas State    *
00011  * University, USA (http://www.cis.ksu.edu/santos).                  *
00012  * It is understood that any modification not identified as such is  *
00013  * not covered by the preceding statement.                           *
00014  *                                                                   *
00015  * This work is free software; you can redistribute it and/or        *
00016  * modify it under the terms of the GNU Library General Public       *
00017  * License as published by the Free Software Foundation; either      *
00018  * version 2 of the License, or (at your option) any later version.  *
00019  *                                                                   *
00020  * This work is distributed in the hope that it will be useful,      *
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00023  * Library General Public License for more details.                  *
00024  *                                                                   *
00025  * You should have received a copy of the GNU Library General Public *
00026  * License along with this toolkit; if not, write to the             *
00027  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00028  * Boston, MA  02111-1307, USA.                                      *
00029  *                                                                   *
00030  * Java is a trademark of Sun Microsystems, Inc.                     *
00031  *                                                                   *
00032  * To submit a bug report, send a comment, or get the latest news on *
00033  * this project and other SAnToS projects, please visit the web-site *
00034  *                http://www.cis.ksu.edu/santos                      *
00035  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00036 import ca.mcgill.sable.util.*;
00037 import edu.ksu.cis.bandera.jjjc.analysis.*;
00038 
00039 public final class AMethodDeclarator extends PMethodDeclarator
00040 {
00041     private TId _id_;
00042     private TLPar _lPar_;
00043     private final LinkedList _formalParameter_ = new TypedLinkedList(new FormalParameter_Cast());
00044     private TRPar _rPar_;
00045     private final LinkedList _dim_ = new TypedLinkedList(new Dim_Cast());
00046 
00047     private class FormalParameter_Cast implements Cast
00048     {
00049         public Object cast(Object o)
00050         {
00051             PFormalParameter node = (PFormalParameter) o;
00052 
00053             if((node.parent() != null) &&
00054                 (node.parent() != AMethodDeclarator.this))
00055             {
00056                 node.parent().removeChild(node);
00057             }
00058 
00059             if((node.parent() == null) ||
00060                 (node.parent() != AMethodDeclarator.this))
00061             {
00062                 node.parent(AMethodDeclarator.this);
00063             }
00064 
00065             return node;
00066         }
00067     }
00068 
00069     private class Dim_Cast implements Cast
00070     {
00071         public Object cast(Object o)
00072         {
00073             PDim node = (PDim) o;
00074 
00075             if((node.parent() != null) &&
00076                 (node.parent() != AMethodDeclarator.this))
00077             {
00078                 node.parent().removeChild(node);
00079             }
00080 
00081             if((node.parent() == null) ||
00082                 (node.parent() != AMethodDeclarator.this))
00083             {
00084                 node.parent(AMethodDeclarator.this);
00085             }
00086 
00087             return node;
00088         }
00089     }
00090     public AMethodDeclarator()
00091     {
00092     }
00093     public AMethodDeclarator(
00094         TId _id_,
00095         TLPar _lPar_,
00096         List _formalParameter_,
00097         TRPar _rPar_,
00098         List _dim_)
00099     {
00100         setId(_id_);
00101 
00102         setLPar(_lPar_);
00103 
00104         {
00105             Object temp[] = _formalParameter_.toArray();
00106             for(int i = 0; i < temp.length; i++)
00107             {
00108                 this._formalParameter_.add(temp[i]);
00109             }
00110         }
00111 
00112         setRPar(_rPar_);
00113 
00114         {
00115             Object temp[] = _dim_.toArray();
00116             for(int i = 0; i < temp.length; i++)
00117             {
00118                 this._dim_.add(temp[i]);
00119             }
00120         }
00121 
00122     }
00123     public AMethodDeclarator(
00124         TId _id_,
00125         TLPar _lPar_,
00126         XPFormalParameter _formalParameter_,
00127         TRPar _rPar_,
00128         XPDim _dim_)
00129     {
00130         setId(_id_);
00131 
00132         setLPar(_lPar_);
00133 
00134         if(_formalParameter_ != null)
00135         {
00136             while(_formalParameter_ instanceof X1PFormalParameter)
00137             {
00138                 this._formalParameter_.addFirst(((X1PFormalParameter) _formalParameter_).getPFormalParameter());
00139                 _formalParameter_ = ((X1PFormalParameter) _formalParameter_).getXPFormalParameter();
00140             }
00141             this._formalParameter_.addFirst(((X2PFormalParameter) _formalParameter_).getPFormalParameter());
00142         }
00143 
00144         setRPar(_rPar_);
00145 
00146         if(_dim_ != null)
00147         {
00148             while(_dim_ instanceof X1PDim)
00149             {
00150                 this._dim_.addFirst(((X1PDim) _dim_).getPDim());
00151                 _dim_ = ((X1PDim) _dim_).getXPDim();
00152             }
00153             this._dim_.addFirst(((X2PDim) _dim_).getPDim());
00154         }
00155 
00156     }
00157     public void apply(Switch sw)
00158     {
00159         ((Analysis) sw).caseAMethodDeclarator(this);
00160     }
00161     public Object clone()
00162     {
00163         return new AMethodDeclarator(
00164             (TId) cloneNode(_id_),
00165             (TLPar) cloneNode(_lPar_),
00166             cloneList(_formalParameter_),
00167             (TRPar) cloneNode(_rPar_),
00168             cloneList(_dim_));
00169     }
00170     public LinkedList getDim()
00171     {
00172         return _dim_;
00173     }
00174     public LinkedList getFormalParameter()
00175     {
00176         return _formalParameter_;
00177     }
00178     public TId getId()
00179     {
00180         return _id_;
00181     }
00182     public TLPar getLPar()
00183     {
00184         return _lPar_;
00185     }
00186     public TRPar getRPar()
00187     {
00188         return _rPar_;
00189     }
00190     void removeChild(Node child)
00191     {
00192         if(_id_ == child)
00193         {
00194             _id_ = null;
00195             return;
00196         }
00197 
00198         if(_lPar_ == child)
00199         {
00200             _lPar_ = null;
00201             return;
00202         }
00203 
00204         if(_formalParameter_.remove(child))
00205         {
00206             return;
00207         }
00208 
00209         if(_rPar_ == child)
00210         {
00211             _rPar_ = null;
00212             return;
00213         }
00214 
00215         if(_dim_.remove(child))
00216         {
00217             return;
00218         }
00219 
00220     }
00221     void replaceChild(Node oldChild, Node newChild)
00222     {
00223         if(_id_ == oldChild)
00224         {
00225             setId((TId) newChild);
00226             return;
00227         }
00228 
00229         if(_lPar_ == oldChild)
00230         {
00231             setLPar((TLPar) newChild);
00232             return;
00233         }
00234 
00235         for(ListIterator i = _formalParameter_.listIterator(); i.hasNext();)
00236         {
00237             if(i.next() == oldChild)
00238             {
00239                 if(newChild != null)
00240                 {
00241                     i.set(newChild);
00242                     oldChild.parent(null);
00243                     return;
00244                 }
00245 
00246                 i.remove();
00247                 oldChild.parent(null);
00248                 return;
00249             }
00250         }
00251 
00252         if(_rPar_ == oldChild)
00253         {
00254             setRPar((TRPar) newChild);
00255             return;
00256         }
00257 
00258         for(ListIterator i = _dim_.listIterator(); i.hasNext();)
00259         {
00260             if(i.next() == oldChild)
00261             {
00262                 if(newChild != null)
00263                 {
00264                     i.set(newChild);
00265                     oldChild.parent(null);
00266                     return;
00267                 }
00268 
00269                 i.remove();
00270                 oldChild.parent(null);
00271                 return;
00272             }
00273         }
00274 
00275     }
00276     public void setDim(List list)
00277     {
00278         Object temp[] = list.toArray();
00279         for(int i = 0; i < temp.length; i++)
00280         {
00281             _dim_.add(temp[i]);
00282         }
00283     }
00284     public void setFormalParameter(List list)
00285     {
00286         Object temp[] = list.toArray();
00287         for(int i = 0; i < temp.length; i++)
00288         {
00289             _formalParameter_.add(temp[i]);
00290         }
00291     }
00292     public void setId(TId node)
00293     {
00294         if(_id_ != null)
00295         {
00296             _id_.parent(null);
00297         }
00298 
00299         if(node != null)
00300         {
00301             if(node.parent() != null)
00302             {
00303                 node.parent().removeChild(node);
00304             }
00305 
00306             node.parent(this);
00307         }
00308 
00309         _id_ = node;
00310     }
00311     public void setLPar(TLPar node)
00312     {
00313         if(_lPar_ != null)
00314         {
00315             _lPar_.parent(null);
00316         }
00317 
00318         if(node != null)
00319         {
00320             if(node.parent() != null)
00321             {
00322                 node.parent().removeChild(node);
00323             }
00324 
00325             node.parent(this);
00326         }
00327 
00328         _lPar_ = node;
00329     }
00330     public void setRPar(TRPar node)
00331     {
00332         if(_rPar_ != null)
00333         {
00334             _rPar_.parent(null);
00335         }
00336 
00337         if(node != null)
00338         {
00339             if(node.parent() != null)
00340             {
00341                 node.parent().removeChild(node);
00342             }
00343 
00344             node.parent(this);
00345         }
00346 
00347         _rPar_ = node;
00348     }
00349     public String toString()
00350     {
00351         return ""
00352             + toString(_id_)
00353             + toString(_lPar_)
00354             + toString(_formalParameter_)
00355             + toString(_rPar_)
00356             + toString(_dim_);
00357     }
00358 }

Generated at Thu Feb 7 06:37:51 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001