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 PrefixExpression extends Expression { 30 31 43 public static class Operator { 44 45 48 private String token; 49 50 59 private Operator(String token) { 60 this.token = token; 61 } 62 63 68 public String toString() { 69 return token; 70 } 71 72 73 public static final Operator INCREMENT = new Operator("++"); 75 public static final Operator DECREMENT = new Operator("--"); 77 public static final Operator PLUS = new Operator("+"); 79 public static final Operator MINUS = new Operator("-"); 81 public static final Operator COMPLEMENT = new Operator("~"); 83 public static final Operator NOT = new Operator("!"); 85 89 private static final Map CODES; 90 static { 91 CODES = new HashMap (20); 92 Operator[] ops = { 93 INCREMENT, 94 DECREMENT, 95 PLUS, 96 MINUS, 97 COMPLEMENT, 98 NOT, 99 }; 100 for (int i = 0; i < ops.length; i++) { 101 CODES.put(ops[i].toString(), ops[i]); 102 } 103 } 104 105 117 public static Operator toOperator(String token) { 118 return (Operator) CODES.get(token); 119 } 120 } 121 122 126 public static final SimplePropertyDescriptor OPERATOR_PROPERTY = 127 new SimplePropertyDescriptor(PrefixExpression.class, "operator", PrefixExpression.Operator.class, MANDATORY); 129 133 public static final ChildPropertyDescriptor OPERAND_PROPERTY = 134 new ChildPropertyDescriptor(PrefixExpression.class, "operand", Expression.class, MANDATORY, CYCLE_RISK); 136 141 private static final List PROPERTY_DESCRIPTORS; 142 143 static { 144 List propertyList = new ArrayList (3); 145 createPropertyList(PrefixExpression.class, propertyList); 146 addProperty(OPERATOR_PROPERTY, propertyList); 147 addProperty(OPERAND_PROPERTY, propertyList); 148 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList); 149 } 150 151 162 public static List propertyDescriptors(int apiLevel) { 163 return PROPERTY_DESCRIPTORS; 164 } 165 166 169 private PrefixExpression.Operator operator = 170 PrefixExpression.Operator.PLUS; 171 172 176 private Expression operand = null; 177 178 185 PrefixExpression(AST ast) { 186 super(ast); 187 } 188 189 192 final List internalStructuralPropertiesForType(int apiLevel) { 193 return propertyDescriptors(apiLevel); 194 } 195 196 199 final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object value) { 200 if (property == OPERATOR_PROPERTY) { 201 if (get) { 202 return getOperator(); 203 } else { 204 setOperator((Operator) value); 205 return null; 206 } 207 } 208 return super.internalGetSetObjectProperty(property, get, value); 210 } 211 212 215 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 216 if (property == OPERAND_PROPERTY) { 217 if (get) { 218 return getOperand(); 219 } else { 220 setOperand((Expression) child); 221 return null; 222 } 223 } 224 return super.internalGetSetChildProperty(property, get, child); 226 } 227 228 231 final int getNodeType0() { 232 return PREFIX_EXPRESSION; 233 } 234 235 238 ASTNode clone0(AST target) { 239 PrefixExpression result = new PrefixExpression(target); 240 result.setSourceRange(this.getStartPosition(), this.getLength()); 241 result.setOperator(getOperator()); 242 result.setOperand((Expression) getOperand().clone(target)); 243 return result; 244 } 245 246 249 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 250 return matcher.match(this, other); 252 } 253 254 257 void accept0(ASTVisitor visitor) { 258 boolean visitChildren = visitor.visit(this); 259 if (visitChildren) { 260 acceptChild(visitor, getOperand()); 262 } 263 visitor.endVisit(this); 264 } 265 266 271 public PrefixExpression.Operator getOperator() { 272 return this.operator; 273 } 274 275 281 public void setOperator(PrefixExpression.Operator operator) { 282 if (operator == null) { 283 throw new IllegalArgumentException (); 284 } 285 preValueChange(OPERATOR_PROPERTY); 286 this.operator = operator; 287 postValueChange(OPERATOR_PROPERTY); 288 } 289 290 295 public Expression getOperand() { 296 if (this.operand == null) { 297 synchronized (this) { 299 if (this.operand == null) { 300 preLazyInit(); 301 this.operand= new SimpleName(this.ast); 302 postLazyInit(this.operand, OPERAND_PROPERTY); 303 } 304 } 305 } 306 return this.operand; 307 } 308 309 320 public void setOperand(Expression expression) { 321 if (expression == null) { 322 throw new IllegalArgumentException (); 323 } 324 ASTNode oldChild = this.operand; 325 preReplaceChild(oldChild, expression, OPERAND_PROPERTY); 326 this.operand = expression; 327 postReplaceChild(oldChild, expression, OPERAND_PROPERTY); 328 } 329 330 333 int memSize() { 334 return BASE_NODE_SIZE + 2 * 4; 336 } 337 338 341 int treeSize() { 342 return 343 memSize() 344 + (this.operand == null ? 0 : getOperand().treeSize()); 345 } 346 } 347 348 | Popular Tags |