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 AClassOrInterfaceTypeExp extends PExp
00040 {
00041 private TNew _new_;
00042 private PName _classOrInterfaceType_;
00043 private final LinkedList _dimExp_ = new TypedLinkedList(new DimExp_Cast());
00044 private final LinkedList _dim_ = new TypedLinkedList(new Dim_Cast());
00045
00046 private class DimExp_Cast implements Cast
00047 {
00048 public Object cast(Object o)
00049 {
00050 PDimExp node = (PDimExp) o;
00051
00052 if((node.parent() != null) &&
00053 (node.parent() != AClassOrInterfaceTypeExp.this))
00054 {
00055 node.parent().removeChild(node);
00056 }
00057
00058 if((node.parent() == null) ||
00059 (node.parent() != AClassOrInterfaceTypeExp.this))
00060 {
00061 node.parent(AClassOrInterfaceTypeExp.this);
00062 }
00063
00064 return node;
00065 }
00066 }
00067
00068 private class Dim_Cast implements Cast
00069 {
00070 public Object cast(Object o)
00071 {
00072 PDim node = (PDim) o;
00073
00074 if((node.parent() != null) &&
00075 (node.parent() != AClassOrInterfaceTypeExp.this))
00076 {
00077 node.parent().removeChild(node);
00078 }
00079
00080 if((node.parent() == null) ||
00081 (node.parent() != AClassOrInterfaceTypeExp.this))
00082 {
00083 node.parent(AClassOrInterfaceTypeExp.this);
00084 }
00085
00086 return node;
00087 }
00088 }
00089 public AClassOrInterfaceTypeExp()
00090 {
00091 }
00092 public AClassOrInterfaceTypeExp(
00093 TNew _new_,
00094 PName _classOrInterfaceType_,
00095 List _dimExp_,
00096 List _dim_)
00097 {
00098 setNew(_new_);
00099
00100 setClassOrInterfaceType(_classOrInterfaceType_);
00101
00102 {
00103 Object temp[] = _dimExp_.toArray();
00104 for(int i = 0; i < temp.length; i++)
00105 {
00106 this._dimExp_.add(temp[i]);
00107 }
00108 }
00109
00110 {
00111 Object temp[] = _dim_.toArray();
00112 for(int i = 0; i < temp.length; i++)
00113 {
00114 this._dim_.add(temp[i]);
00115 }
00116 }
00117
00118 }
00119 public AClassOrInterfaceTypeExp(
00120 TNew _new_,
00121 PName _classOrInterfaceType_,
00122 XPDimExp _dimExp_,
00123 XPDim _dim_)
00124 {
00125 setNew(_new_);
00126
00127 setClassOrInterfaceType(_classOrInterfaceType_);
00128
00129 if(_dimExp_ != null)
00130 {
00131 while(_dimExp_ instanceof X1PDimExp)
00132 {
00133 this._dimExp_.addFirst(((X1PDimExp) _dimExp_).getPDimExp());
00134 _dimExp_ = ((X1PDimExp) _dimExp_).getXPDimExp();
00135 }
00136 this._dimExp_.addFirst(((X2PDimExp) _dimExp_).getPDimExp());
00137 }
00138
00139 if(_dim_ != null)
00140 {
00141 while(_dim_ instanceof X1PDim)
00142 {
00143 this._dim_.addFirst(((X1PDim) _dim_).getPDim());
00144 _dim_ = ((X1PDim) _dim_).getXPDim();
00145 }
00146 this._dim_.addFirst(((X2PDim) _dim_).getPDim());
00147 }
00148
00149 }
00150 public void apply(Switch sw)
00151 {
00152 ((Analysis) sw).caseAClassOrInterfaceTypeExp(this);
00153 }
00154 public Object clone()
00155 {
00156 return new AClassOrInterfaceTypeExp(
00157 (TNew) cloneNode(_new_),
00158 (PName) cloneNode(_classOrInterfaceType_),
00159 cloneList(_dimExp_),
00160 cloneList(_dim_));
00161 }
00162 public PName getClassOrInterfaceType()
00163 {
00164 return _classOrInterfaceType_;
00165 }
00166 public LinkedList getDim()
00167 {
00168 return _dim_;
00169 }
00170 public LinkedList getDimExp()
00171 {
00172 return _dimExp_;
00173 }
00174 public TNew getNew()
00175 {
00176 return _new_;
00177 }
00178 void removeChild(Node child)
00179 {
00180 if(_new_ == child)
00181 {
00182 _new_ = null;
00183 return;
00184 }
00185
00186 if(_classOrInterfaceType_ == child)
00187 {
00188 _classOrInterfaceType_ = null;
00189 return;
00190 }
00191
00192 if(_dimExp_.remove(child))
00193 {
00194 return;
00195 }
00196
00197 if(_dim_.remove(child))
00198 {
00199 return;
00200 }
00201
00202 }
00203 void replaceChild(Node oldChild, Node newChild)
00204 {
00205 if(_new_ == oldChild)
00206 {
00207 setNew((TNew) newChild);
00208 return;
00209 }
00210
00211 if(_classOrInterfaceType_ == oldChild)
00212 {
00213 setClassOrInterfaceType((PName) newChild);
00214 return;
00215 }
00216
00217 for(ListIterator i = _dimExp_.listIterator(); i.hasNext();)
00218 {
00219 if(i.next() == oldChild)
00220 {
00221 if(newChild != null)
00222 {
00223 i.set(newChild);
00224 oldChild.parent(null);
00225 return;
00226 }
00227
00228 i.remove();
00229 oldChild.parent(null);
00230 return;
00231 }
00232 }
00233
00234 for(ListIterator i = _dim_.listIterator(); i.hasNext();)
00235 {
00236 if(i.next() == oldChild)
00237 {
00238 if(newChild != null)
00239 {
00240 i.set(newChild);
00241 oldChild.parent(null);
00242 return;
00243 }
00244
00245 i.remove();
00246 oldChild.parent(null);
00247 return;
00248 }
00249 }
00250
00251 }
00252 public void setClassOrInterfaceType(PName node)
00253 {
00254 if(_classOrInterfaceType_ != null)
00255 {
00256 _classOrInterfaceType_.parent(null);
00257 }
00258
00259 if(node != null)
00260 {
00261 if(node.parent() != null)
00262 {
00263 node.parent().removeChild(node);
00264 }
00265
00266 node.parent(this);
00267 }
00268
00269 _classOrInterfaceType_ = node;
00270 }
00271 public void setDim(List list)
00272 {
00273 Object temp[] = list.toArray();
00274 for(int i = 0; i < temp.length; i++)
00275 {
00276 _dim_.add(temp[i]);
00277 }
00278 }
00279 public void setDimExp(List list)
00280 {
00281 Object temp[] = list.toArray();
00282 for(int i = 0; i < temp.length; i++)
00283 {
00284 _dimExp_.add(temp[i]);
00285 }
00286 }
00287 public void setNew(TNew node)
00288 {
00289 if(_new_ != null)
00290 {
00291 _new_.parent(null);
00292 }
00293
00294 if(node != null)
00295 {
00296 if(node.parent() != null)
00297 {
00298 node.parent().removeChild(node);
00299 }
00300
00301 node.parent(this);
00302 }
00303
00304 _new_ = node;
00305 }
00306 public String toString()
00307 {
00308 return ""
00309 + toString(_new_)
00310 + toString(_classOrInterfaceType_)
00311 + toString(_dimExp_)
00312 + toString(_dim_);
00313 }
00314 }