KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > dom > TypeDeclaration


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.core.dom;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17
18 /**
19  * Type declaration AST node type. A type declaration
20  * is the union of a class declaration and an interface declaration.
21  * For JLS2:
22  * <pre>
23  * TypeDeclaration:
24  * ClassDeclaration
25  * InterfaceDeclaration
26  * ClassDeclaration:
27  * [ Javadoc ] { Modifier } <b>class</b> Identifier
28  * [ <b>extends</b> Type]
29  * [ <b>implements</b> Type { <b>,</b> Type } ]
30  * <b>{</b> { ClassBodyDeclaration | <b>;</b> } <b>}</b>
31  * InterfaceDeclaration:
32  * [ Javadoc ] { Modifier } <b>interface</b> Identifier
33  * [ <b>extends</b> Type { <b>,</b> Type } ]
34  * <b>{</b> { InterfaceBodyDeclaration | <b>;</b> } <b>}</b>
35  * </pre>
36  * For JLS3, type parameters and reified modifiers
37  * (and annotations) were added, and the superclass type name and superinterface
38  * types names are generalized to type so that parameterized types can be
39  * referenced:
40  * <pre>
41  * TypeDeclaration:
42  * ClassDeclaration
43  * InterfaceDeclaration
44  * ClassDeclaration:
45  * [ Javadoc ] { ExtendedModifier } <b>class</b> Identifier
46  * [ <b>&lt;</b> TypeParameter { <b>,</b> TypeParameter } <b>&gt;</b> ]
47  * [ <b>extends</b> Type ]
48  * [ <b>implements</b> Type { <b>,</b> Type } ]
49  * <b>{</b> { ClassBodyDeclaration | <b>;</b> } <b>}</b>
50  * InterfaceDeclaration:
51  * [ Javadoc ] { ExtendedModifier } <b>interface</b> Identifier
52  * [ <b>&lt;</b> TypeParameter { <b>,</b> TypeParameter } <b>&gt;</b> ]
53  * [ <b>extends</b> Type { <b>,</b> Type } ]
54  * <b>{</b> { InterfaceBodyDeclaration | <b>;</b> } <b>}</b>
55  * </pre>
56  * <p>
57  * When a Javadoc comment is present, the source
58  * range begins with the first character of the "/**" comment delimiter.
59  * When there is no Javadoc comment, the source range begins with the first
60  * character of the first modifier or annotation (if any), or the
61  * first character of the "class" or "interface" keyword (if no
62  * modifiers or annotations). The source range extends through the last character of the "}"
63  * token following the body declarations.
64  * </p>
65  *
66  * @since 2.0
67  */

