1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 33 public class PackageDeclaration extends ASTNode { 34 35 39 public static final ChildPropertyDescriptor JAVADOC_PROPERTY = 40 new ChildPropertyDescriptor(PackageDeclaration.class, "javadoc", Javadoc.class, OPTIONAL, NO_CYCLE_RISK); 42 46 public static final ChildListPropertyDescriptor ANNOTATIONS_PROPERTY = 47 new ChildListPropertyDescriptor(PackageDeclaration.class, "annotations", Annotation.class, CYCLE_RISK); 49 53 public static final ChildPropertyDescriptor NAME_PROPERTY = 54 new ChildPropertyDescriptor(PackageDeclaration.class, "name", Name.class, MANDATORY, NO_CYCLE_RISK); 56 62 private static final List PROPERTY_DESCRIPTORS_2_0; 63 64 70 private static final List PROPERTY_DESCRIPTORS_3_0; 71 72 static { 73 List propertyList = new ArrayList (2); 74 createPropertyList(PackageDeclaration.class, propertyList); 75 addProperty(NAME_PROPERTY, propertyList); 76 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(propertyList); 77 78 propertyList = new ArrayList (4); 79 createPropertyList(PackageDeclaration.class, propertyList); 80 addProperty(JAVADOC_PROPERTY, propertyList); 81 addProperty(ANNOTATIONS_PROPERTY, propertyList); 82 addProperty(NAME_PROPERTY, propertyList); 83 PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(propertyList); 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 110 Javadoc optionalDocComment = null; 111 112 118 private ASTNode.NodeList annotations = null; 119 120 124 private Name packageName = null; 125 126 138 PackageDeclaration(AST ast) { 139 super(ast); 140 if (ast.apiLevel >= AST.JLS3) { 141 this.annotations = new ASTNode.NodeList(ANNOTATIONS_PROPERTY); 142 } 143 } 144 145 148 final List internalStructuralPropertiesForType(int apiLevel) { 149 return propertyDescriptors(apiLevel); 150 } 151 152 155 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 156 if (property == JAVADOC_PROPERTY) { 157 if (get) { 158 return getJavadoc(); 159 } else { 160 setJavadoc((Javadoc) child); 161 return null; 162 } 163 } 164 if (property == NAME_PROPERTY) { 165 if (get) { 166 return getName(); 167 } else { 168 setName((Name) child); 169 return null; 170 } 171 } 172 return super.internalGetSetChildProperty(property, get, child); 174 } 175 176 179 final List internalGetChildListProperty(ChildListPropertyDescriptor property) { 180 if (property == ANNOTATIONS_PROPERTY) { 181 return annotations(); 182 } 183 return super.internalGetChildListProperty(property); 185 } 186 187 190 final int getNodeType0() { 191 return PACKAGE_DECLARATION; 192 } 193 194 197 ASTNode clone0(AST target) { 198 PackageDeclaration result = new PackageDeclaration(target); 199 result.setSourceRange(this.getStartPosition(), this.getLength()); 200 if (this.ast.apiLevel >= AST.JLS3) { 201 result.setJavadoc((Javadoc) ASTNode.copySubtree(target, getJavadoc())); 202 result.annotations().addAll(ASTNode.copySubtrees(target, annotations())); 203 } 204 result.setName((Name) getName().clone(target)); 205 return result; 206 } 207 208 211 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 212 return matcher.match(this, other); 214 } 215 216 219 void accept0(ASTVisitor visitor) { 220 boolean visitChildren = visitor.visit(this); 221 if (visitChildren) { 222 if (this.ast.apiLevel >= AST.JLS3) { 223 acceptChild(visitor, getJavadoc()); 224 acceptChildren(visitor, this.annotations); 225 } 226 acceptChild(visitor, getName()); 227 } 228 visitor.endVisit(this); 229 } 230 231 241 public List annotations() { 242 if (this.annotations == null) { 244 unsupportedIn2(); 245 } 246 return this.annotations; 247 } 248 249 257 public Javadoc getJavadoc() { 258 if (this.annotations == null) { 260 unsupportedIn2(); 261 } 262 return this.optionalDocComment; 263 } 264 265 274 public void setJavadoc(Javadoc docComment) { 275 if (this.annotations == null) { 277 unsupportedIn2(); 278 } 279 ASTNode oldChild = this.optionalDocComment; 280 preReplaceChild(oldChild, docComment, JAVADOC_PROPERTY); 281 this.optionalDocComment = docComment; 282 postReplaceChild(oldChild, docComment, JAVADOC_PROPERTY); 283 } 284 285 290 public Name getName() { 291 if (this.packageName == null) { 292 synchronized (this) { 294 if (this.packageName == null) { 295 preLazyInit(); 296 this.packageName = new SimpleName(this.ast); 297 postLazyInit(this.packageName, NAME_PROPERTY); 298 } 299 } 300 } 301 return this.packageName; 302 } 303 304 314 public void setName(Name name) { 315 if (name == null) { 316 throw new IllegalArgumentException (); 317 } 318 ASTNode oldChild = this.packageName; 319 preReplaceChild(oldChild, name, NAME_PROPERTY); 320 this.packageName = name; 321 postReplaceChild(oldChild, name, NAME_PROPERTY); 322 } 323 324 335 public IPackageBinding resolveBinding() { 336 return this.ast.getBindingResolver().resolvePackage(this); 337 } 338 339 342 int memSize() { 343 return BASE_NODE_SIZE + 3 * 4; 344 } 345 346 349 int treeSize() { 350 return 351 memSize() 352 + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize()) 353 + (this.annotations == null ? 0 : this.annotations.listSize()) 354 + (this.packageName == null ? 0 : getName().treeSize()); 355 } 356 } 357 358 | Popular Tags |