1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 27 public class LabeledStatement extends Statement { 28 29 33 public static final ChildPropertyDescriptor LABEL_PROPERTY = 34 new ChildPropertyDescriptor(LabeledStatement.class, "label", SimpleName.class, MANDATORY, NO_CYCLE_RISK); 36 40 public static final ChildPropertyDescriptor BODY_PROPERTY = 41 new ChildPropertyDescriptor(LabeledStatement.class, "body", Statement.class, MANDATORY, CYCLE_RISK); 43 48 private static final List PROPERTY_DESCRIPTORS; 49 50 static { 51 List propertyList = new ArrayList (3); 52 createPropertyList(LabeledStatement.class, propertyList); 53 addProperty(LABEL_PROPERTY, propertyList); 54 addProperty(BODY_PROPERTY, propertyList); 55 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList); 56 } 57 58 69 public static List propertyDescriptors(int apiLevel) { 70 return PROPERTY_DESCRIPTORS; 71 } 72 73 77 private SimpleName labelName = null; 78 79 83 private Statement body = null; 84 85 95 LabeledStatement(AST ast) { 96 super(ast); 97 } 98 99 102 final List internalStructuralPropertiesForType(int apiLevel) { 103 return propertyDescriptors(apiLevel); 104 } 105 106 109 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 110 if (property == LABEL_PROPERTY) { 111 if (get) { 112 return getLabel(); 113 } else { 114 setLabel((SimpleName) child); 115 return null; 116 } 117 } 118 if (property == BODY_PROPERTY) { 119 if (get) { 120 return getBody(); 121 } else { 122 setBody((Statement) child); 123 return null; 124 } 125 } 126 return super.internalGetSetChildProperty(property, get, child); 128 } 129 130 133 final int getNodeType0() { 134 return LABELED_STATEMENT; 135 } 136 137 140 ASTNode clone0(AST target) { 141 LabeledStatement result = new LabeledStatement(target); 142 result.setSourceRange(this.getStartPosition(), this.getLength()); 143 result.setLabel( 144 (SimpleName) ASTNode.copySubtree(target, getLabel())); 145 result.setBody( 146 (Statement) ASTNode.copySubtree(target, getBody())); 147 return result; 148 } 149 150 153 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 154 return matcher.match(this, other); 156 } 157 158 161 void accept0(ASTVisitor visitor) { 162 boolean visitChildren = visitor.visit(this); 163 if (visitChildren) { 164 acceptChild(visitor, getLabel()); 166 acceptChild(visitor, getBody()); 167 } 168 visitor.endVisit(this); 169 } 170 171 176 public SimpleName getLabel() { 177 if (this.labelName == null) { 178 synchronized (this) { 180 if (this.labelName == null) { 181 preLazyInit(); 182 this.labelName= new SimpleName(this.ast); 183 postLazyInit(this.labelName, LABEL_PROPERTY); 184 } 185 } 186 } 187 return this.labelName; 188 } 189 190 200 public void setLabel(SimpleName label) { 201 if (label == null) { 202 throw new IllegalArgumentException (); 203 } 204 ASTNode oldChild = this.labelName; 205 preReplaceChild(oldChild, label, LABEL_PROPERTY); 206 this.labelName = label; 207 postReplaceChild(oldChild, label, LABEL_PROPERTY); 208 } 209 210 215 public Statement getBody() { 216 if (this.body == null) { 217 synchronized (this) { 219 if (this.body == null) { 220 preLazyInit(); 221 this.body= new EmptyStatement(this.ast); 222 postLazyInit(this.body, BODY_PROPERTY); 223 } 224 } 225 } 226 return this.body; 227 } 228 229 248 public void setBody(Statement statement) { 249 if (statement == null) { 250 throw new IllegalArgumentException (); 251 } 252 ASTNode oldChild = this.body; 253 preReplaceChild(oldChild, statement, BODY_PROPERTY); 254 this.body = statement; 255 postReplaceChild(oldChild, statement, BODY_PROPERTY); 256 } 257 258 261 int memSize() { 262 return super.memSize() + 2 * 4; 263 } 264 265 268 int treeSize() { 269 return 270 memSize() 271 + (this.labelName == null ? 0 : getLabel().treeSize()) 272 + (this.body == null ? 0 : getBody().treeSize()); 273 } 274 } 275 276 | Popular Tags |