68 public class TypeDeclaration extends AbstractTypeDeclaration {
69     
70     /**
71      * The "javadoc" structural property of this node type.
72      * @since 3.0
73      */

74     public static final ChildPropertyDescriptor JAVADOC_PROPERTY =
75         internalJavadocPropertyFactory(TypeDeclaration.class);
76
77     /**
78      * The "modifiers" structural property of this node type (JLS2 API only).
79      * @since 3.0
80      */

81     public static final SimplePropertyDescriptor MODIFIERS_PROPERTY =
82         internalModifiersPropertyFactory(TypeDeclaration.class);
83     
84     /**
85      * The "modifiers" structural property of this node type (added in JLS3 API).
86      * @since 3.1
87      */

88     public static final ChildListPropertyDescriptor MODIFIERS2_PROPERTY =
89         internalModifiers2PropertyFactory(TypeDeclaration.class);
90     
91     /**
92      * The "interface" structural property of this node type.
93      * @since 3.0
94      */

95     public static final SimplePropertyDescriptor INTERFACE_PROPERTY =
96         new SimplePropertyDescriptor(TypeDeclaration.class, "interface", boolean.class, MANDATORY); //$NON-NLS-1$
97

98     /**
99      * The "name" structural property of this node type.
100      * @since 3.0
101      */

102     public static final ChildPropertyDescriptor NAME_PROPERTY =
103         new ChildPropertyDescriptor(TypeDeclaration.class, "name", SimpleName.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
104

105     /**
106      * The "superclass" structural property of this node type (JLS2 API only).
107      * @since 3.0
108      */

109     public static final ChildPropertyDescriptor SUPERCLASS_PROPERTY =
110         new ChildPropertyDescriptor(TypeDeclaration.class, "superclass", Name.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
111

112     /**
113      * The "superInterfaces" structural property of this node type (JLS2 API only).
114      * @since 3.0
115      */

116     public static final ChildListPropertyDescriptor SUPER_INTERFACES_PROPERTY =
117         new ChildListPropertyDescriptor(TypeDeclaration.class, "superInterfaces", Name.class, NO_CYCLE_RISK); //$NON-NLS-1$
118

119     /**
120      * The "superclassType" structural property of this node type (added in JLS3 API).
121      * @since 3.1
122      */

123     public static final ChildPropertyDescriptor SUPERCLASS_TYPE_PROPERTY =
124         new ChildPropertyDescriptor(TypeDeclaration.class, "superclassType", Type.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
125

126     /**
127      * The "superInterfaceTypes" structural property of this node type (added in JLS3 API).
128      * @since 3.1
129      */

130     public static final ChildListPropertyDescriptor SUPER_INTERFACE_TYPES_PROPERTY =
131         new ChildListPropertyDescriptor(TypeDeclaration.class, "superInterfaceTypes", Type.class, NO_CYCLE_RISK); //$NON-NLS-1$
132

133     /**
134      * The "typeParameters" structural property of this node type (added in JLS3 API).
135      * @since 3.1
136      */

137     public static final ChildListPropertyDescriptor TYPE_PARAMETERS_PROPERTY =
138         new ChildListPropertyDescriptor(TypeDeclaration.class, "typeParameters", TypeParameter.class, NO_CYCLE_RISK); //$NON-NLS-1$
139

140     /**
141      * The "bodyDeclarations" structural property of this node type (added in JLS3 API).
142      * @since 3.0
143      */

144     public static final ChildListPropertyDescriptor BODY_DECLARATIONS_PROPERTY =
145         internalBodyDeclarationPropertyFactory(TypeDeclaration.class);
146     
147     /**
148      * A list of property descriptors (element type:
149      * {@link StructuralPropertyDescriptor}),
150      * or null if uninitialized.
151      * @since 3.0
152      */

153     private static final List JavaDoc PROPERTY_DESCRIPTORS_2_0;
154     
155     /**
156      * A list of property descriptors (element type:
157      * {@link StructuralPropertyDescriptor}),
158      * or null if uninitialized.
159      * @since 3.1
160      */

161     private static final List JavaDoc PROPERTY_DESCRIPTORS_3_0;
162     
163     static {
164         List JavaDoc propertyList = new ArrayList JavaDoc(8);
165         createPropertyList(TypeDeclaration.class, propertyList);
166         addProperty(JAVADOC_PROPERTY, propertyList);
167         addProperty(MODIFIERS_PROPERTY, propertyList);
168         addProperty(INTERFACE_PROPERTY, propertyList);
169         addProperty(NAME_PROPERTY, propertyList);
170         addProperty(SUPERCLASS_PROPERTY, propertyList);
171         addProperty(SUPER_INTERFACES_PROPERTY, propertyList);
172         addProperty(BODY_DECLARATIONS_PROPERTY, propertyList);
173         PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(propertyList);
174         
175         propertyList = new ArrayList JavaDoc(9);
176         createPropertyList(TypeDeclaration.class, propertyList);
177         addProperty(JAVADOC_PROPERTY, propertyList);
178         addProperty(MODIFIERS2_PROPERTY, propertyList);
179         addProperty(INTERFACE_PROPERTY, propertyList);
180         addProperty(NAME_PROPERTY, propertyList);
181         addProperty(TYPE_PARAMETERS_PROPERTY, propertyList);
182         addProperty(SUPERCLASS_TYPE_PROPERTY, propertyList);
183         addProperty(SUPER_INTERFACE_TYPES_PROPERTY, propertyList);
184         addProperty(BODY_DECLARATIONS_PROPERTY, propertyList);
185         PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(propertyList);
186     }
187
188     /**
189      * Returns a list of structural property descriptors for this node type.
190      * Clients must not modify the result.
191      *
192      * @param apiLevel the API level; one of the
193      * <code>AST.JLS&ast;</code> constants
194
195      * @return a list of property descriptors (element type:
196      * {@link StructuralPropertyDescriptor})
197      * @since 3.0
198      */

199     public static List JavaDoc propertyDescriptors(int apiLevel) {
200         if (apiLevel == AST.JLS2_INTERNAL) {
201             return PROPERTY_DESCRIPTORS_2_0;
202         } else {
203             return PROPERTY_DESCRIPTORS_3_0;
204         }
205     }
206             
207     /**
208      * <code>true</code> for an interface, <code>false</code> for a class.
209      * Defaults to class.
210      */

211     private boolean isInterface = false;
212     
213     /**
214      * The type paramters (element type: <code>TypeParameter</code>).
215      * Null in JLS2. Added in JLS3; defaults to an empty list
216      * (see constructor).
217      * @since 3.1
218      */

219     private ASTNode.NodeList typeParameters = null;
220
221     /**
222      * The optional superclass name; <code>null</code> if none.
223      * Defaults to none. Note that this field is not used for
224      * interface declarations. Not used in 3.0.
225      */

226     private Name optionalSuperclassName = null;
227
228     /**
229      * The superinterface names (element type: <code>Name</code>).
230      * JLS2 only; defaults to an empty list. Not used in JLS3.
231      * (see constructor).
232      *
233      */

234     private ASTNode.NodeList superInterfaceNames = null;
235
236     /**
237      * The optional superclass type; <code>null</code> if none.
238      * Defaults to none. Note that this field is not used for
239      * interface declarations. Null in JLS2. Added in JLS3.
240      * @since 3.1
241      */

242     private Type optionalSuperclassType = null;
243
244     /**
245      * The superinterface types (element type: <code>Type</code>).
246      * Null in JLS2. Added in JLS3; defaults to an empty list
247      * (see constructor).
248      * @since 3.1
249      */

250     private ASTNode.NodeList superInterfaceTypes = null;
251
252     /**
253      * Creates a new AST node for a type declaration owned by the given
254      * AST. By default, the type declaration is for a class of an
255      * unspecified, but legal, name; no modifiers; no javadoc;
256      * no type parameters; no superclass or superinterfaces; and an empty list
257      * of body declarations.
258      * <p>
259      * N.B. This constructor is package-private; all subclasses must be
260      * declared in the same package; clients are unable to declare
261      * additional subclasses.
262      * </p>
263      *
264      * @param ast the AST that is to own this node
265      */

266     TypeDeclaration(AST ast) {
267         super(ast);
268         if (ast.apiLevel == AST.JLS2_INTERNAL) {
269             this.superInterfaceNames = new ASTNode.NodeList(SUPER_INTERFACES_PROPERTY);
270         }
271         if (ast.apiLevel >= AST.JLS3) {
272             this.typeParameters = new ASTNode.NodeList(TYPE_PARAMETERS_PROPERTY);
273             this.superInterfaceTypes = new ASTNode.NodeList(SUPER_INTERFACE_TYPES_PROPERTY);
274         }
275     }
276
277     /* (omit javadoc for this method)
278      * Method declared on ASTNode.
279      * @since 3.0
280      */

281     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
282         return propertyDescriptors(apiLevel);
283     }
284     
285     /* (omit javadoc for this method)
286      * Method declared on ASTNode.
287      */

288     final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) {
289         if (property == MODIFIERS_PROPERTY) {
290             if (get) {
291                 return getModifiers();
292             } else {
293                 internalSetModifiers(value);
294                 return 0;
295             }
296         }
297         // allow default implementation to flag the error
298
return super.internalGetSetIntProperty(property, get, value);
299     }
300
301     /* (omit javadoc for this method)
302      * Method declared on ASTNode.
303      */

304     final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) {
305         if (property == INTERFACE_PROPERTY) {
306             if (get) {
307                 return isInterface();
308             } else {
309                 setInterface(value);
310                 return false;
311             }
312         }
313         // allow default implementation to flag the error
314
return super.internalGetSetBooleanProperty(property, get, value);
315     }
316     
317     /* (omit javadoc for this method)
318      * Method declared on ASTNode.
319      */

320     final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
321         if (property == JAVADOC_PROPERTY) {
322             if (get) {
323                 return getJavadoc();
324             } else {
325                 setJavadoc((Javadoc) child);
326                 return null;
327             }
328         }
329         if (property == NAME_PROPERTY) {
330             if (get) {
331                 return getName();
332             } else {
333                 setName((SimpleName) child);
334                 return null;
335             }
336         }
337         if (property == SUPERCLASS_PROPERTY) {
338             if (get) {
339                 return getSuperclass();
340             } else {
341                 setSuperclass((Name) child);
342                 return null;
343             }
344         }
345         if (property == SUPERCLASS_TYPE_PROPERTY) {
346             if (get) {
347                 return getSuperclassType();
348             } else {
349                 setSuperclassType((Type) child);
350                 return null;
351             }
352         }
353         // allow default implementation to flag the error
354
return super.internalGetSetChildProperty(property, get, child);
355     }
356     
357     /* (omit javadoc for this method)
358      * Method declared on ASTNode.
359      */

