1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 29 public class TryStatement extends Statement { 30 31 35 public static final ChildPropertyDescriptor BODY_PROPERTY = 36 new ChildPropertyDescriptor(TryStatement.class, "body", Block.class, MANDATORY, CYCLE_RISK); 38 42 public static final ChildListPropertyDescriptor CATCH_CLAUSES_PROPERTY = 43 new ChildListPropertyDescriptor(TryStatement.class, "catchClauses", CatchClause.class, CYCLE_RISK); 45 49 public static final ChildPropertyDescriptor FINALLY_PROPERTY = 50 new ChildPropertyDescriptor(TryStatement.class, "finally", Block.class, OPTIONAL, CYCLE_RISK); 52 57 private static final List PROPERTY_DESCRIPTORS; 58 59 static { 60 List propertyList = new ArrayList (4); 61 createPropertyList(TryStatement.class, propertyList); 62 addProperty(BODY_PROPERTY, propertyList); 63 addProperty(CATCH_CLAUSES_PROPERTY, propertyList); 64 addProperty(FINALLY_PROPERTY, propertyList); 65 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList); 66 } 67 68 78 public static List propertyDescriptors(int apiLevel) { 79 return PROPERTY_DESCRIPTORS; 80 } 81 82 85 private Block body = null; 86 87 91 private ASTNode.NodeList catchClauses = 92 new ASTNode.NodeList(CATCH_CLAUSES_PROPERTY); 93 94 98 private Block optionalFinallyBody = null; 99 100 101 111 TryStatement(AST ast) { 112 super(ast); 113 } 114 115 118 final List internalStructuralPropertiesForType(int apiLevel) { 119 return propertyDescriptors(apiLevel); 120 } 121 122 125 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 126 if (property == BODY_PROPERTY) { 127 if (get) { 128 return getBody(); 129 } else { 130 setBody((Block) child); 131 return null; 132 } 133 } 134 if (property == FINALLY_PROPERTY) { 135 if (get) { 136 return getFinally(); 137 } else { 138 setFinally((Block) child); 139 return null; 140 } 141 } 142 return super.internalGetSetChildProperty(property, get, child); 144 } 145 146 149 final List internalGetChildListProperty(ChildListPropertyDescriptor property) { 150 if (property == CATCH_CLAUSES_PROPERTY) { 151 return catchClauses(); 152 } 153 return super.internalGetChildListProperty(property); 155 } 156 157 160 final int getNodeType0() { 161 return TRY_STATEMENT; 162 } 163 164 167 ASTNode clone0(AST target) { 168 TryStatement result = new TryStatement(target); 169 result.setSourceRange(this.getStartPosition(), this.getLength()); 170 result.copyLeadingComment(this); 171 result.setBody((Block) getBody().clone(target)); 172 result.catchClauses().addAll( 173 ASTNode.copySubtrees(target, catchClauses())); 174 result.setFinally( 175 (Block) ASTNode.copySubtree(target, getFinally())); 176 return result; 177 } 178 179 182 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 183 return matcher.match(this, other); 185 } 186 187 190 void accept0(ASTVisitor visitor) { 191 boolean visitChildren = visitor.visit(this); 192 if (visitChildren) { 193 acceptChild(visitor, getBody()); 195 acceptChildren(visitor, this.catchClauses); 196 acceptChild(visitor, getFinally()); 197 } 198 visitor.endVisit(this); 199 } 200 201 206 public Block getBody() { 207 if (this.body == null) { 208 synchronized (this) { 210 if (this.body == null) { 211 preLazyInit(); 212 this.body = new Block(this.ast); 213 postLazyInit(this.body, BODY_PROPERTY); 214 } 215 } 216 } 217 return this.body; 218 } 219 220 231 public void setBody(Block body) { 232 if (body == null) { 233 throw new IllegalArgumentException (); 234 } 235 ASTNode oldChild = this.body; 236 preReplaceChild(oldChild, body, BODY_PROPERTY); 237 this.body = body; 238 postReplaceChild(oldChild, body, BODY_PROPERTY); 239 } 240 241 247 public List catchClauses() { 248 return this.catchClauses; 249 } 250 251 258 public Block getFinally() { 259 return this.optionalFinallyBody; 260 } 261 262 274 public void setFinally(Block block) { 275 ASTNode oldChild = this.optionalFinallyBody; 276 preReplaceChild(oldChild, block, FINALLY_PROPERTY); 277 this.optionalFinallyBody = block; 278 postReplaceChild(oldChild, block, FINALLY_PROPERTY); 279 } 280 281 284 int memSize() { 285 return super.memSize() + 3 * 4; 286 } 287 288 291 int treeSize() { 292 return 293 memSize() 294 + (this.body == null ? 0 : getBody().treeSize()) 295 + this.catchClauses.listSize() 296 + (this.optionalFinallyBody == null ? 0 : getFinally().treeSize()); 297 } 298 } 299 | Popular Tags |