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 CastExpression extends Expression { 28 29 33 public static final ChildPropertyDescriptor TYPE_PROPERTY = 34 new ChildPropertyDescriptor(CastExpression.class, "type", Type.class, MANDATORY, NO_CYCLE_RISK); 36 40 public static final ChildPropertyDescriptor EXPRESSION_PROPERTY = 41 new ChildPropertyDescriptor(CastExpression.class, "expression", Expression.class, MANDATORY, CYCLE_RISK); 43 48 private static final List PROPERTY_DESCRIPTORS; 49 50 static { 51 List properyList = new ArrayList (3); 52 createPropertyList(CastExpression.class, properyList); 53 addProperty(TYPE_PROPERTY, properyList); 54 addProperty(EXPRESSION_PROPERTY, properyList); 55 PROPERTY_DESCRIPTORS = reapPropertyList(properyList); 56 } 57 58 68 public static List propertyDescriptors(int apiLevel) { 69 return PROPERTY_DESCRIPTORS; 70 } 71 72 76 private Type type = null; 77 78 82 private Expression expression = null; 83 84 93 CastExpression(AST ast) { 94 super(ast); 95 } 96 97 100 final List internalStructuralPropertiesForType(int apiLevel) { 101 return propertyDescriptors(apiLevel); 102 } 103 104 107 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 108 if (property == EXPRESSION_PROPERTY) { 109 if (get) { 110 return getExpression(); 111 } else { 112 setExpression((Expression) child); 113 return null; 114 } 115 } 116 if (property == TYPE_PROPERTY) { 117 if (get) { 118 return getType(); 119 } else { 120 setType((Type) child); 121 return null; 122 } 123 } 124 return super.internalGetSetChildProperty(property, get, child); 126 } 127 128 131 final int getNodeType0() { 132 return CAST_EXPRESSION; 133 } 134 135 138 ASTNode clone0(AST target) { 139 CastExpression result = new CastExpression(target); 140 result.setSourceRange(this.getStartPosition(), this.getLength()); 141 result.setType((Type) getType().clone(target)); 142 result.setExpression((Expression) getExpression().clone(target)); 143 return result; 144 } 145 146 149 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 150 return matcher.match(this, other); 152 } 153 154 157 void accept0(ASTVisitor visitor) { 158 boolean visitChildren = visitor.visit(this); 159 if (visitChildren) { 160 acceptChild(visitor, getType()); 162 acceptChild(visitor, getExpression()); 163 } 164 visitor.endVisit(this); 165 } 166 167 172 public Type getType() { 173 if (this.type == null) { 174 synchronized (this) { 176 if (this.type == null) { 177 preLazyInit(); 178 this.type = this.ast.newPrimitiveType(PrimitiveType.INT); 179 postLazyInit(this.type, TYPE_PROPERTY); 180 } 181 } 182 } 183 return this.type; 184 } 185 186 196 public void setType(Type type) { 197 if (type == null) { 198 throw new IllegalArgumentException (); 199 } 200 ASTNode oldChild = this.type; 201 preReplaceChild(oldChild, type, TYPE_PROPERTY); 202 this.type = type; 203 postReplaceChild(oldChild, type, TYPE_PROPERTY); 204 } 205 206 211 public Expression getExpression() { 212 if (this.expression == null) { 213 synchronized (this) { 215 if (this.expression == null) { 216 preLazyInit(); 217 this.expression = new SimpleName(this.ast); 218 postLazyInit(this.expression, EXPRESSION_PROPERTY); 219 } 220 } 221 } 222 return this.expression; 223 } 224 225 236 public void setExpression(Expression expression) { 237 if (expression == null) { 238 throw new IllegalArgumentException (); 239 } 240 ASTNode oldChild = this.expression; 241 preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 242 this.expression = expression; 243 postReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); 244 } 245 246 249 int memSize() { 250 return BASE_NODE_SIZE + 2 * 4; 252 } 253 254 257 int treeSize() { 258 return 259 memSize() 260 + (this.expression == null ? 0 : getExpression().treeSize()) 261 + (this.type == null ? 0 : getType().treeSize()); 262 } 263 } 264 | Popular Tags |