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

ACompilationUnit.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 ACompilationUnit extends PCompilationUnit
00040 {
00041     private TPackage _package_;
00042     private PName _packageDeclaration_;
00043     private TSemicolon _semicolon_;
00044     private final LinkedList _importDeclaration_ = new TypedLinkedList(new ImportDeclaration_Cast());
00045     private final LinkedList _typeDeclaration_ = new TypedLinkedList(new TypeDeclaration_Cast());
00046 
00047     private class ImportDeclaration_Cast implements Cast
00048     {
00049         public Object cast(Object o)
00050         {
00051             PImportDeclaration node = (PImportDeclaration) o;
00052 
00053             if((node.parent() != null) &&
00054                 (node.parent() != ACompilationUnit.this))
00055             {
00056                 node.parent().removeChild(node);
00057             }
00058 
00059             if((node.parent() == null) ||
00060                 (node.parent() != ACompilationUnit.this))
00061             {
00062                 node.parent(ACompilationUnit.this);
00063             }
00064 
00065             return node;
00066         }
00067     }
00068 
00069     private class TypeDeclaration_Cast implements Cast
00070     {
00071         public Object cast(Object o)
00072         {
00073             PTypeDeclaration node = (PTypeDeclaration) o;
00074 
00075             if((node.parent() != null) &&
00076                 (node.parent() != ACompilationUnit.this))
00077             {
00078                 node.parent().removeChild(node);
00079             }
00080 
00081             if((node.parent() == null) ||
00082                 (node.parent() != ACompilationUnit.this))
00083             {
00084                 node.parent(ACompilationUnit.this);
00085             }
00086 
00087             return node;
00088         }
00089     }
00090     public ACompilationUnit()
00091     {
00092     }
00093     public ACompilationUnit(
00094         TPackage _package_,
00095         PName _packageDeclaration_,
00096         TSemicolon _semicolon_,
00097         List _importDeclaration_,
00098         List _typeDeclaration_)
00099     {
00100         setPackage(_package_);
00101 
00102         setPackageDeclaration(_packageDeclaration_);
00103 
00104         setSemicolon(_semicolon_);
00105 
00106         {
00107             Object temp[] = _importDeclaration_.toArray();
00108             for(int i = 0; i < temp.length; i++)
00109             {
00110                 this._importDeclaration_.add(temp[i]);
00111             }
00112         }
00113 
00114         {
00115             Object temp[] = _typeDeclaration_.toArray();
00116             for(int i = 0; i < temp.length; i++)
00117             {
00118                 this._typeDeclaration_.add(temp[i]);
00119             }
00120         }
00121 
00122     }
00123     public ACompilationUnit(
00124         TPackage _package_,
00125         PName _packageDeclaration_,
00126         TSemicolon _semicolon_,
00127         XPImportDeclaration _importDeclaration_,
00128         XPTypeDeclaration _typeDeclaration_)
00129     {
00130         setPackage(_package_);
00131 
00132         setPackageDeclaration(_packageDeclaration_);
00133 
00134         setSemicolon(_semicolon_);
00135 
00136         if(_importDeclaration_ != null)
00137         {
00138             while(_importDeclaration_ instanceof X1PImportDeclaration)
00139             {
00140                 this._importDeclaration_.addFirst(((X1PImportDeclaration) _importDeclaration_).getPImportDeclaration());
00141                 _importDeclaration_ = ((X1PImportDeclaration) _importDeclaration_).getXPImportDeclaration();
00142             }
00143             this._importDeclaration_.addFirst(((X2PImportDeclaration) _importDeclaration_).getPImportDeclaration());
00144         }
00145 
00146         if(_typeDeclaration_ != null)
00147         {
00148             while(_typeDeclaration_ instanceof X1PTypeDeclaration)
00149             {
00150                 this._typeDeclaration_.addFirst(((X1PTypeDeclaration) _typeDeclaration_).getPTypeDeclaration());
00151                 _typeDeclaration_ = ((X1PTypeDeclaration) _typeDeclaration_).getXPTypeDeclaration();
00152             }
00153             this._typeDeclaration_.addFirst(((X2PTypeDeclaration) _typeDeclaration_).getPTypeDeclaration());
00154         }
00155 
00156     }
00157     public void apply(Switch sw)
00158     {
00159         ((Analysis) sw).caseACompilationUnit(this);
00160     }
00161     public Object clone()
00162     {
00163         return new ACompilationUnit(
00164             (TPackage) cloneNode(_package_),
00165             (PName) cloneNode(_packageDeclaration_),
00166             (TSemicolon) cloneNode(_semicolon_),
00167             cloneList(_importDeclaration_),
00168             cloneList(_typeDeclaration_));
00169     }
00170     public LinkedList getImportDeclaration()
00171     {
00172         return _importDeclaration_;
00173     }
00174     public TPackage getPackage()
00175     {
00176         return _package_;
00177     }
00178     public PName getPackageDeclaration()
00179     {
00180         return _packageDeclaration_;
00181     }
00182     public TSemicolon getSemicolon()
00183     {
00184         return _semicolon_;
00185     }
00186     public LinkedList getTypeDeclaration()
00187     {
00188         return _typeDeclaration_;
00189     }
00190     void removeChild(Node child)
00191     {
00192         if(_package_ == child)
00193         {
00194             _package_ = null;
00195             return;
00196         }
00197 
00198         if(_packageDeclaration_ == child)
00199         {
00200             _packageDeclaration_ = null;
00201             return;
00202         }
00203 
00204         if(_semicolon_ == child)
00205         {
00206             _semicolon_ = null;
00207             return;
00208         }
00209 
00210         if(_importDeclaration_.remove(child))
00211         {
00212             return;
00213         }
00214 
00215         if(_typeDeclaration_.remove(child))
00216         {
00217             return;
00218         }
00219 
00220     }
00221     void replaceChild(Node oldChild, Node newChild)
00222     {
00223         if(_package_ == oldChild)
00224         {
00225             setPackage((TPackage) newChild);
00226             return;
00227         }
00228 
00229         if(_packageDeclaration_ == oldChild)
00230         {
00231             setPackageDeclaration((PName) newChild);
00232             return;
00233         }
00234 
00235         if(_semicolon_ == oldChild)
00236         {
00237             setSemicolon((TSemicolon) newChild);
00238             return;
00239         }
00240 
00241         for(ListIterator i = _importDeclaration_.listIterator(); i.hasNext();)
00242         {
00243             if(i.next() == oldChild)
00244             {
00245                 if(newChild != null)
00246                 {
00247                     i.set(newChild);
00248                     oldChild.parent(null);
00249                     return;
00250                 }
00251 
00252                 i.remove();
00253                 oldChild.parent(null);
00254                 return;
00255             }
00256         }
00257 
00258         for(ListIterator i = _typeDeclaration_.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 setImportDeclaration(List list)
00277     {
00278         Object temp[] = list.toArray();
00279         for(int i = 0; i < temp.length; i++)
00280         {
00281             _importDeclaration_.add(temp[i]);
00282         }
00283     }
00284     public void setPackage(TPackage node)
00285     {
00286         if(_package_ != null)
00287         {
00288             _package_.parent(null);
00289         }
00290 
00291         if(node != null)
00292         {
00293             if(node.parent() != null)
00294             {
00295                 node.parent().removeChild(node);
00296             }
00297 
00298             node.parent(this);
00299         }
00300 
00301         _package_ = node;
00302     }
00303     public void setPackageDeclaration(PName node)
00304     {
00305         if(_packageDeclaration_ != null)
00306         {
00307             _packageDeclaration_.parent(null);
00308         }
00309 
00310         if(node != null)
00311         {
00312             if(node.parent() != null)
00313             {
00314                 node.parent().removeChild(node);
00315             }
00316 
00317             node.parent(this);
00318         }
00319 
00320         _packageDeclaration_ = node;
00321     }
00322     public void setSemicolon(TSemicolon node)
00323     {
00324         if(_semicolon_ != null)
00325         {
00326             _semicolon_.parent(null);
00327         }
00328 
00329         if(node != null)
00330         {
00331             if(node.parent() != null)
00332             {
00333                 node.parent().removeChild(node);
00334             }
00335 
00336             node.parent(this);
00337         }
00338 
00339         _semicolon_ = node;
00340     }
00341     public void setTypeDeclaration(List list)
00342     {
00343         Object temp[] = list.toArray();
00344         for(int i = 0; i < temp.length; i++)
00345         {
00346             _typeDeclaration_.add(temp[i]);
00347         }
00348     }
00349     public String toString()
00350     {
00351         return ""
00352             + toString(_package_)
00353             + toString(_packageDeclaration_)
00354             + toString(_semicolon_)
00355             + toString(_importDeclaration_)
00356             + toString(_typeDeclaration_);
00357     }
00358 }

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