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

ALocalVariableDeclaration.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 ALocalVariableDeclaration extends PLocalVariableDeclaration
00040 {
00041     private final LinkedList _modifier_ = new TypedLinkedList(new Modifier_Cast());
00042     private PType _type_;
00043     private final LinkedList _variableDeclarator_ = new TypedLinkedList(new VariableDeclarator_Cast());
00044 
00045     private class Modifier_Cast implements Cast
00046     {
00047         public Object cast(Object o)
00048         {
00049             PModifier node = (PModifier) o;
00050 
00051             if((node.parent() != null) &&
00052                 (node.parent() != ALocalVariableDeclaration.this))
00053             {
00054                 node.parent().removeChild(node);
00055             }
00056 
00057             if((node.parent() == null) ||
00058                 (node.parent() != ALocalVariableDeclaration.this))
00059             {
00060                 node.parent(ALocalVariableDeclaration.this);
00061             }
00062 
00063             return node;
00064         }
00065     }
00066 
00067     private class VariableDeclarator_Cast implements Cast
00068     {
00069         public Object cast(Object o)
00070         {
00071             PVariableDeclarator node = (PVariableDeclarator) o;
00072 
00073             if((node.parent() != null) &&
00074                 (node.parent() != ALocalVariableDeclaration.this))
00075             {
00076                 node.parent().removeChild(node);
00077             }
00078 
00079             if((node.parent() == null) ||
00080                 (node.parent() != ALocalVariableDeclaration.this))
00081             {
00082                 node.parent(ALocalVariableDeclaration.this);
00083             }
00084 
00085             return node;
00086         }
00087     }
00088     public ALocalVariableDeclaration()
00089     {
00090     }
00091     public ALocalVariableDeclaration(
00092         List _modifier_,
00093         PType _type_,
00094         List _variableDeclarator_)
00095     {
00096         {
00097             Object temp[] = _modifier_.toArray();
00098             for(int i = 0; i < temp.length; i++)
00099             {
00100                 this._modifier_.add(temp[i]);
00101             }
00102         }
00103 
00104         setType(_type_);
00105 
00106         {
00107             Object temp[] = _variableDeclarator_.toArray();
00108             for(int i = 0; i < temp.length; i++)
00109             {
00110                 this._variableDeclarator_.add(temp[i]);
00111             }
00112         }
00113 
00114     }
00115     public ALocalVariableDeclaration(
00116         XPModifier _modifier_,
00117         PType _type_,
00118         XPVariableDeclarator _variableDeclarator_)
00119     {
00120         if(_modifier_ != null)
00121         {
00122             while(_modifier_ instanceof X1PModifier)
00123             {
00124                 this._modifier_.addFirst(((X1PModifier) _modifier_).getPModifier());
00125                 _modifier_ = ((X1PModifier) _modifier_).getXPModifier();
00126             }
00127             this._modifier_.addFirst(((X2PModifier) _modifier_).getPModifier());
00128         }
00129 
00130         setType(_type_);
00131 
00132         if(_variableDeclarator_ != null)
00133         {
00134             while(_variableDeclarator_ instanceof X1PVariableDeclarator)
00135             {
00136                 this._variableDeclarator_.addFirst(((X1PVariableDeclarator) _variableDeclarator_).getPVariableDeclarator());
00137                 _variableDeclarator_ = ((X1PVariableDeclarator) _variableDeclarator_).getXPVariableDeclarator();
00138             }
00139             this._variableDeclarator_.addFirst(((X2PVariableDeclarator) _variableDeclarator_).getPVariableDeclarator());
00140         }
00141 
00142     }
00143     public void apply(Switch sw)
00144     {
00145         ((Analysis) sw).caseALocalVariableDeclaration(this);
00146     }
00147     public Object clone()
00148     {
00149         return new ALocalVariableDeclaration(
00150             cloneList(_modifier_),
00151             (PType) cloneNode(_type_),
00152             cloneList(_variableDeclarator_));
00153     }
00154     public LinkedList getModifier()
00155     {
00156         return _modifier_;
00157     }
00158     public PType getType()
00159     {
00160         return _type_;
00161     }
00162     public LinkedList getVariableDeclarator()
00163     {
00164         return _variableDeclarator_;
00165     }
00166     void removeChild(Node child)
00167     {
00168         if(_modifier_.remove(child))
00169         {
00170             return;
00171         }
00172 
00173         if(_type_ == child)
00174         {
00175             _type_ = null;
00176             return;
00177         }
00178 
00179         if(_variableDeclarator_.remove(child))
00180         {
00181             return;
00182         }
00183 
00184     }
00185     void replaceChild(Node oldChild, Node newChild)
00186     {
00187         for(ListIterator i = _modifier_.listIterator(); i.hasNext();)
00188         {
00189             if(i.next() == oldChild)
00190             {
00191                 if(newChild != null)
00192                 {
00193                     i.set(newChild);
00194                     oldChild.parent(null);
00195                     return;
00196                 }
00197 
00198                 i.remove();
00199                 oldChild.parent(null);
00200                 return;
00201             }
00202         }
00203 
00204         if(_type_ == oldChild)
00205         {
00206             setType((PType) newChild);
00207             return;
00208         }
00209 
00210         for(ListIterator i = _variableDeclarator_.listIterator(); i.hasNext();)
00211         {
00212             if(i.next() == oldChild)
00213             {
00214                 if(newChild != null)
00215                 {
00216                     i.set(newChild);
00217                     oldChild.parent(null);
00218                     return;
00219                 }
00220 
00221                 i.remove();
00222                 oldChild.parent(null);
00223                 return;
00224             }
00225         }
00226 
00227     }
00228     public void setModifier(List list)
00229     {
00230         Object temp[] = list.toArray();
00231         for(int i = 0; i < temp.length; i++)
00232         {
00233             _modifier_.add(temp[i]);
00234         }
00235     }
00236     public void setType(PType node)
00237     {
00238         if(_type_ != null)
00239         {
00240             _type_.parent(null);
00241         }
00242 
00243         if(node != null)
00244         {
00245             if(node.parent() != null)
00246             {
00247                 node.parent().removeChild(node);
00248             }
00249 
00250             node.parent(this);
00251         }
00252 
00253         _type_ = node;
00254     }
00255     public void setVariableDeclarator(List list)
00256     {
00257         Object temp[] = list.toArray();
00258         for(int i = 0; i < temp.length; i++)
00259         {
00260             _variableDeclarator_.add(temp[i]);
00261         }
00262     }
00263     public String toString()
00264     {
00265         return ""
00266             + toString(_modifier_)
00267             + toString(_type_)
00268             + toString(_variableDeclarator_);
00269     }
00270 }

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