360     final List JavaDoc internalGetChildListProperty(ChildListPropertyDescriptor property) {
361         if (property == MODIFIERS2_PROPERTY) {
362             return modifiers();
363         }
364         if (property == TYPE_PARAMETERS_PROPERTY) {
365             return typeParameters();
366         }
367         if (property == SUPER_INTERFACES_PROPERTY) {
368             return superInterfaces();
369         }
370         if (property == SUPER_INTERFACE_TYPES_PROPERTY) {
371             return superInterfaceTypes();
372         }
373         if (property == BODY_DECLARATIONS_PROPERTY) {
374             return bodyDeclarations();
375         }
376         // allow default implementation to flag the error
377
return super.internalGetChildListProperty(property);
378     }
379     
380     /* (omit javadoc for this method)
381      * Method declared on BodyDeclaration.
382      */

383     final ChildPropertyDescriptor internalJavadocProperty() {
384         return JAVADOC_PROPERTY;
385     }
386
387     /* (omit javadoc for this method)
388      * Method declared on BodyDeclaration.
389      */

390     final ChildListPropertyDescriptor internalModifiers2Property() {
391         return MODIFIERS2_PROPERTY;
392     }
393
394     /* (omit javadoc for this method)
395      * Method declared on BodyDeclaration.
396      */

