1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 40 public class TypeDeclarationStatement extends Statement { 41 42 46 public static final ChildPropertyDescriptor TYPE_DECLARATION_PROPERTY = 47 new ChildPropertyDescriptor(TypeDeclarationStatement.class, "typeDeclaration", TypeDeclaration.class, MANDATORY, CYCLE_RISK); 49 53 public static final ChildPropertyDescriptor DECLARATION_PROPERTY = 54 new ChildPropertyDescriptor(TypeDeclarationStatement.class, "declaration", AbstractTypeDeclaration.class, MANDATORY, 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(TypeDeclarationStatement.class, propertyList); 75 addProperty(TYPE_DECLARATION_PROPERTY, propertyList); 76 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(propertyList); 77 78 propertyList = new ArrayList (2); 79 createPropertyList(TypeDeclarationStatement.class, propertyList); 80 addProperty(DECLARATION_PROPERTY, propertyList); 81 PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(propertyList); 82 } 83 84 95 public static List propertyDescriptors(int apiLevel) { 96 if (apiLevel == AST.JLS2_INTERNAL) { 97 return PROPERTY_DESCRIPTORS_2_0; 98 } else { 99 return PROPERTY_DESCRIPTORS_3_0; 100 } 101 } 102 103 109 private AbstractTypeDeclaration typeDecl = null; 110 111 119 private ChildPropertyDescriptor typeDeclProperty () { 120 if (getAST().apiLevel() == AST.JLS2_INTERNAL) { 121 return TYPE_DECLARATION_PROPERTY; 122 } else { 123 return DECLARATION_PROPERTY; 124 } 125 } 126 127 128 138 TypeDeclarationStatement(AST ast) { 139 super(ast); 140 } 141 142 146 final List internalStructuralPropertiesForType(int apiLevel) { 147 return propertyDescriptors(apiLevel); 148 } 149 150 153 final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 154 if (property == TYPE_DECLARATION_PROPERTY) { 155 if (get) { 156 return getTypeDeclaration(); 157 } else { 158 setTypeDeclaration((TypeDeclaration) child); 159 return null; 160 } 161 } 162 if (property == DECLARATION_PROPERTY) { 163 if (get) { 164 return getDeclaration(); 165 } else { 166 setDeclaration((AbstractTypeDeclaration) child); 167 return null; 168 } 169 } 170 return super.internalGetSetChildProperty(property, get, child); 172 } 173 174 177 final int getNodeType0() { 178 return TYPE_DECLARATION_STATEMENT; 179 } 180 181 184 ASTNode clone0(AST target) { 185 TypeDeclarationStatement result = 186 new TypeDeclarationStatement(target); 187 result.setSourceRange(this.getStartPosition(), this.getLength()); 188 result.copyLeadingComment(this); 189 result.setDeclaration( 190 (AbstractTypeDeclaration) getDeclaration().clone(target)); 191 return result; 192 } 193 194 197 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 198 return matcher.match(this, other); 200 } 201 202 205 void accept0(ASTVisitor visitor) { 206 boolean visitChildren = visitor.visit(this); 207 if (visitChildren) { 208 acceptChild(visitor, getDeclaration()); 209 } 210 visitor.endVisit(this); 211 } 212 213 220 public AbstractTypeDeclaration getDeclaration() { 221 if (this.typeDecl == null) { 222 synchronized (this) { 224 if (this.typeDecl == null) { 225 preLazyInit(); 226 this.typeDecl = new TypeDeclaration(this.ast); 227 postLazyInit(this.typeDecl, typeDeclProperty()); 228 } 229 } 230 } 231 return this.typeDecl; 232 } 233 234 247 public void setDeclaration(AbstractTypeDeclaration decl) { 248 if (decl == null) { 249 throw new IllegalArgumentException (); 250 } 251 ASTNode oldChild = this.typeDecl; 254 ChildPropertyDescriptor typeDeclProperty = typeDeclProperty(); 255 preReplaceChild(oldChild, decl, typeDeclProperty); 256 this.typeDecl= decl; 257 postReplaceChild(oldChild, decl, typeDeclProperty); 258 } 259 260 271 public TypeDeclaration getTypeDeclaration() { 272 return internalGetTypeDeclaration(); 273 } 274 275 280 final TypeDeclaration internalGetTypeDeclaration() { 281 supportedOnlyIn2(); 282 return (TypeDeclaration) getDeclaration(); 283 } 284 285 303 public void setTypeDeclaration(TypeDeclaration decl) { 304 internalSetTypeDeclaration(decl); 305 } 306 307 312 final void internalSetTypeDeclaration(TypeDeclaration decl) { 313 supportedOnlyIn2(); 314 setDeclaration(decl); 316 } 317 318 329 public ITypeBinding resolveBinding() { 330 AbstractTypeDeclaration d = getDeclaration(); 332 if (d instanceof TypeDeclaration) { 333 return ((TypeDeclaration) d).resolveBinding(); 334 } else if (d instanceof AnnotationTypeDeclaration) { 335 return ((AnnotationTypeDeclaration) d).resolveBinding(); 336 } else { 337 return null; 339 } 340 } 341 342 345 int memSize() { 346 return super.memSize() + 1 * 4; 347 } 348 349 352 int treeSize() { 353 return 354 memSize() 355 + (this.typeDecl == null ? 0 : getDeclaration().treeSize()); 356 } 357 } 358 359 | Popular Tags |