1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 29 public class Assignment extends Expression { 30 31 49 public static class Operator { 50 51 54 private String op; 55 56 65 private Operator(String op) { 66 this.op = op; 67 } 68 69 74 public String toString() { 75 return op; 76 } 77 78 79 public static final Operator ASSIGN = new Operator("="); 81 public static final Operator PLUS_ASSIGN = new Operator("+="); 83 public static final Operator MINUS_ASSIGN = new Operator("-="); 85 public static final Operator TIMES_ASSIGN = new Operator("*="); 87 public static final Operator DIVIDE_ASSIGN = new Operator("/="); 89 public static final Operator BIT_AND_ASSIGN = new Operator("&="); 91 public static final Operator BIT_OR_ASSIGN = new Operator("|="); 93 public static final Operator BIT_XOR_ASSIGN = new Operator("^="); 95 public static final Operator REMAINDER_ASSIGN = new Operator("%="); 97 public static final Operator LEFT_SHIFT_ASSIGN = 98 new Operator("<<="); 100 public static final Operator RIGHT_SHIFT_SIGNED_ASSIGN = 101 new Operator(">>="); 103 public static final Operator RIGHT_SHIFT_UNSIGNED_ASSIGN = 104 new Operator(">>>="); 106 118 public static Operator toOperator(String token) { 119 return (Operator) CODES.get(token); 120 } 121 122 126 private static final Map CODES; 127 static { 128 CODES = new HashMap (20); 129 Operator[] ops = { 130 ASSIGN, 131 PLUS_ASSIGN, 132 MINUS_ASSIGN, 133 TIMES_ASSIGN, 134 DIVIDE_ASSIGN, 135 BIT_AND_ASSIGN, 136 BIT_OR_ASSIGN, 137 BIT_XOR_ASSIGN, 138 REMAINDER_ASSIGN, 139 LEFT_SHIFT_ASSIGN, 140 RIGHT_SHIFT_SIGNED_ASSIGN, 141 RIGHT_SHIFT_UNSIGNED_ASSIGN 142 }; 143 for (int i = 0; i < ops.length; i++) { 144 CODES.put(ops[i].toString(), ops[i]); 145 } 146 } 147 } 148 149 153 public static final ChildPropertyDescriptor LEFT_HAND_SIDE_PROPERTY = 154 new ChildPropertyDescriptor(Assignment.class, "leftHandSide", Expression.class, MANDATORY, CYCLE_RISK); 156 160 public static final SimplePropertyDescriptor OPERATOR_PROPERTY = 161 new SimplePropertyDescriptor(Assignment.class, "operator", Assignment.Operator.class, MANDATORY); 163 167 public static final ChildPropertyDescriptor RIGHT_HAND_SIDE_PROPERTY = 168 new ChildPropertyDescriptor(Assignment.class, "rightHandSide", Expression.class, MANDATORY, CYCLE_RISK); 170 175 private static final List PROPERTY_DESCRIPTORS; 176 177 static { 178 List properyList = new ArrayList (4); 179 createPropertyList(Assignment.class, properyList); 180 addProperty(LEFT_HAND_SIDE_PROPERTY, properyList); 181 addProperty(OPERATOR_PROPERTY, properyList); 182 addProperty(RIGHT_HAND_SIDE_PROPERTY, properyList); 183 PROPERTY_DESCRIPTORS = reapPropertyList(properyList); 184 } 185 186 197 public static List propertyDescriptors(int apiLevel) { 198 return PROPERTY_DESCRIPTORS; 199 } 200 201 204 private Assignment.Operator assignmentOperator = Assignment.Operator.ASSIGN; 205 206 210 private Expression leftHandSide = null; 211 212 216 private Expression rightHandSide = null; 217 218 225 Assignment(AST ast) { 226 super(ast); 227 } 228 229 232 final List internalStructuralPropertiesForType(int apiLevel) { 233 return propertyDescriptors(apiLevel); 234 } 235 236 239 final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object value) { 240 if (property == OPERATOR_PROPERTY) { 241 if (get) { 242 return getOperator(); 243 } else { 244 setOperator((Operator) value); 245 return null; 246 } 247 } 248 return super.internalGetSetObjectProperty(property, get, value); 250 } 251 252 255 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 256 if (property == LEFT_HAND_SIDE_PROPERTY) { 257 if (get) { 258 return getLeftHandSide(); 259 } else { 260 setLeftHandSide((Expression) child); 261 return null; 262 } 263 } 264 if (property == RIGHT_HAND_SIDE_PROPERTY) { 265 if (get) { 266 return getRightHandSide(); 267 } else { 268 setRightHandSide((Expression) child); 269 return null; 270 } 271 } 272 return super.internalGetSetChildProperty(property, get, child); 274 } 275 276 279 final int getNodeType0() { 280 return ASSIGNMENT; 281 } 282 283 286 ASTNode clone0(AST target) { 287 Assignment result = new Assignment(target); 288 result.setSourceRange(this.getStartPosition(), this.getLength()); 289 result.setOperator(getOperator()); 290 result.setLeftHandSide((Expression) getLeftHandSide().clone(target)); 291 result.setRightHandSide((Expression) getRightHandSide().clone(target)); 292 return result; 293 } 294 295 298 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 299 return matcher.match(this, other); 301 } 302 303 306 void accept0(ASTVisitor visitor) { 307 boolean visitChildren = visitor.visit(this); 308 if (visitChildren) { 309 acceptChild(visitor, getLeftHandSide()); 311 acceptChild(visitor, getRightHandSide()); 312 } 313 visitor.endVisit(this); 314 } 315 316 321 public Assignment.Operator getOperator() { 322 return this.assignmentOperator; 323 } 324 325 331 public void setOperator(Assignment.Operator assignmentOperator) { 332 if (assignmentOperator == null) { 333 throw new IllegalArgumentException (); 334 } 335 preValueChange(OPERATOR_PROPERTY); 336 this.assignmentOperator = assignmentOperator; 337 postValueChange(OPERATOR_PROPERTY); 338 } 339 340 345 public Expression getLeftHandSide() { 346 if (this.leftHandSide == null) { 347 synchronized (this) { 349 if (this.leftHandSide == null) { 350 preLazyInit(); 351 this.leftHandSide= new SimpleName(this.ast); 352 postLazyInit(this.leftHandSide, LEFT_HAND_SIDE_PROPERTY); 353 } 354 } 355 } 356 return this.leftHandSide; 357 } 358 359 370 public void setLeftHandSide(Expression expression) { 371 if (expression == null) { 372 throw new IllegalArgumentException (); 373 } 374 ASTNode oldChild = this.leftHandSide; 376 preReplaceChild(oldChild, expression, LEFT_HAND_SIDE_PROPERTY); 377 this.leftHandSide = expression; 378 postReplaceChild(oldChild, expression, LEFT_HAND_SIDE_PROPERTY); 379 } 380 381 386 public Expression getRightHandSide() { 387 if (this.rightHandSide == null) { 388 synchronized (this) { 390 if (this.rightHandSide == null) { 391 preLazyInit(); 392 this.rightHandSide= new SimpleName(this.ast); 393 postLazyInit(this.rightHandSide, RIGHT_HAND_SIDE_PROPERTY); 394 } 395 } 396 } 397 return this.rightHandSide; 398 } 399 400 411 public void setRightHandSide(Expression expression) { 412 if (expression == null) { 413 throw new IllegalArgumentException (); 414 } 415 ASTNode oldChild = this.rightHandSide; 417 preReplaceChild(oldChild, expression, RIGHT_HAND_SIDE_PROPERTY); 418 this.rightHandSide = expression; 419 postReplaceChild(oldChild, expression, RIGHT_HAND_SIDE_PROPERTY); 420 } 421 422 425 int memSize() { 426 return BASE_NODE_SIZE + 3 * 4; 428 } 429 430 433 int treeSize() { 434 return 435 memSize() 436 + (this.leftHandSide == null ? 0 : getLeftHandSide().treeSize()) 437 + (this.rightHandSide == null ? 0 : getRightHandSide().treeSize()); 438 } 439 } 440 441 | Popular Tags |