397     final SimplePropertyDescriptor internalModifiersProperty() {
398         return MODIFIERS_PROPERTY;
399     }
400
401     /* (omit javadoc for this method)
402      * Method declared on AbstractTypeDeclaration.
403      */

404     final ChildPropertyDescriptor internalNameProperty() {
405         return NAME_PROPERTY;
406     }
407
408     /* (omit javadoc for this method)
409      * Method declared on AbstractTypeDeclaration.
410      */

411     final ChildListPropertyDescriptor internalBodyDeclarationsProperty() {
412         return BODY_DECLARATIONS_PROPERTY;
413     }
414
415
416     /* (omit javadoc for this method)
417      * Method declared on ASTNode.
418      */

419     final int getNodeType0() {
420         return TYPE_DECLARATION;
421     }
422
423     /* (omit javadoc for this method)
424      * Method declared on ASTNode.
425      */

426     ASTNode clone0(AST target) {
427         TypeDeclaration result = new TypeDeclaration(target);
428         result.setSourceRange(this.getStartPosition(), this.getLength());
429         result.setJavadoc(
430             (Javadoc) ASTNode.copySubtree(target, getJavadoc()));
431         if (this.ast.apiLevel == AST.JLS2_INTERNAL) {
432             result.internalSetModifiers(getModifiers());
433             result.setSuperclass(
434                     (Name) ASTNode.copySubtree(target, getSuperclass()));
435             result.superInterfaces().addAll(
436                     ASTNode.copySubtrees(target, superInterfaces()));
437         }
438         result.setInterface(isInterface());
439         result.setName((SimpleName) getName().clone(target));
440         if (this.ast.apiLevel >= AST.JLS3) {
441             result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers()));
442             result.typeParameters().addAll(
443                     ASTNode.copySubtrees(target, typeParameters()));
444             result.setSuperclassType(
445                     (Type) ASTNode.copySubtree(target, getSuperclassType()));
446             result.superInterfaceTypes().addAll(
447                     ASTNode.copySubtrees(target, superInterfaceTypes()));
448         }
449         result.bodyDeclarations().addAll(
450             ASTNode.copySubtrees(target, bodyDeclarations()));
451         return result;
452     }
453
454     /* (omit javadoc for this method)
455      * Method declared on ASTNode.
456      */

457     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
458         // dispatch to correct overloaded match method
459
return matcher.match(this, other);
460     }
461     
462     /* (omit javadoc for this method)
463      * Method declared on ASTNode.
464      */

