00001 package edu.ksu.cis.bandera.specification.assertion.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
00037
00038 import java.util.*;
00039 import edu.ksu.cis.bandera.specification.assertion.analysis.*;
00040 import edu.ksu.cis.bandera.jjjc.node.*;
00041
00042 public final class APostAssertion extends PAssertion
00043 {
00044 private TPost _post_;
00045 private TId _id_;
00046 private TColon _colon_;
00047 private PExp exp;
00048 private TSemicolon _semicolon_;
00049 private final LinkedList _comment_ = new TypedLinkedList(new Comment_Cast());
00050
00051 private class Comment_Cast implements Cast
00052 {
00053 public Object cast(Object o)
00054 {
00055 PComment node = (PComment) o;
00056
00057 if((node.parent() != null) &&
00058 (node.parent() != APostAssertion.this))
00059 {
00060 node.parent().removeChild(node);
00061 }
00062
00063 if((node.parent() == null) ||
00064 (node.parent() != APostAssertion.this))
00065 {
00066 node.parent(APostAssertion.this);
00067 }
00068
00069 return node;
00070 }
00071 }
00072 public APostAssertion()
00073 {
00074 }
00075 public APostAssertion(
00076 TPost _post_,
00077 TId _id_,
00078 TColon _colon_,
00079 TSemicolon _semicolon_,
00080 XPComment _comment_)
00081 {
00082 setPost(_post_);
00083
00084 setId(_id_);
00085
00086 setColon(_colon_);
00087
00088 setSemicolon(_semicolon_);
00089
00090 if(_comment_ != null)
00091 {
00092 while(_comment_ instanceof X1PComment)
00093 {
00094 this._comment_.addFirst(((X1PComment) _comment_).getPComment());
00095 _comment_ = ((X1PComment) _comment_).getXPComment();
00096 }
00097 this._comment_.addFirst(((X2PComment) _comment_).getPComment());
00098 }
00099
00100 }
00101 public APostAssertion(
00102 TPost _post_,
00103 TId _id_,
00104 TColon _colon_,
00105 TSemicolon _semicolon_,
00106 List _comment_)
00107 {
00108 setPost(_post_);
00109
00110 setId(_id_);
00111
00112 setColon(_colon_);
00113
00114 setSemicolon(_semicolon_);
00115
00116 {
00117 Object temp[] = _comment_.toArray();
00118 for(int i = 0; i < temp.length; i++)
00119 {
00120 this._comment_.add(temp[i]);
00121 }
00122 }
00123
00124 }
00125 public void apply(Switch sw)
00126 {
00127 ((Analysis) sw).caseAPostAssertion(this);
00128 }
00129 public Object clone()
00130 {
00131 return new APostAssertion(
00132 (TPost) cloneNode(_post_),
00133 (TId) cloneNode(_id_),
00134 (TColon) cloneNode(_colon_),
00135 (TSemicolon) cloneNode(_semicolon_),
00136 cloneList(_comment_));
00137 }
00138 public TColon getColon()
00139 {
00140 return _colon_;
00141 }
00142 public LinkedList getComment()
00143 {
00144 return _comment_;
00145 }
00146
00147
00148
00149
00150 public edu.ksu.cis.bandera.jjjc.node.PExp getExp() {
00151 return exp;
00152 }
00153 public TId getId()
00154 {
00155 return _id_;
00156 }
00157 public TPost getPost()
00158 {
00159 return _post_;
00160 }
00161 public TSemicolon getSemicolon()
00162 {
00163 return _semicolon_;
00164 }
00165 void removeChild(Node child)
00166 {
00167 if(_post_ == child)
00168 {
00169 _post_ = null;
00170 return;
00171 }
00172
00173 if(_id_ == child)
00174 {
00175 _id_ = null;
00176 return;
00177 }
00178
00179 if(_colon_ == child)
00180 {
00181 _colon_ = null;
00182 return;
00183 }
00184
00185 if(_semicolon_ == child)
00186 {
00187 _semicolon_ = null;
00188 return;
00189 }
00190
00191 if(_comment_.remove(child))
00192 {
00193 return;
00194 }
00195
00196 }
00197 void replaceChild(Node oldChild, Node newChild)
00198 {
00199 if(_post_ == oldChild)
00200 {
00201 setPost((TPost) newChild);
00202 return;
00203 }
00204
00205 if(_id_ == oldChild)
00206 {
00207 setId((TId) newChild);
00208 return;
00209 }
00210
00211 if(_colon_ == oldChild)
00212 {
00213 setColon((TColon) newChild);
00214 return;
00215 }
00216
00217 if(_semicolon_ == oldChild)
00218 {
00219 setSemicolon((TSemicolon) newChild);
00220 return;
00221 }
00222
00223 for(ListIterator i = _comment_.listIterator(); i.hasNext();)
00224 {
00225 if(i.next() == oldChild)
00226 {
00227 if(newChild != null)
00228 {
00229 i.set(newChild);
00230 oldChild.parent(null);
00231 return;
00232 }
00233
00234 i.remove();
00235 oldChild.parent(null);
00236 return;
00237 }
00238 }
00239
00240 }
00241 public void setColon(TColon node)
00242 {
00243 if(_colon_ != null)
00244 {
00245 _colon_.parent(null);
00246 }
00247
00248 if(node != null)
00249 {
00250 if(node.parent() != null)
00251 {
00252 node.parent().removeChild(node);
00253 }
00254
00255 node.parent(this);
00256 }
00257
00258 _colon_ = node;
00259 }
00260 public void setComment(List list)
00261 {
00262 Object temp[] = list.toArray();
00263 for(int i = 0; i < temp.length; i++)
00264 {
00265 _comment_.add(temp[i]);
00266 }
00267 }
00268
00269
00270
00271
00272 public void setExp(edu.ksu.cis.bandera.jjjc.node.PExp newExp) {
00273 exp = newExp;
00274 }
00275 public void setId(TId node)
00276 {
00277 if(_id_ != null)
00278 {
00279 _id_.parent(null);
00280 }
00281
00282 if(node != null)
00283 {
00284 if(node.parent() != null)
00285 {
00286 node.parent().removeChild(node);
00287 }
00288
00289 node.parent(this);
00290 }
00291
00292 _id_ = node;
00293 }
00294 public void setPost(TPost node)
00295 {
00296 if(_post_ != null)
00297 {
00298 _post_.parent(null);
00299 }
00300
00301 if(node != null)
00302 {
00303 if(node.parent() != null)
00304 {
00305 node.parent().removeChild(node);
00306 }
00307
00308 node.parent(this);
00309 }
00310
00311 _post_ = node;
00312 }
00313 public void setSemicolon(TSemicolon node)
00314 {
00315 if(_semicolon_ != null)
00316 {
00317 _semicolon_.parent(null);
00318 }
00319
00320 if(node != null)
00321 {
00322 if(node.parent() != null)
00323 {
00324 node.parent().removeChild(node);
00325 }
00326
00327 node.parent(this);
00328 }
00329
00330 _semicolon_ = node;
00331 }
00332 public String toString()
00333 {
00334 return ""
00335 + toString(_post_)
00336 + toString(_id_)
00337 + toString(_colon_)
00338 + toString(_semicolon_)
00339 + toString(_comment_);
00340 }
00341 }