1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 32 public class ImportDeclaration extends ASTNode { 33 34 38 public static final ChildPropertyDescriptor NAME_PROPERTY = 39 new ChildPropertyDescriptor(ImportDeclaration.class, "name", Name.class, MANDATORY, NO_CYCLE_RISK); 41 45 public static final SimplePropertyDescriptor ON_DEMAND_PROPERTY = 46 new SimplePropertyDescriptor(ImportDeclaration.class, "onDemand", boolean.class, MANDATORY); 48 52 public static final SimplePropertyDescriptor STATIC_PROPERTY = 53 new SimplePropertyDescriptor(ImportDeclaration.class, "static", boolean.class, MANDATORY); 55 61 private static final List PROPERTY_DESCRIPTORS_2_0; 62 63 69 private static final List PROPERTY_DESCRIPTORS_3_0; 70 71 static { 72 List properyList = new ArrayList (3); 73 createPropertyList(ImportDeclaration.class, properyList); 74 addProperty(NAME_PROPERTY, properyList); 75 addProperty(ON_DEMAND_PROPERTY, properyList); 76 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(properyList); 77 78 properyList = new ArrayList (4); 79 createPropertyList(ImportDeclaration.class, properyList); 80 addProperty(STATIC_PROPERTY, properyList); 81 addProperty(NAME_PROPERTY, properyList); 82 addProperty(ON_DEMAND_PROPERTY, properyList); 83 PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(properyList); 84 } 85 86 97 public static List propertyDescriptors(int apiLevel) { 98 if (apiLevel == AST.JLS2_INTERNAL) { 99 return PROPERTY_DESCRIPTORS_2_0; 100 } else { 101 return PROPERTY_DESCRIPTORS_3_0; 102 } 103 } 104 105 109 private Name importName = null; 110 111 114 private boolean onDemand = false; 115 116 121 private boolean isStatic = false; 122 123 135 ImportDeclaration(AST ast) { 136 super(ast); 137 } 138 139 142 final List internalStructuralPropertiesForType(int apiLevel) { 143 return propertyDescriptors(apiLevel); 144 } 145 146 149 final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { 150 if (property == ON_DEMAND_PROPERTY) { 151 if (get) { 152 return isOnDemand(); 153 } else { 154 setOnDemand(value); 155 return false; 156 } 157 } 158 if (property == STATIC_PROPERTY) { 159 if (get) { 160 return isStatic(); 161 } else { 162 setStatic(value); 163 return false; 164 } 165 } 166 return super.internalGetSetBooleanProperty(property, get, value); 168 } 169 170 173 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 174 if (property == NAME_PROPERTY) { 175 if (get) { 176 return getName(); 177 } else { 178 setName((Name) child); 179 return null; 180 } 181 } 182 return super.internalGetSetChildProperty(property, get, child); 184 } 185 186 189 final int getNodeType0() { 190 return IMPORT_DECLARATION; 191 } 192 193 196 ASTNode clone0(AST target) { 197 ImportDeclaration result = new ImportDeclaration(target); 198 result.setSourceRange(this.getStartPosition(), this.getLength()); 199 result.setOnDemand(isOnDemand()); 200 if (this.ast.apiLevel >= AST.JLS3) { 201 result.setStatic(isStatic()); 202 } 203 result.setName((Name) getName().clone(target)); 204 return result; 205 } 206 207 210 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 211 return matcher.match(this, other); 213 } 214 215 218 void accept0(ASTVisitor visitor) { 219 boolean visitChildren = visitor.visit(this); 220 if (visitChildren) { 221 acceptChild(visitor, getName()); 222 } 223 visitor.endVisit(this); 224 } 225 226 238 public Name getName() { 239 if (this.importName == null) { 240 synchronized (this) { 242 if (this.importName == null) { 243 preLazyInit(); 244 this.importName =this.ast.newQualifiedName( 245 new SimpleName(this.ast), new SimpleName(this.ast)); 246 postLazyInit(this.importName, NAME_PROPERTY); 247 } 248 } 249 } 250 return importName; 251 } 252 253 270 public void setName(Name name) { 271 if (name == null) { 272 throw new IllegalArgumentException (); 273 } 274 ASTNode oldChild = this.importName; 275 preReplaceChild(oldChild, name, NAME_PROPERTY); 276 this.importName = name; 277 postReplaceChild(oldChild, name, NAME_PROPERTY); 278 } 279 280 287 public boolean isOnDemand() { 288 return onDemand; 289 } 290 291 298 public void setOnDemand(boolean onDemand) { 299 preValueChange(ON_DEMAND_PROPERTY); 300 this.onDemand = onDemand; 301 postValueChange(ON_DEMAND_PROPERTY); 302 } 303 304 313 public boolean isStatic() { 314 unsupportedIn2(); 315 return isStatic; 316 } 317 318 327 public void setStatic(boolean isStatic) { 328 unsupportedIn2(); 329 preValueChange(STATIC_PROPERTY); 330 this.isStatic = isStatic; 331 postValueChange(STATIC_PROPERTY); 332 } 333 334 357 public IBinding resolveBinding() { 358 return this.ast.getBindingResolver().resolveImport(this); 359 } 360 361 364 int memSize() { 365 return BASE_NODE_SIZE + 3 * 4; 366 } 367 368 371 int treeSize() { 372 return 373 memSize() 374 + (importName == null ? 0 : getName().treeSize()); 375 } 376 } 377 378 | Popular Tags |