465     void accept0(ASTVisitor visitor) {
466         boolean visitChildren = visitor.visit(this);
467         if (visitChildren) {
468             // visit children in normal left to right reading order
469
if (this.ast.apiLevel == AST.JLS2_INTERNAL) {
470                 acceptChild(visitor, getJavadoc());
471                 acceptChild(visitor, getName());
472                 acceptChild(visitor, getSuperclass());
473                 acceptChildren(visitor, this.superInterfaceNames);
474                 acceptChildren(visitor, this.bodyDeclarations);
475             }
476             if (this.ast.apiLevel >= AST.JLS3) {
477                 acceptChild(visitor, getJavadoc());
478                 acceptChildren(visitor, this.modifiers);
479                 acceptChild(visitor, getName());
480                 acceptChildren(visitor, this.typeParameters);
481                 acceptChild(visitor, getSuperclassType());
482                 acceptChildren(visitor, this.superInterfaceTypes);
483                 acceptChildren(visitor, this.bodyDeclarations);
484             }
485         }
486         visitor.endVisit(this);
487     }
488     
489     /**
490      * Returns whether this type declaration declares a class or an
491      * interface.
492      *
493      * @return <code>true</code> if this is an interface declaration,
494      * and <code>false</code> if this is a class declaration
495      */

496     public boolean isInterface() {
497         return this.isInterface;
498     }
499     
500     /**
501      * Sets whether this type declaration declares a class or an
502      * interface.
503      *
504      * @param isInterface <code>true</code> if this is an interface
505      * declaration, and <code>false</code> if this is a class
506      * declaration
507      */

508     public void setInterface(boolean isInterface) {
509         preValueChange(INTERFACE_PROPERTY);
510         this.isInterface = isInterface;
511         postValueChange(INTERFACE_PROPERTY);
512     }
513
514     /**
515      * Returns the live ordered list of type parameters of this type
516      * declaration (added in JLS3 API). This list is non-empty for parameterized types.
517      *
518      * @return the live list of type parameters
519      * (element type: <code>TypeParameter</code>)
520      * @exception UnsupportedOperationException if this operation is used in
521      * a JLS2 AST
522      * @since 3.1
523      */

524     public List JavaDoc typeParameters() {
525         // more efficient than just calling unsupportedIn2() to check
526
if (this.typeParameters == null) {
527             unsupportedIn2();
528         }
529         return this.typeParameters;
530     }
531     
532     /**
533      * Returns the name of the superclass declared in this type
534      * declaration, or <code>null</code> if there is none (JLS2 API only).
535      * <p>
536      * Note that this child is not relevant for interface
537      * declarations (although it does still figure in subtree
538      * equality comparisons).
539      * </p>
540      *
541      * @return the superclass name node, or <code>null</code> if
542      * there is none
543      * @exception UnsupportedOperationException if this operation is used in
544      * an AST later than JLS2
545      * @deprecated In the JLS3 API, this method is replaced by
546      * {@link #getSuperclassType()}, which returns a <code>Type</code>
547      * instead of a <code>Name</code>.
548      */

549     public Name getSuperclass() {
550         return internalGetSuperclass();
551     }
552     
553     /**
554      * Internal synonym for deprecated method. Used to avoid
555      * deprecation warnings.
556      * @since 3.1
557      */

558     /*package*/ final Name internalGetSuperclass() {
559         supportedOnlyIn2();
560         return this.optionalSuperclassName;
561     }
562
563     /**
564     * Returns the superclass declared in this type
565     * declaration, or <code>null</code> if there is none (added in JLS3 API).
566     * <p>
567     * Note that this child is not relevant for interface
568     * declarations (although it does still figure in subtree
569     * equality comparisons).
570     * </p>
571     *
572     * @return the superclass type node, or <code>null</code> if
573     * there is none
574     * @exception UnsupportedOperationException if this operation is used in
575     * a JLS2 AST
576     * @since 3.1
577     */

