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 ArrayAccess extends Expression { 28 29 33 public static final ChildPropertyDescriptor ARRAY_PROPERTY = 34 new ChildPropertyDescriptor(ArrayAccess.class, "array", Expression.class, MANDATORY, CYCLE_RISK); 36 40 public static final ChildPropertyDescriptor INDEX_PROPERTY = 41 new ChildPropertyDescriptor(ArrayAccess.class, "index", Expression.class, MANDATORY, CYCLE_RISK); 43 48 private static final List PROPERTY_DESCRIPTORS; 49 50 static { 51 List properyList = new ArrayList (3); 52 createPropertyList(ArrayAccess.class, properyList); 53 addProperty(ARRAY_PROPERTY, properyList); 54 addProperty(INDEX_PROPERTY, properyList); 55 PROPERTY_DESCRIPTORS = reapPropertyList(properyList); 56 } 57 58 69 public static List propertyDescriptors(int apiLevel) { 70 return PROPERTY_DESCRIPTORS; 71 } 72 73 77 private Expression arrayExpression = null; 78 79 83 private Expression indexExpression = null; 84 85 95 ArrayAccess(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 == ARRAY_PROPERTY) { 111 if (get) { 112 return getArray(); 113 } else { 114 setArray((Expression) child); 115 return null; 116 } 117 } 118 if (property == INDEX_PROPERTY) { 119 if (get) { 120 return getIndex(); 121 } else { 122 setIndex((Expression) child); 123 return null; 124 } 125 } 126 return super.internalGetSetChildProperty(property, get, child); 128 } 129 130 133 final int getNodeType0() { 134 return ARRAY_ACCESS; 135 } 136 137 140 ASTNode clone0(AST target) { 141 ArrayAccess result = new ArrayAccess(target); 142 result.setSourceRange(this.getStartPosition(), this.getLength()); 143 result.setArray((Expression) getArray().clone(target)); 144 result.setIndex((Expression) getIndex().clone(target)); 145 return result; 146 } 147 148 151 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 152 return matcher.match(this, other); 154 } 155 156 159 void accept0(ASTVisitor visitor) { 160 boolean visitChildren = visitor.visit(this); 161 if (visitChildren) { 162 acceptChild(visitor, getArray()); 164 acceptChild(visitor, getIndex()); 165 } 166 visitor.endVisit(this); 167 } 168 169 174 public Expression getArray() { 175 if (this.arrayExpression == null) { 176 synchronized (this) { 178 if (this.arrayExpression == null) { 179 preLazyInit(); 180 this.arrayExpression = new SimpleName(this.ast); 181 postLazyInit(this.arrayExpression, ARRAY_PROPERTY); 182 } 183 } 184 } 185 return this.arrayExpression; 186 } 187 188 199 public void setArray(Expression expression) { 200 if (expression == null) { 201 throw new IllegalArgumentException (); 202 } 203 ASTNode oldChild = this.arrayExpression; 206 preReplaceChild(oldChild, expression, ARRAY_PROPERTY); 207 this.arrayExpression = expression; 208 postReplaceChild(oldChild, expression, ARRAY_PROPERTY); 209 } 210 211 216 public Expression getIndex() { 217 if (this.indexExpression == null) { 218 synchronized (this) { 220 if (this.indexExpression == null) { 221 preLazyInit(); 222 this.indexExpression = new SimpleName(this.ast); 223 postLazyInit(this.indexExpression, INDEX_PROPERTY); 224 } 225 } 226 } 227 return this.indexExpression; 228 } 229 230 241 public void setIndex(Expression expression) { 242 if (expression == null) { 243 throw new IllegalArgumentException (); 244 } 245 ASTNode oldChild = this.indexExpression; 248 preReplaceChild(oldChild, expression, INDEX_PROPERTY); 249 this.indexExpression = expression; 250 postReplaceChild(oldChild, expression, INDEX_PROPERTY); 251 } 252 253 256 int memSize() { 257 return BASE_NODE_SIZE + 2 * 4; 258 } 259 260 263 int treeSize() { 264 return 265 memSize() 266 + (this.arrayExpression == null ? 0 : getArray().treeSize()) 267 + (this.indexExpression == null ? 0 : getIndex().treeSize()); 268 } 269 } 270 271 | Popular Tags |