Lines 22-27
Link Here
|
22 |
* TypeDeclaration: |
22 |
* TypeDeclaration: |
23 |
* ClassDeclaration |
23 |
* ClassDeclaration |
24 |
* InterfaceDeclaration |
24 |
* InterfaceDeclaration |
|
|
25 |
* EnumDeclaration |
25 |
* ClassDeclaration: |
26 |
* ClassDeclaration: |
26 |
* [ Javadoc ] { Modifier } <b>class</b> Identifier |
27 |
* [ Javadoc ] { Modifier } <b>class</b> Identifier |
27 |
* [ <b>extends</b> Type] |
28 |
* [ <b>extends</b> Type] |
Lines 31-46
Link Here
|
31 |
* [ Javadoc ] { Modifier } <b>interface</b> Identifier |
32 |
* [ Javadoc ] { Modifier } <b>interface</b> Identifier |
32 |
* [ <b>extends</b> Type { <b>,</b> Type } ] |
33 |
* [ <b>extends</b> Type { <b>,</b> Type } ] |
33 |
* <b>{</b> { InterfaceBodyDeclaration | <b>;</b> } <b>}</b> |
34 |
* <b>{</b> { InterfaceBodyDeclaration | <b>;</b> } <b>}</b> |
|
|
35 |
* EnumDeclaration: |
36 |
* [ Javadoc ] { Modifier } <b>enum</b> Identifier |
37 |
* [ <b>implements</b> Type { <b>,</b> Type } ] |
38 |
* <b>{</b> |
39 |
* [ EnumConstantDeclaration [ <b>,</b> EnumConstantDeclaration ] ] |
40 |
* [ <b>;</b> { ClassBodyDeclaration | <b>;</b> } ] |
41 |
* <b>}</b> |
34 |
* </pre> |
42 |
* </pre> |
35 |
* <p> |
43 |
* <p> |
36 |
* When a Javadoc comment is present, the source |
44 |
* When a Javadoc comment is present, the source |
37 |
* range begins with the first character of the "/**" comment delimiter. |
45 |
* range begins with the first character of the "/**" comment delimiter. |
38 |
* When there is no Javadoc comment, the source range begins with the first |
46 |
* When there is no Javadoc comment, the source range begins with the first |
39 |
* character of the first modifier keyword (if modifiers), or the |
47 |
* character of the first modifier keyword (if modifiers), or the |
40 |
* first character of the "class" or "interface": keyword (if no modifiers). |
48 |
* first character of the "class", "interface", or "enum" keyword (if no |
41 |
* The source range extends through the last character of the ";" token (if |
49 |
* modifiers). The source range extends through the last character of the "}" |
42 |
* no body), or the last character of the "}" token following the body |
50 |
* token following the body declarations. |
43 |
* declarations. |
51 |
* </p> |
|
|
52 |
* <p> |
53 |
* Note: Enum declarations are an experimental language feature |
54 |
* under discussion in JSR-201 and under consideration for inclusion |
55 |
* in the 1.5 release of J2SE. The support here is therefore tentative |
56 |
* and subject to change. |
44 |
* </p> |
57 |
* </p> |
45 |
* |
58 |
* |
46 |
* @since 2.0 |
59 |
* @since 2.0 |
Lines 62-67
Link Here
|
62 |
private boolean isInterface = false; |
75 |
private boolean isInterface = false; |
63 |
|
76 |
|
64 |
/** |
77 |
/** |
|
|
78 |
* <code>true</code> for an enumeration, <code>false</code> for a class. |
79 |
* Defaults to class. This field is ignored for interfaces. |
80 |
* <p> |
81 |
* Note: Enum declarations are an experimental language feature |
82 |
* under discussion in JSR-201 and under consideration for inclusion |
83 |
* in the 1.5 release of J2SE. The support here is therefore tentative |
84 |
* and subject to change. |
85 |
* </p> |
86 |
* |
87 |
* @since 2.2 |
88 |
*/ |
89 |
private boolean isEnumeration = false; |
90 |
|
91 |
/** |
65 |
* The modifiers; bit-wise or of Modifier flags. |
92 |
* The modifiers; bit-wise or of Modifier flags. |
66 |
* Defaults to none. |
93 |
* Defaults to none. |
67 |
*/ |
94 |
*/ |
Lines 129-134
Link Here
|
129 |
result.setJavadoc( |
156 |
result.setJavadoc( |
130 |
(Javadoc) ASTNode.copySubtree(target,(ASTNode) getJavadoc())); |
157 |
(Javadoc) ASTNode.copySubtree(target,(ASTNode) getJavadoc())); |
131 |
result.setInterface(isInterface()); |
158 |
result.setInterface(isInterface()); |
|
|
159 |
result.setEnumeration(isEnumeration()); |
132 |
result.setName((SimpleName) getName().clone(target)); |
160 |
result.setName((SimpleName) getName().clone(target)); |
133 |
result.setSuperclass( |
161 |
result.setSuperclass( |
134 |
(Name) ASTNode.copySubtree(target,(ASTNode) getSuperclass())); |
162 |
(Name) ASTNode.copySubtree(target,(ASTNode) getSuperclass())); |
Lines 168-174
Link Here
|
168 |
* interface. |
196 |
* interface. |
169 |
* |
197 |
* |
170 |
* @return <code>true</code> if this is an interface declaration, |
198 |
* @return <code>true</code> if this is an interface declaration, |
171 |
* and <code>false</code> if this is a class declaration |
199 |
* and <code>false</code> if this is a class or enumeration declaration |
172 |
*/ |
200 |
*/ |
173 |
public boolean isInterface() { |
201 |
public boolean isInterface() { |
174 |
return isInterface; |
202 |
return isInterface; |
Lines 179-185
Link Here
|
179 |
* interface. |
207 |
* interface. |
180 |
* |
208 |
* |
181 |
* @param isInterface <code>true</code> if this is an interface |
209 |
* @param isInterface <code>true</code> if this is an interface |
182 |
* declaration, and <code>false</code> if this is a class |
210 |
* declaration, and <code>false</code> if this is a class or enumeration |
183 |
* declaration |
211 |
* declaration |
184 |
*/ |
212 |
*/ |
185 |
public void setInterface(boolean isInterface) { |
213 |
public void setInterface(boolean isInterface) { |
Lines 188-193
Link Here
|
188 |
} |
216 |
} |
189 |
|
217 |
|
190 |
/** |
218 |
/** |
|
|
219 |
* Returns whether this type declaration declares a class or an |
220 |
* enumeration. Note that this property is not relevant for interfaces. |
221 |
* <p> |
222 |
* Note: Enum declarations are an experimental language feature |
223 |
* under discussion in JSR-201 and under consideration for inclusion |
224 |
* in the 1.5 release of J2SE. The support here is therefore tentative |
225 |
* and subject to change. |
226 |
* </p> |
227 |
* |
228 |
* @return <code>true</code> if this is an enumeration declaration, |
229 |
* and <code>false</code> if this is a class declaration |
230 |
* @since 2.2 |
231 |
*/ |
232 |
public boolean isEnumeration() { |
233 |
return isEnumeration; |
234 |
} |
235 |
|
236 |
/** |
237 |
* Sets whether this type declaration declares a class or an |
238 |
* enumeration. Note that this property is not relevant for interfaces. |
239 |
* <p> |
240 |
* Note: Enum declarations are an experimental language feature |
241 |
* under discussion in JSR-201 and under consideration for inclusion |
242 |
* in the 1.5 release of J2SE. The support here is therefore tentative |
243 |
* and subject to change. |
244 |
* </p> |
245 |
* |
246 |
* @param isEnumeration <code>true</code> if this is an enumeration |
247 |
* declaration, and <code>false</code> if this is a class |
248 |
* declaration |
249 |
* @since 2.2 |
250 |
*/ |
251 |
public void setEnumeration(boolean isEnumeration) { |
252 |
modifying(); |
253 |
this.isEnumeration = isEnumeration; |
254 |
} |
255 |
|
256 |
/** |
191 |
* Returns the modifiers explicitly specified on this declaration. |
257 |
* Returns the modifiers explicitly specified on this declaration. |
192 |
* <p> |
258 |
* <p> |
193 |
* Note that deprecated is not included. |
259 |
* Note that deprecated is not included. |
Lines 266-273
Link Here
|
266 |
* Returns the name of the superclass declared in this type |
332 |
* Returns the name of the superclass declared in this type |
267 |
* declaration, or <code>null</code> if there is none. |
333 |
* declaration, or <code>null</code> if there is none. |
268 |
* <p> |
334 |
* <p> |
269 |
* Note that this child is not relevant for interface declarations |
335 |
* Note that this child is not relevant for interface and |
270 |
* (although it does still figure in subtree equality comparisons). |
336 |
* enumeration declarations (although it does still figure in subtree |
|
|
337 |
* equality comparisons). |
271 |
* </p> |
338 |
* </p> |
272 |
* |
339 |
* |
273 |
* @return the superclass name node, or <code>null</code> if |
340 |
* @return the superclass name node, or <code>null</code> if |
Lines 281-288
Link Here
|
281 |
* Sets or clears the name of the superclass declared in this type |
348 |
* Sets or clears the name of the superclass declared in this type |
282 |
* declaration. |
349 |
* declaration. |
283 |
* <p> |
350 |
* <p> |
284 |
* Note that this child is not relevant for interface declarations |
351 |
* Note that this child is not relevant for interface and |
285 |
* (although it does still figure in subtree equality comparisons). |
352 |
* enumeration declarations (although it does still figure in subtree |
|
|
353 |
* equality comparisons). |
286 |
* </p> |
354 |
* </p> |
287 |
* |
355 |
* |
288 |
* @param superclassName the superclass name node, or <code>null</code> if |
356 |
* @param superclassName the superclass name node, or <code>null</code> if |
Lines 302-310
Link Here
|
302 |
|
370 |
|
303 |
/** |
371 |
/** |
304 |
* Returns the live ordered list of names of superinterfaces of this type |
372 |
* Returns the live ordered list of names of superinterfaces of this type |
305 |
* declaration. For a class declaration, these are the names of the |
373 |
* declaration. For a class or enumeration declaration, these are the names |
306 |
* interfaces that this class implements; for an interface declaration, |
374 |
* of the interfaces that this class implements; for an interface |
307 |
* these are the names of the interfaces that this interface extends. |
375 |
* declaration, these are the names of the interfaces that this interface |
|
|
376 |
* extends. |
308 |
* |
377 |
* |
309 |
* @return the live list of interface names |
378 |
* @return the live list of interface names |
310 |
* (element type: <code>Name</code>) |
379 |
* (element type: <code>Name</code>) |
Lines 317-324
Link Here
|
317 |
* Returns the live ordered list of body declarations of this type |
386 |
* Returns the live ordered list of body declarations of this type |
318 |
* declaration. For a class declaration, these are the |
387 |
* declaration. For a class declaration, these are the |
319 |
* initializer, field, method, constructor, and member type |
388 |
* initializer, field, method, constructor, and member type |
320 |
* declarations; for an interface declaration, these are |
389 |
* declarations; for an interface declaration, these are the constant, |
321 |
* the constant, method, and member type declarations. |
390 |
* method, and member type declarations. For an enumeration declaration, |
|
|
391 |
* these are the enum constant declarations, which are always at the |
392 |
* front of the list, followed by any initializer, field, method, |
393 |
* constructor, and member type declarations. |
322 |
* |
394 |
* |
323 |
* @return the live list of body declarations |
395 |
* @return the live list of body declarations |
324 |
* (element type: <code>BodyDeclaration</code>) |
396 |
* (element type: <code>BodyDeclaration</code>) |
Lines 331-337
Link Here
|
331 |
* Returns the ordered list of field declarations of this type |
403 |
* Returns the ordered list of field declarations of this type |
332 |
* declaration. For a class declaration, these are the |
404 |
* declaration. For a class declaration, these are the |
333 |
* field declarations; for an interface declaration, these are |
405 |
* field declarations; for an interface declaration, these are |
334 |
* the constant declarations. |
406 |
* the constant declarations; for an enum declaration, these are |
|
|
407 |
* the explicitly declared field declarations (excludes enum |
408 |
* constant declarations). |
335 |
* <p> |
409 |
* <p> |
336 |
* This convenience method returns this node's body declarations |
410 |
* This convenience method returns this node's body declarations |
337 |
* with non-fields filtered out. Unlike <code>bodyDeclarations</code>, |
411 |
* with non-fields filtered out. Unlike <code>bodyDeclarations</code>, |
Lines 421-426
Link Here
|
421 |
} |
495 |
} |
422 |
|
496 |
|
423 |
/** |
497 |
/** |
|
|
498 |
* Returns the ordered list of enum constant declarations of this enum |
499 |
* declaration. This method is not relevant for class and interface |
500 |
* declarations, for which enum constant declarations are meaningless. |
501 |
* <p> |
502 |
* This convenience method returns this node's enum constant declarations |
503 |
* with non-enum constants filtered out. Unlike <code>bodyDeclarations</code>, |
504 |
* this method does not return a live result. |
505 |
* </p> |
506 |
* <p> |
507 |
* Note: Enum declarations are an experimental language feature |
508 |
* under discussion in JSR-201 and under consideration for inclusion |
509 |
* in the 1.5 release of J2SE. The support here is therefore tentative |
510 |
* and subject to change. |
511 |
* </p> |
512 |
* |
513 |
* @return the (possibly empty) list of enum constant declarations |
514 |
* @since 2.2 |
515 |
*/ |
516 |
public EnumConstantDeclaration[] getEnumConstants() { |
517 |
List bd = bodyDeclarations(); |
518 |
int enumCount = 0; |
519 |
for (Iterator it = bd.listIterator(); it.hasNext(); ) { |
520 |
if (it.next() instanceof EnumConstantDeclaration) { |
521 |
enumCount++; |
522 |
} |
523 |
} |
524 |
EnumConstantDeclaration[] enumConstants = new EnumConstantDeclaration[enumCount]; |
525 |
int next = 0; |
526 |
for (Iterator it = bd.listIterator(); it.hasNext(); ) { |
527 |
Object decl = it.next(); |
528 |
if (decl instanceof EnumConstantDeclaration) { |
529 |
enumConstants[next++] = (EnumConstantDeclaration) decl; |
530 |
} |
531 |
} |
532 |
return enumConstants; |
533 |
} |
534 |
|
535 |
/** |
424 |
* Returns whether this type declaration is a package member (that is, |
536 |
* Returns whether this type declaration is a package member (that is, |
425 |
* a top-level type). |
537 |
* a top-level type). |
426 |
* <p> |
538 |
* <p> |
Lines 440-457
Link Here
|
440 |
* Returns whether this type declaration is a type member. |
552 |
* Returns whether this type declaration is a type member. |
441 |
* <p> |
553 |
* <p> |
442 |
* Note that this is a convenience method that simply checks whether |
554 |
* Note that this is a convenience method that simply checks whether |
443 |
* this node's parent is a type declaration node or an anonymous |
555 |
* this node's parent is a type declaration node, an anonymous |
444 |
* class declaration. |
556 |
* class declaration, or an enumeration constant declaration. |
445 |
* </p> |
557 |
* </p> |
446 |
* |
558 |
* |
447 |
* @return <code>true</code> if this type declaration is a child of |
559 |
* @return <code>true</code> if this type declaration is a child of |
448 |
* a type declaration node or a class instance creation node, and |
560 |
* a type declaration node, a class instance creation node, or an |
449 |
* <code>false</code> otherwise |
561 |
* enum constant declaration, and <code>false</code> otherwise |
450 |
*/ |
562 |
*/ |
451 |
public boolean isMemberTypeDeclaration() { |
563 |
public boolean isMemberTypeDeclaration() { |
452 |
ASTNode parent = getParent(); |
564 |
ASTNode parent = getParent(); |
453 |
return (parent instanceof TypeDeclaration) |
565 |
return (parent instanceof TypeDeclaration) |
454 |
|| (parent instanceof AnonymousClassDeclaration); |
566 |
|| (parent instanceof AnonymousClassDeclaration) |
|
|
567 |
|| (parent instanceof EnumConstantDeclaration); |
455 |
} |
568 |
} |
456 |
|
569 |
|
457 |
/** |
570 |
/** |
Lines 488-512
Link Here
|
488 |
* Method declared on ASTNode. |
601 |
* Method declared on ASTNode. |
489 |
*/ |
602 |
*/ |
490 |
void appendDebugString(StringBuffer buffer) { |
603 |
void appendDebugString(StringBuffer buffer) { |
491 |
buffer.append("TypeDeclaration[");//$NON-NLS-1$ |
604 |
buffer.append("TypeDeclaration["); //$NON-NLS-1$ |
492 |
buffer.append(isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$ |
605 |
buffer.append(isInterface() |
|
|
606 |
? "interface " //$NON-NLS-1$ |
607 |
: (isEnumeration() |
608 |
? "enum " : "class ")); //$NON-NLS-2$//$NON-NLS-1$ |
493 |
buffer.append(getName().getIdentifier()); |
609 |
buffer.append(getName().getIdentifier()); |
494 |
buffer.append(" ");//$NON-NLS-1$ |
610 |
buffer.append(" "); //$NON-NLS-1$ |
495 |
for (Iterator it = bodyDeclarations().iterator(); it.hasNext(); ) { |
611 |
for (Iterator it = bodyDeclarations().iterator(); it.hasNext();) { |
496 |
BodyDeclaration d = (BodyDeclaration) it.next(); |
612 |
BodyDeclaration d = (BodyDeclaration) it.next(); |
497 |
d.appendDebugString(buffer); |
613 |
d.appendDebugString(buffer); |
498 |
if (it.hasNext()) { |
614 |
if (it.hasNext()) { |
499 |
buffer.append(";");//$NON-NLS-1$ |
615 |
buffer.append(";"); //$NON-NLS-1$ |
500 |
} |
616 |
} |
501 |
} |
617 |
} |
502 |
buffer.append("]");//$NON-NLS-1$ |
618 |
buffer.append("]"); //$NON-NLS-1$ |
503 |
} |
619 |
} |
504 |
|
620 |
|
505 |
/* (omit javadoc for this method) |
621 |
/* (omit javadoc for this method) |
506 |
* Method declared on ASTNode. |
622 |
* Method declared on ASTNode. |
507 |
*/ |
623 |
*/ |
508 |
int memSize() { |
624 |
int memSize() { |
509 |
return super.memSize() + 6 * 4; |
625 |
return super.memSize() + 7 * 4; |
510 |
} |
626 |
} |
511 |
|
627 |
|
512 |
/* (omit javadoc for this method) |
628 |
/* (omit javadoc for this method) |