578     public Type getSuperclassType() {
579         unsupportedIn2();
580         return this.optionalSuperclassType;
581     }
582
583     /**
584      * Sets or clears the name of the superclass declared in this type
585      * declaration (JLS2 API only).
586      * <p>
587      * Note that this child is not relevant for interface
588      * declarations (although it does still figure in subtree
589      * equality comparisons).
590      * </p>
591      *
592      * @param superclassName the superclass name node, or <code>null</code> if
593      * there is none
594      * @exception IllegalArgumentException if:
595      * <ul>
596      * <li>the node belongs to a different AST</li>
597      * <li>the node already has a parent</li>
598      * </ul>
599      * @exception UnsupportedOperationException if this operation is used in
600      * an AST later than JLS2
601      * @deprecated In the JLS3 API, this method is replaced by
602      * {@link #setSuperclassType(Type)}, which expects a
603      * <code>Type</code> instead of a <code>Name</code>.
604      */

605     public void setSuperclass(Name superclassName) {
606         internalSetSuperclass(superclassName);
607     }
608     
609     /**
610      * Internal synonym for deprecated method. Used to avoid
611      * deprecation warnings.
612      * @since 3.1
613      */

614     /*package*/ final void internalSetSuperclass(Name superclassName) {
615         supportedOnlyIn2();
616         ASTNode oldChild = this.optionalSuperclassName;
617         preReplaceChild(oldChild, superclassName, SUPERCLASS_PROPERTY);
618         this.optionalSuperclassName = superclassName;
619         postReplaceChild(oldChild, superclassName, SUPERCLASS_PROPERTY);
620     }
621
622     /**
623      * Sets or clears the superclass declared in this type
624      * declaration (added in JLS3 API).
625      * <p>
626      * Note that this child is not relevant for interface declarations
627      * (although it does still figure in subtree equality comparisons).
628      * </p>
629      *
630      * @param superclassType the superclass type node, or <code>null</code> if
631      * there is none
632      * @exception IllegalArgumentException if:
633      * <ul>
634      * <li>the node belongs to a different AST</li>
635      * <li>the node already has a parent</li>
636      * </ul>
637      * @exception UnsupportedOperationException if this operation is used in
638      * a JLS2 AST
639      * @since 3.1
640      */

641     public void setSuperclassType(Type superclassType) {
642         unsupportedIn2();
643         ASTNode oldChild = this.optionalSuperclassType;
644         preReplaceChild(oldChild, superclassType, SUPERCLASS_TYPE_PROPERTY);
645         this.optionalSuperclassType = superclassType;
646         postReplaceChild(oldChild, superclassType, SUPERCLASS_TYPE_PROPERTY);
647     }
648
649     /**
650      * Returns the live ordered list of names of superinterfaces of this type
651      * declaration (JLS2 API only). For a class declaration, these are the names
652      * of the interfaces that this class implements; for an interface
653      * declaration, these are the names of the interfaces that this interface
654      * extends.
655      *
656      * @return the live list of interface names
657      * (element type: <code>Name</code>)
658      * @exception UnsupportedOperationException if this operation is used in
659      * an AST later than JLS2
660      * @deprecated In the JLS3 API, this method is replaced by
661      * {@link #superInterfaceTypes()}.
662      */

663     public List JavaDoc superInterfaces() {
664         return internalSuperInterfaces();
665     }
666     
667     /**
668      * Internal synonym for deprecated method. Used to avoid
669      * deprecation warnings.
670      * @since 3.1
671      */

672     /*package*/ final List JavaDoc internalSuperInterfaces() {
673         // more efficient than just calling supportedOnlyIn2() to check
674
if (this.superInterfaceNames == null) {
675             supportedOnlyIn2();
676         }
677         return this.superInterfaceNames;
678     }
679     
680     /**
681      * Returns the live ordered list of superinterfaces of this type
682      * declaration (added in JLS3 API). For a class declaration, these are the interfaces
683      * that this class implements; for an interface declaration,
684      * these are the interfaces that this interface extends.
685      *
686      * @return the live list of interface types
687      * (element type: <code>Type</code>)
688      * @exception UnsupportedOperationException if this operation is used in
689      * a JLS2 AST
690      * @since 3.1
691      */

692     public List JavaDoc superInterfaceTypes() {
693         // more efficient than just calling unsupportedIn2() to check
694
if (this.superInterfaceTypes == null) {
695             unsupportedIn2();
696         }
697         return this.superInterfaceTypes;
698     }
699     
700     /**
701      * Returns the ordered list of field declarations of this type
702      * declaration. For a class declaration, these are the
703      * field declarations; for an interface declaration, these are
704      * the constant declarations.
705      * <p>
706      * This convenience method returns this node's body declarations
707      * with non-fields filtered out. Unlike <code>bodyDeclarations</code>,
708      * this method does not return a live result.
709      * </p>
710      *
711      * @return the (possibly empty) list of field declarations
712      */

