00001 package edu.ksu.cis.bandera.jjjc.node;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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 }