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 AConstructorBody extends PConstructorBody
00040 {
00041 private TLBrace _lBrace_;
00042 private PConstructorInvocation _constructorInvocation_;
00043 private final LinkedList _blockedStmt_ = new TypedLinkedList(new BlockedStmt_Cast());
00044 private TRBrace _rBrace_;
00045
00046 private class BlockedStmt_Cast implements Cast
00047 {
00048 public Object cast(Object o)
00049 {
00050 PBlockedStmt node = (PBlockedStmt) o;
00051
00052 if((node.parent() != null) &&
00053 (node.parent() != AConstructorBody.this))
00054 {
00055 node.parent().removeChild(node);
00056 }
00057
00058 if((node.parent() == null) ||
00059 (node.parent() != AConstructorBody.this))
00060 {
00061 node.parent(AConstructorBody.this);
00062 }
00063
00064 return node;
00065 }
00066 }
00067 public AConstructorBody()
00068 {
00069 }
00070 public AConstructorBody(
00071 TLBrace _lBrace_,
00072 PConstructorInvocation _constructorInvocation_,
00073 List _blockedStmt_,
00074 TRBrace _rBrace_)
00075 {
00076 setLBrace(_lBrace_);
00077
00078 setConstructorInvocation(_constructorInvocation_);
00079
00080 {
00081 Object temp[] = _blockedStmt_.toArray();
00082 for(int i = 0; i < temp.length; i++)
00083 {
00084 this._blockedStmt_.add(temp[i]);
00085 }
00086 }
00087
00088 setRBrace(_rBrace_);
00089
00090 }
00091 public AConstructorBody(
00092 TLBrace _lBrace_,
00093 PConstructorInvocation _constructorInvocation_,
00094 XPBlockedStmt _blockedStmt_,
00095 TRBrace _rBrace_)
00096 {
00097 setLBrace(_lBrace_);
00098
00099 setConstructorInvocation(_constructorInvocation_);
00100
00101 if(_blockedStmt_ != null)
00102 {
00103 while(_blockedStmt_ instanceof X1PBlockedStmt)
00104 {
00105 this._blockedStmt_.addFirst(((X1PBlockedStmt) _blockedStmt_).getPBlockedStmt());
00106 _blockedStmt_ = ((X1PBlockedStmt) _blockedStmt_).getXPBlockedStmt();
00107 }
00108 this._blockedStmt_.addFirst(((X2PBlockedStmt) _blockedStmt_).getPBlockedStmt());
00109 }
00110
00111 setRBrace(_rBrace_);
00112
00113 }
00114 public void apply(Switch sw)
00115 {
00116 ((Analysis) sw).caseAConstructorBody(this);
00117 }
00118 public Object clone()
00119 {
00120 return new AConstructorBody(
00121 (TLBrace) cloneNode(_lBrace_),
00122 (PConstructorInvocation) cloneNode(_constructorInvocation_),
00123 cloneList(_blockedStmt_),
00124 (TRBrace) cloneNode(_rBrace_));
00125 }
00126 public LinkedList getBlockedStmt()
00127 {
00128 return _blockedStmt_;
00129 }
00130 public PConstructorInvocation getConstructorInvocation()
00131 {
00132 return _constructorInvocation_;
00133 }
00134 public TLBrace getLBrace()
00135 {
00136 return _lBrace_;
00137 }
00138 public TRBrace getRBrace()
00139 {
00140 return _rBrace_;
00141 }
00142 void removeChild(Node child)
00143 {
00144 if(_lBrace_ == child)
00145 {
00146 _lBrace_ = null;
00147 return;
00148 }
00149
00150 if(_constructorInvocation_ == child)
00151 {
00152 _constructorInvocation_ = null;
00153 return;
00154 }
00155
00156 if(_blockedStmt_.remove(child))
00157 {
00158 return;
00159 }
00160
00161 if(_rBrace_ == child)
00162 {
00163 _rBrace_ = null;
00164 return;
00165 }
00166
00167 }
00168 void replaceChild(Node oldChild, Node newChild)
00169 {
00170 if(_lBrace_ == oldChild)
00171 {
00172 setLBrace((TLBrace) newChild);
00173 return;
00174 }
00175
00176 if(_constructorInvocation_ == oldChild)
00177 {
00178 setConstructorInvocation((PConstructorInvocation) newChild);
00179 return;
00180 }
00181
00182 for(ListIterator i = _blockedStmt_.listIterator(); i.hasNext();)
00183 {
00184 if(i.next() == oldChild)
00185 {
00186 if(newChild != null)
00187 {
00188 i.set(newChild);
00189 oldChild.parent(null);
00190 return;
00191 }
00192
00193 i.remove();
00194 oldChild.parent(null);
00195 return;
00196 }
00197 }
00198
00199 if(_rBrace_ == oldChild)
00200 {
00201 setRBrace((TRBrace) newChild);
00202 return;
00203 }
00204
00205 }
00206 public void setBlockedStmt(List list)
00207 {
00208 Object temp[] = list.toArray();
00209 for(int i = 0; i < temp.length; i++)
00210 {
00211 _blockedStmt_.add(temp[i]);
00212 }
00213 }
00214 public void setConstructorInvocation(PConstructorInvocation node)
00215 {
00216 if(_constructorInvocation_ != null)
00217 {
00218 _constructorInvocation_.parent(null);
00219 }
00220
00221 if(node != null)
00222 {
00223 if(node.parent() != null)
00224 {
00225 node.parent().removeChild(node);
00226 }
00227
00228 node.parent(this);
00229 }
00230
00231 _constructorInvocation_ = node;
00232 }
00233 public void setLBrace(TLBrace node)
00234 {
00235 if(_lBrace_ != null)
00236 {
00237 _lBrace_.parent(null);
00238 }
00239
00240 if(node != null)
00241 {
00242 if(node.parent() != null)
00243 {
00244 node.parent().removeChild(node);
00245 }
00246
00247 node.parent(this);
00248 }
00249
00250 _lBrace_ = node;
00251 }
00252 public void setRBrace(TRBrace node)
00253 {
00254 if(_rBrace_ != null)
00255 {
00256 _rBrace_.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 _rBrace_ = node;
00270 }
00271 public String toString()
00272 {
00273 return ""
00274 + toString(_lBrace_)
00275 + toString(_constructorInvocation_)
00276 + toString(_blockedStmt_)
00277 + toString(_rBrace_);
00278 }
00279 }