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

AOldCompilationUnit.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 AOldCompilationUnit extends PCompilationUnit
00040 {
00041     private PPackageDeclaration _packageDeclaration_;
00042     private final LinkedList _importDeclaration_ = new TypedLinkedList(new ImportDeclaration_Cast());
00043     private final LinkedList _typeDeclaration_ = new TypedLinkedList(new TypeDeclaration_Cast());
00044 
00045     private class ImportDeclaration_Cast implements Cast
00046     {
00047         public Object cast(Object o)
00048         {
00049             PImportDeclaration node = (PImportDeclaration) o;
00050 
00051             if((node.parent() != null) &&
00052                 (node.parent() != AOldCompilationUnit.this))
00053             {
00054                 node.parent().removeChild(node);
00055             }
00056 
00057             if((node.parent() == null) ||
00058                 (node.parent() != AOldCompilationUnit.this))
00059             {
00060                 node.parent(AOldCompilationUnit.this);
00061             }
00062 
00063             return node;
00064         }
00065     }
00066 
00067     private class TypeDeclaration_Cast implements Cast
00068     {
00069         public Object cast(Object o)
00070         {
00071             PTypeDeclaration node = (PTypeDeclaration) o;
00072 
00073             if((node.parent() != null) &&
00074                 (node.parent() != AOldCompilationUnit.this))
00075             {
00076                 node.parent().removeChild(node);
00077             }
00078 
00079             if((node.parent() == null) ||
00080                 (node.parent() != AOldCompilationUnit.this))
00081             {
00082                 node.parent(AOldCompilationUnit.this);
00083             }
00084 
00085             return node;
00086         }
00087     }
00088     public AOldCompilationUnit()
00089     {
00090     }
00091     public AOldCompilationUnit(
00092         PPackageDeclaration _packageDeclaration_,
00093         List _importDeclaration_,
00094         List _typeDeclaration_)
00095     {
00096         setPackageDeclaration(_packageDeclaration_);
00097 
00098         {
00099             Object temp[] = _importDeclaration_.toArray();
00100             for(int i = 0; i < temp.length; i++)
00101             {
00102                 this._importDeclaration_.add(temp[i]);
00103             }
00104         }
00105 
00106         {
00107             Object temp[] = _typeDeclaration_.toArray();
00108             for(int i = 0; i < temp.length; i++)
00109             {
00110                 this._typeDeclaration_.add(temp[i]);
00111             }
00112         }
00113 
00114     }
00115     public AOldCompilationUnit(
00116         PPackageDeclaration _packageDeclaration_,
00117         XPImportDeclaration _importDeclaration_,
00118         XPTypeDeclaration _typeDeclaration_)
00119     {
00120         setPackageDeclaration(_packageDeclaration_);
00121 
00122         if(_importDeclaration_ != null)
00123         {
00124             while(_importDeclaration_ instanceof X1PImportDeclaration)
00125             {
00126                 this._importDeclaration_.addFirst(((X1PImportDeclaration) _importDeclaration_).getPImportDeclaration());
00127                 _importDeclaration_ = ((X1PImportDeclaration) _importDeclaration_).getXPImportDeclaration();
00128             }
00129             this._importDeclaration_.addFirst(((X2PImportDeclaration) _importDeclaration_).getPImportDeclaration());
00130         }
00131 
00132         if(_typeDeclaration_ != null)
00133         {
00134             while(_typeDeclaration_ instanceof X1PTypeDeclaration)
00135             {
00136                 this._typeDeclaration_.addFirst(((X1PTypeDeclaration) _typeDeclaration_).getPTypeDeclaration());
00137                 _typeDeclaration_ = ((X1PTypeDeclaration) _typeDeclaration_).getXPTypeDeclaration();
00138             }
00139             this._typeDeclaration_.addFirst(((X2PTypeDeclaration) _typeDeclaration_).getPTypeDeclaration());
00140         }
00141 
00142     }
00143     public void apply(Switch sw)
00144     {
00145         ((Analysis) sw).caseAOldCompilationUnit(this);
00146     }
00147     public Object clone()
00148     {
00149         return new AOldCompilationUnit(
00150             (PPackageDeclaration) cloneNode(_packageDeclaration_),
00151             cloneList(_importDeclaration_),
00152             cloneList(_typeDeclaration_));
00153     }
00154     public LinkedList getImportDeclaration()
00155     {
00156         return _importDeclaration_;
00157     }
00158     public PPackageDeclaration getPackageDeclaration()
00159     {
00160         return _packageDeclaration_;
00161     }
00162     public LinkedList getTypeDeclaration()
00163     {
00164         return _typeDeclaration_;
00165     }
00166     void removeChild(Node child)
00167     {
00168         if(_packageDeclaration_ == child)
00169         {
00170             _packageDeclaration_ = null;
00171             return;
00172         }
00173 
00174         if(_importDeclaration_.remove(child))
00175         {
00176             return;
00177         }
00178 
00179         if(_typeDeclaration_.remove(child))
00180         {
00181             return;
00182         }
00183 
00184     }
00185     void replaceChild(Node oldChild, Node newChild)
00186     {
00187         if(_packageDeclaration_ == oldChild)
00188         {
00189             setPackageDeclaration((PPackageDeclaration) newChild);
00190             return;
00191         }
00192 
00193         for(ListIterator i = _importDeclaration_.listIterator(); i.hasNext();)
00194         {
00195             if(i.next() == oldChild)
00196             {
00197                 if(newChild != null)
00198                 {
00199                     i.set(newChild);
00200                     oldChild.parent(null);
00201                     return;
00202                 }
00203 
00204                 i.remove();
00205                 oldChild.parent(null);
00206                 return;
00207             }
00208         }
00209 
00210         for(ListIterator i = _typeDeclaration_.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 setImportDeclaration(List list)
00229     {
00230         Object temp[] = list.toArray();
00231         for(int i = 0; i < temp.length; i++)
00232         {
00233             _importDeclaration_.add(temp[i]);
00234         }
00235     }
00236     public void setPackageDeclaration(PPackageDeclaration node)
00237     {
00238         if(_packageDeclaration_ != null)
00239         {
00240             _packageDeclaration_.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         _packageDeclaration_ = node;
00254     }
00255     public void setTypeDeclaration(List list)
00256     {
00257         Object temp[] = list.toArray();
00258         for(int i = 0; i < temp.length; i++)
00259         {
00260             _typeDeclaration_.add(temp[i]);
00261         }
00262     }
00263     public String toString()
00264     {
00265         return ""
00266             + toString(_packageDeclaration_)
00267             + toString(_importDeclaration_)
00268             + toString(_typeDeclaration_);
00269     }
00270 }

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