1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 41 public class MethodRefParameter extends ASTNode { 42 43 47 public static final ChildPropertyDescriptor TYPE_PROPERTY = 48 new ChildPropertyDescriptor(MethodRefParameter.class, "type", Type.class, MANDATORY, NO_CYCLE_RISK); 50 54 public static final SimplePropertyDescriptor VARARGS_PROPERTY = 55 new SimplePropertyDescriptor(MethodRefParameter.class, "varargs", boolean.class, MANDATORY); 57 61 public static final ChildPropertyDescriptor NAME_PROPERTY = 62 new ChildPropertyDescriptor(MethodRefParameter.class, "name", SimpleName.class, OPTIONAL, NO_CYCLE_RISK); 64 70 private static final List PROPERTY_DESCRIPTORS_2_0; 71 72 78 private static final List PROPERTY_DESCRIPTORS_3_0; 79 80 static { 81 List properyList = new ArrayList (3); 82 createPropertyList(MethodRefParameter.class, properyList); 83 addProperty(TYPE_PROPERTY, properyList); 84 addProperty(NAME_PROPERTY, properyList); 85 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(properyList); 86 87 properyList = new ArrayList (3); 88 createPropertyList(MethodRefParameter.class, properyList); 89 addProperty(TYPE_PROPERTY, properyList); 90 addProperty(VARARGS_PROPERTY, properyList); 91 addProperty(NAME_PROPERTY, properyList); 92 PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(properyList); 93 } 94 95 104 public static List propertyDescriptors(int apiLevel) { 105 if (apiLevel == AST.JLS2_INTERNAL) { 106 return PROPERTY_DESCRIPTORS_2_0; 107 } else { 108 return PROPERTY_DESCRIPTORS_3_0; 109 } 110 } 111 112 116 private Type type = null; 117 118 124 private boolean variableArity = false; 125 126 130 private SimpleName optionalParameterName = null; 131 132 142 MethodRefParameter(AST ast) { 143 super(ast); 144 } 145 146 149 final List internalStructuralPropertiesForType(int apiLevel) { 150 return propertyDescriptors(apiLevel); 151 } 152 153 156 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 157 if (property == TYPE_PROPERTY) { 158 if (get) { 159 return getType(); 160 } else { 161 setType((Type) child); 162 return null; 163 } 164 } 165 if (property == NAME_PROPERTY) { 166 if (get) { 167 return getName(); 168 } else { 169 setName((SimpleName) child); 170 return null; 171 } 172 } 173 return super.internalGetSetChildProperty(property, get, child); 175 } 176 177 180 final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { 181 if (property == VARARGS_PROPERTY) { 182 if (get) { 183 return isVarargs(); 184 } else { 185 setVarargs(value); 186 return false; 187 } 188 } 189 return super.internalGetSetBooleanProperty(property, get, value); 191 } 192 193 196 final int getNodeType0() { 197 return METHOD_REF_PARAMETER; 198 } 199 200 203 ASTNode clone0(AST target) { 204 MethodRefParameter result = new MethodRefParameter(target); 205 result.setSourceRange(this.getStartPosition(), this.getLength()); 206 result.setType((Type) ASTNode.copySubtree(target, getType())); 207 if (this.ast.apiLevel >= AST.JLS3) { 208 result.setVarargs(isVarargs()); 209 } 210 result.setName((SimpleName) ASTNode.copySubtree(target, getName())); 211 return result; 212 } 213 214 217 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 218 return matcher.match(this, other); 220 } 221 222 225 void accept0(ASTVisitor visitor) { 226 boolean visitChildren = visitor.visit(this); 227 if (visitChildren) { 228 acceptChild(visitor, getType()); 230 acceptChild(visitor, getName()); 231 } 232 visitor.endVisit(this); 233 } 234 235 240 public Type getType() { 241 if (this.type == null) { 242 synchronized (this) { 244 if (this.type == null) { 245 preLazyInit(); 246 this.type = this.ast.newPrimitiveType(PrimitiveType.INT); 247 postLazyInit(this.type, TYPE_PROPERTY); 248 } 249 } 250 } 251 return this.type; 252 } 253 254 265 public void setType(Type type) { 266 if (type == null) { 267 throw new IllegalArgumentException (); 268 } 269 ASTNode oldChild = this.type; 270 preReplaceChild(oldChild, type, TYPE_PROPERTY); 271 this.type = type; 272 postReplaceChild(oldChild, type, TYPE_PROPERTY); 273 } 274 275 294 public boolean isVarargs() { 295 unsupportedIn2(); 296 return this.variableArity; 297 } 298 299 307 public void setVarargs(boolean variableArity) { 308 unsupportedIn2(); 309 preValueChange(VARARGS_PROPERTY); 310 this.variableArity = variableArity; 311 postValueChange(VARARGS_PROPERTY); 312 } 313 314 319 public SimpleName getName() { 320 return this.optionalParameterName; 321 } 322 323 334 public void setName(SimpleName name) { 335 ASTNode oldChild = this.optionalParameterName; 336 preReplaceChild(oldChild, name, NAME_PROPERTY); 337 this.optionalParameterName = name; 338 postReplaceChild(oldChild, name, NAME_PROPERTY); 339 } 340 341 344 int memSize() { 345 return BASE_NODE_SIZE + 2 * 5; 346 } 347 348 351 int treeSize() { 352 return 353 memSize() 354 + (this.type == null ? 0 : getType().treeSize()) 355 + (this.optionalParameterName == null ? 0 : getName().treeSize()); 356 } 357 } 358 | Popular Tags |