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 PostfixExpression extends Expression { 30 31 39 public static class Operator { 40 41 44 private String token; 45 46 55 private Operator(String token) { 56 this.token = token; 57 } 58 59 64 public String toString() { 65 return token; 66 } 67 68 69 public static final Operator INCREMENT = new Operator("++"); 71 public static final Operator DECREMENT = new Operator("--"); 73 77 private static final Map CODES; 78 static { 79 CODES = new HashMap (20); 80 Operator[] ops = { 81 INCREMENT, 82 DECREMENT, 83 }; 84 for (int i = 0; i < ops.length; i++) { 85 CODES.put(ops[i].toString(), ops[i]); 86 } 87 } 88 89 101 public static Operator toOperator(String token) { 102 return (Operator) CODES.get(token); 103 } 104 } 105 106 110 public static final SimplePropertyDescriptor OPERATOR_PROPERTY = 111 new SimplePropertyDescriptor(PostfixExpression.class, "operator", PostfixExpression.Operator.class, MANDATORY); 113 117 public static final ChildPropertyDescriptor OPERAND_PROPERTY = 118 new ChildPropertyDescriptor(PostfixExpression.class, "operand", Expression.class, MANDATORY, CYCLE_RISK); 120 125 private static final List PROPERTY_DESCRIPTORS; 126 127 static { 128 List propertyList = new ArrayList (3); 129 createPropertyList(PostfixExpression.class, propertyList); 130 addProperty(OPERAND_PROPERTY, propertyList); 131 addProperty(OPERATOR_PROPERTY, propertyList); 132 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList); 133 } 134 135 146 public static List propertyDescriptors(int apiLevel) { 147 return PROPERTY_DESCRIPTORS; 148 } 149 150 153 private PostfixExpression.Operator operator = 154 PostfixExpression.Operator.INCREMENT; 155 156 160 private Expression operand = null; 161 162 169 PostfixExpression(AST ast) { 170 super(ast); 171 } 172 173 176 final List internalStructuralPropertiesForType(int apiLevel) { 177 return propertyDescriptors(apiLevel); 178 } 179 180 183 final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object value) { 184 if (property == OPERATOR_PROPERTY) { 185 if (get) { 186 return getOperator(); 187 } else { 188 setOperator((Operator) value); 189 return null; 190 } 191 } 192 return super.internalGetSetObjectProperty(property, get, value); 194 } 195 196 199 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 200 if (property == OPERAND_PROPERTY) { 201 if (get) { 202 return getOperand(); 203 } else { 204 setOperand((Expression) child); 205 return null; 206 } 207 } 208 return super.internalGetSetChildProperty(property, get, child); 210 } 211 212 215 final int getNodeType0() { 216 return POSTFIX_EXPRESSION; 217 } 218 219 222 ASTNode clone0(AST target) { 223 PostfixExpression result = new PostfixExpression(target); 224 result.setSourceRange(this.getStartPosition(), this.getLength()); 225 result.setOperator(getOperator()); 226 result.setOperand((Expression) getOperand().clone(target)); 227 return result; 228 } 229 230 233 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 234 return matcher.match(this, other); 236 } 237 238 241 void accept0(ASTVisitor visitor) { 242 boolean visitChildren = visitor.visit(this); 243 if (visitChildren) { 244 acceptChild(visitor, getOperand()); 245 } 246 visitor.endVisit(this); 247 } 248 249 254 public PostfixExpression.Operator getOperator() { 255 return this.operator; 256 } 257 258 264 public void setOperator(PostfixExpression.Operator operator) { 265 if (operator == null) { 266 throw new IllegalArgumentException (); 267 } 268 preValueChange(OPERATOR_PROPERTY); 269 this.operator = operator; 270 postValueChange(OPERATOR_PROPERTY); 271 } 272 273 278 public Expression getOperand() { 279 if (this.operand == null) { 280 synchronized (this) { 282 if (this.operand == null) { 283 preLazyInit(); 284 this.operand= new SimpleName(this.ast); 285 postLazyInit(this.operand, OPERAND_PROPERTY); 286 } 287 } 288 } 289 return this.operand; 290 } 291 292 303 public void setOperand(Expression expression) { 304 if (expression == null) { 305 throw new IllegalArgumentException (); 306 } 307 ASTNode oldChild = this.operand; 308 preReplaceChild(oldChild, expression, OPERAND_PROPERTY); 309 this.operand = expression; 310 postReplaceChild(oldChild, expression, OPERAND_PROPERTY); 311 } 312 313 316 int memSize() { 317 return BASE_NODE_SIZE + 2 * 4; 319 } 320 321 324 int treeSize() { 325 return 326 memSize() 327 + (this.operand == null ? 0 : getOperand().treeSize()); 328 } 329 } 330 | Popular Tags |