713     public FieldDeclaration[] getFields() {
714         List JavaDoc bd = bodyDeclarations();
715         int fieldCount = 0;
716         for (Iterator JavaDoc it = bd.listIterator(); it.hasNext(); ) {
717             if (it.next() instanceof FieldDeclaration) {
718                 fieldCount++;
719             }
720         }
721         FieldDeclaration[] fields = new FieldDeclaration[fieldCount];
722         int next = 0;
723         for (Iterator JavaDoc it = bd.listIterator(); it.hasNext(); ) {
724             Object JavaDoc decl = it.next();
725             if (decl instanceof FieldDeclaration) {
726                 fields[next++] = (FieldDeclaration) decl;
727             }
728         }
729         return fields;
730     }
731
732     /**
733      * Returns the ordered list of method declarations of this type
734      * declaration.
735      * <p>
736      * This convenience method returns this node's body declarations
737      * with non-methods filtered out. Unlike <code>bodyDeclarations</code>,
738      * this method does not return a live result.
739      * </p>
740      *
741      * @return the (possibly empty) list of method (and constructor)
742      * declarations
743      */

744     public MethodDeclaration[] getMethods() {
745         List JavaDoc bd = bodyDeclarations();
746         int methodCount = 0;
747         for (Iterator JavaDoc it = bd.listIterator(); it.hasNext(); ) {
748             if (it.next() instanceof MethodDeclaration) {
749                 methodCount++;
750             }
751         }
752         MethodDeclaration[] methods = new MethodDeclaration[methodCount];
753         int next = 0;
754         for (Iterator JavaDoc it = bd.listIterator(); it.hasNext(); ) {
755             Object JavaDoc decl = it.next();
756             if (decl instanceof MethodDeclaration) {
757                 methods[next++] = (MethodDeclaration) decl;
758             }
759         }
760         return methods;
761     }
762
763     /**
764      * Returns the ordered list of member type declarations of this type
765      * declaration.
766      * <p>
767      * This convenience method returns this node's body declarations
768      * with non-types filtered out. Unlike <code>bodyDeclarations</code>,
769      * this method does not return a live result.
770      * </p>
771      *
772      * @return the (possibly empty) list of member type declarations
773      */

774     public TypeDeclaration[] getTypes() {
775         List JavaDoc bd = bodyDeclarations();
776         int typeCount = 0;
777         for (Iterator JavaDoc it = bd.listIterator(); it.hasNext(); ) {
778             if (it.next() instanceof TypeDeclaration) {
779                 typeCount++;
780             }
781         }
782         TypeDeclaration[] memberTypes = new TypeDeclaration[typeCount];
783         int next = 0;
784         for (Iterator JavaDoc it = bd.listIterator(); it.hasNext(); ) {
785             Object JavaDoc decl = it.next();
786             if (decl instanceof TypeDeclaration) {
787                 memberTypes[next++] = (TypeDeclaration) decl;
788             }
789         }
790         return memberTypes;
791     }
792
793     /* (omit javadoc for this method)
794      * Method declared on AsbtractTypeDeclaration.
795      */

796     ITypeBinding internalResolveBinding() {
797         return this.ast.getBindingResolver().resolveType(this);
798     }
799     
800     /* (omit javadoc for this method)
801      * Method declared on ASTNode.
802      */

803     int memSize() {
804         return super.memSize() + 6 * 4;
805     }
806     
807     /* (omit javadoc for this method)
808      * Method declared on ASTNode.
809      */

810     int treeSize() {
811         return memSize()
812             + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize())
813             + (this.modifiers == null ? 0 : this.modifiers.listSize())
814             + (this.typeName == null ? 0 : getName().treeSize())
815             + (this.typeParameters == null ? 0 : this.typeParameters.listSize())
816             + (this.optionalSuperclassName == null ? 0 : getSuperclass().treeSize())
817             + (this.optionalSuperclassType == null ? 0 : getSuperclassType().treeSize())
818             + (this.superInterfaceNames == null ? 0 : this.superInterfaceNames.listSize())
819             + (this.superInterfaceTypes == null ? 0 : this.superInterfaceTypes.listSize())
820             + this.bodyDeclarations.listSize();
821     }
822 }
823
824
Popular Tags