Initial upgrade to Platform/JDT 3.4.1
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / TypeDeclaration.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2008 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 net.sourceforge.phpdt.core.dom;
13
14 import java.util.ArrayList;
15 import java.util.Iterator;
16 import java.util.List;
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  * @noinstantiate This class is not intended to be instantiated by clients.
68  */
69 public class TypeDeclaration extends AbstractTypeDeclaration {
70         
71         /**
72          * The "javadoc" structural property of this node type.
73          * @since 3.0
74          */
75         public static final ChildPropertyDescriptor JAVADOC_PROPERTY = 
76                 internalJavadocPropertyFactory(TypeDeclaration.class);
77
78         /**
79          * The "modifiers" structural property of this node type (JLS2 API only).
80          * @since 3.0
81          */
82         public static final SimplePropertyDescriptor MODIFIERS_PROPERTY = 
83                 internalModifiersPropertyFactory(TypeDeclaration.class);
84         
85         /**
86          * The "modifiers" structural property of this node type (added in JLS3 API).
87          * @since 3.1
88          */
89         public static final ChildListPropertyDescriptor MODIFIERS2_PROPERTY = 
90                 internalModifiers2PropertyFactory(TypeDeclaration.class);
91         
92         /**
93          * The "interface" structural property of this node type.
94          * @since 3.0
95          */
96         public static final SimplePropertyDescriptor INTERFACE_PROPERTY = 
97                 new SimplePropertyDescriptor(TypeDeclaration.class, "interface", boolean.class, MANDATORY); //$NON-NLS-1$
98         
99         /**
100          * The "name" structural property of this node type.
101          * @since 3.0
102          */
103         public static final ChildPropertyDescriptor NAME_PROPERTY =
104                 internalNamePropertyFactory(TypeDeclaration.class);
105
106         /**
107          * The "superclass" structural property of this node type (JLS2 API only).
108          * @since 3.0
109          */
110         public static final ChildPropertyDescriptor SUPERCLASS_PROPERTY = 
111                 new ChildPropertyDescriptor(TypeDeclaration.class, "superclass", Name.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
112
113         /**
114          * The "superInterfaces" structural property of this node type (JLS2 API only).
115          * @since 3.0
116          */
117         public static final ChildListPropertyDescriptor SUPER_INTERFACES_PROPERTY = 
118                 new ChildListPropertyDescriptor(TypeDeclaration.class, "superInterfaces", Name.class, NO_CYCLE_RISK); //$NON-NLS-1$
119
120         /**
121          * The "superclassType" structural property of this node type (added in JLS3 API).
122          * @since 3.1
123          */
124         public static final ChildPropertyDescriptor SUPERCLASS_TYPE_PROPERTY = 
125                 new ChildPropertyDescriptor(TypeDeclaration.class, "superclassType", Type.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
126
127         /**
128          * The "superInterfaceTypes" structural property of this node type (added in JLS3 API).
129          * @since 3.1
130          */
131         public static final ChildListPropertyDescriptor SUPER_INTERFACE_TYPES_PROPERTY = 
132                 new ChildListPropertyDescriptor(TypeDeclaration.class, "superInterfaceTypes", Type.class, NO_CYCLE_RISK); //$NON-NLS-1$
133         
134         /**
135          * The "typeParameters" structural property of this node type (added in JLS3 API).
136          * @since 3.1
137          */
138         public static final ChildListPropertyDescriptor TYPE_PARAMETERS_PROPERTY = 
139                 new ChildListPropertyDescriptor(TypeDeclaration.class, "typeParameters", TypeParameter.class, NO_CYCLE_RISK); //$NON-NLS-1$
140         
141         /**
142          * The "bodyDeclarations" structural property of this node type (added in JLS3 API).
143          * @since 3.0
144          */
145         public static final ChildListPropertyDescriptor BODY_DECLARATIONS_PROPERTY = 
146                 internalBodyDeclarationPropertyFactory(TypeDeclaration.class);
147         
148         /**
149          * A list of property descriptors (element type: 
150          * {@link StructuralPropertyDescriptor}),
151          * or null if uninitialized.
152          * @since 3.0
153          */
154         private static final List PROPERTY_DESCRIPTORS_2_0;
155         
156         /**
157          * A list of property descriptors (element type: 
158          * {@link StructuralPropertyDescriptor}),
159          * or null if uninitialized.
160          * @since 3.1
161          */
162         private static final List PROPERTY_DESCRIPTORS_3_0;
163         
164         static {
165                 List propertyList = new ArrayList(8);
166                 createPropertyList(TypeDeclaration.class, propertyList);
167                 addProperty(JAVADOC_PROPERTY, propertyList);
168                 addProperty(MODIFIERS_PROPERTY, propertyList);
169                 addProperty(INTERFACE_PROPERTY, propertyList);
170                 addProperty(NAME_PROPERTY, propertyList);
171                 addProperty(SUPERCLASS_PROPERTY, propertyList);
172                 addProperty(SUPER_INTERFACES_PROPERTY, propertyList);
173                 addProperty(BODY_DECLARATIONS_PROPERTY, propertyList);
174                 PROPERTY_DESCRIPTORS_2_0 = reapPropertyList(propertyList);
175                 
176                 propertyList = new ArrayList(9);
177                 createPropertyList(TypeDeclaration.class, propertyList);
178                 addProperty(JAVADOC_PROPERTY, propertyList);
179                 addProperty(MODIFIERS2_PROPERTY, propertyList);
180                 addProperty(INTERFACE_PROPERTY, propertyList);
181                 addProperty(NAME_PROPERTY, propertyList);
182                 addProperty(TYPE_PARAMETERS_PROPERTY, propertyList);
183                 addProperty(SUPERCLASS_TYPE_PROPERTY, propertyList);
184                 addProperty(SUPER_INTERFACE_TYPES_PROPERTY, propertyList);
185                 addProperty(BODY_DECLARATIONS_PROPERTY, propertyList);
186                 PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(propertyList);
187         }
188
189         /**
190          * Returns a list of structural property descriptors for this node type.
191          * Clients must not modify the result.
192          * 
193          * @param apiLevel the API level; one of the
194          * <code>AST.JLS*</code> constants
195
196          * @return a list of property descriptors (element type: 
197          * {@link StructuralPropertyDescriptor})
198          * @since 3.0
199          */
200         public static List propertyDescriptors(int apiLevel) {
201                 if (apiLevel == AST.JLS2_INTERNAL) {
202                         return PROPERTY_DESCRIPTORS_2_0;
203                 } else {
204                         return PROPERTY_DESCRIPTORS_3_0;
205                 }
206         }
207                         
208         /**
209          * <code>true</code> for an interface, <code>false</code> for a class.
210          * Defaults to class.
211          */
212         private boolean isInterface = false;
213         
214         /**
215          * The type paramters (element type: <code>TypeParameter</code>). 
216          * Null in JLS2. Added in JLS3; defaults to an empty list
217          * (see constructor).
218          * @since 3.1
219          */
220         private ASTNode.NodeList typeParameters = null;
221
222         /**
223          * The optional superclass name; <code>null</code> if none.
224          * Defaults to none. Note that this field is not used for
225          * interface declarations. Not used in 3.0.
226          */
227         private Name optionalSuperclassName = null;
228
229         /**
230          * The superinterface names (element type: <code>Name</code>). 
231          * JLS2 only; defaults to an empty list. Not used in JLS3.
232          * (see constructor).
233          * 
234          */
235         private ASTNode.NodeList superInterfaceNames = null;
236
237         /**
238          * The optional superclass type; <code>null</code> if none.
239          * Defaults to none. Note that this field is not used for
240          * interface declarations. Null in JLS2. Added in JLS3.
241          * @since 3.1
242          */
243         private Type optionalSuperclassType = null;
244
245         /**
246          * The superinterface types (element type: <code>Type</code>). 
247          * Null in JLS2. Added in JLS3; defaults to an empty list
248          * (see constructor).
249          * @since 3.1
250          */
251         private ASTNode.NodeList superInterfaceTypes = null;
252
253         /**
254          * Creates a new AST node for a type declaration owned by the given 
255          * AST. By default, the type declaration is for a class of an
256          * unspecified, but legal, name; no modifiers; no javadoc; 
257          * no type parameters; no superclass or superinterfaces; and an empty list
258          * of body declarations.
259          * <p>
260          * N.B. This constructor is package-private; all subclasses must be 
261          * declared in the same package; clients are unable to declare 
262          * additional subclasses.
263          * </p>
264          * 
265          * @param ast the AST that is to own this node
266          */
267         TypeDeclaration(AST ast) {
268                 super(ast);
269                 if (ast.apiLevel == AST.JLS2_INTERNAL) {
270                         this.superInterfaceNames = new ASTNode.NodeList(SUPER_INTERFACES_PROPERTY);
271                 }
272                 if (ast.apiLevel >= AST.JLS3) {
273                         this.typeParameters = new ASTNode.NodeList(TYPE_PARAMETERS_PROPERTY);
274                         this.superInterfaceTypes = new ASTNode.NodeList(SUPER_INTERFACE_TYPES_PROPERTY);
275                 }
276         }
277
278         /* (omit javadoc for this method)
279          * Method declared on ASTNode.
280          * @since 3.0
281          */
282         final List internalStructuralPropertiesForType(int apiLevel) {
283                 return propertyDescriptors(apiLevel);
284         }
285         
286         /* (omit javadoc for this method)
287          * Method declared on ASTNode.
288          */
289         final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) {
290                 if (property == MODIFIERS_PROPERTY) {
291                         if (get) {
292                                 return getModifiers();
293                         } else {
294                                 internalSetModifiers(value);
295                                 return 0;
296                         }
297                 }
298                 // allow default implementation to flag the error
299                 return super.internalGetSetIntProperty(property, get, value);
300         }
301
302         /* (omit javadoc for this method)
303          * Method declared on ASTNode.
304          */
305         final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) {
306                 if (property == INTERFACE_PROPERTY) {
307                         if (get) {
308                                 return isInterface();
309                         } else {
310                                 setInterface(value);
311                                 return false;
312                         }
313                 }
314                 // allow default implementation to flag the error
315                 return super.internalGetSetBooleanProperty(property, get, value);
316         }
317         
318         /* (omit javadoc for this method)
319          * Method declared on ASTNode.
320          */
321         final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
322                 if (property == JAVADOC_PROPERTY) {
323                         if (get) {
324                                 return getJavadoc();
325                         } else {
326                                 setJavadoc((Javadoc) child);
327                                 return null;
328                         }
329                 }
330                 if (property == NAME_PROPERTY) {
331                         if (get) {
332                                 return getName();
333                         } else {
334                                 setName((SimpleName) child);
335                                 return null;
336                         }
337                 }
338                 if (property == SUPERCLASS_PROPERTY) {
339                         if (get) {
340                                 return getSuperclass();
341                         } else {
342                                 setSuperclass((Name) child);
343                                 return null;
344                         }
345                 }
346                 if (property == SUPERCLASS_TYPE_PROPERTY) {
347                         if (get) {
348                                 return getSuperclassType();
349                         } else {
350                                 setSuperclassType((Type) child);
351                                 return null;
352                         }
353                 }
354                 // allow default implementation to flag the error
355                 return super.internalGetSetChildProperty(property, get, child);
356         }
357         
358         /* (omit javadoc for this method)
359          * Method declared on ASTNode.
360          */
361         final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
362                 if (property == MODIFIERS2_PROPERTY) {
363                         return modifiers();
364                 }
365                 if (property == TYPE_PARAMETERS_PROPERTY) {
366                         return typeParameters();
367                 }
368                 if (property == SUPER_INTERFACES_PROPERTY) {
369                         return superInterfaces();
370                 }
371                 if (property == SUPER_INTERFACE_TYPES_PROPERTY) {
372                         return superInterfaceTypes();
373                 }
374                 if (property == BODY_DECLARATIONS_PROPERTY) {
375                         return bodyDeclarations();
376                 }
377                 // allow default implementation to flag the error
378                 return super.internalGetChildListProperty(property);
379         }
380         
381         /* (omit javadoc for this method)
382          * Method declared on BodyDeclaration.
383          */
384         final ChildPropertyDescriptor internalJavadocProperty() {
385                 return JAVADOC_PROPERTY;
386         }
387
388         /* (omit javadoc for this method)
389          * Method declared on BodyDeclaration.
390          */
391         final ChildListPropertyDescriptor internalModifiers2Property() {
392                 return MODIFIERS2_PROPERTY;
393         }
394
395         /* (omit javadoc for this method)
396          * Method declared on BodyDeclaration.
397          */
398         final SimplePropertyDescriptor internalModifiersProperty() {
399                 return MODIFIERS_PROPERTY;
400         }
401
402         /* (omit javadoc for this method)
403          * Method declared on AbstractTypeDeclaration.
404          */
405         final ChildPropertyDescriptor internalNameProperty() {
406                 return NAME_PROPERTY;
407         }
408
409         /* (omit javadoc for this method)
410          * Method declared on AbstractTypeDeclaration.
411          */
412         final ChildListPropertyDescriptor internalBodyDeclarationsProperty() {
413                 return BODY_DECLARATIONS_PROPERTY;
414         }
415
416
417         /* (omit javadoc for this method)
418          * Method declared on ASTNode.
419          */
420         final int getNodeType0() {
421                 return TYPE_DECLARATION;
422         }
423
424         /* (omit javadoc for this method)
425          * Method declared on ASTNode.
426          */
427         ASTNode clone0(AST target) {
428                 TypeDeclaration result = new TypeDeclaration(target);
429                 result.setSourceRange(this.getStartPosition(), this.getLength());
430                 result.setJavadoc(
431                         (Javadoc) ASTNode.copySubtree(target, getJavadoc()));
432                 if (this.ast.apiLevel == AST.JLS2_INTERNAL) {
433                         result.internalSetModifiers(getModifiers());
434                         result.setSuperclass(
435                                         (Name) ASTNode.copySubtree(target, getSuperclass()));
436                         result.superInterfaces().addAll(
437                                         ASTNode.copySubtrees(target, superInterfaces()));
438                 }
439                 result.setInterface(isInterface());
440                 result.setName((SimpleName) getName().clone(target));
441                 if (this.ast.apiLevel >= AST.JLS3) {
442                         result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers()));
443                         result.typeParameters().addAll(
444                                         ASTNode.copySubtrees(target, typeParameters()));
445                         result.setSuperclassType(
446                                         (Type) ASTNode.copySubtree(target, getSuperclassType()));
447                         result.superInterfaceTypes().addAll(
448                                         ASTNode.copySubtrees(target, superInterfaceTypes()));
449                 }
450                 result.bodyDeclarations().addAll(
451                         ASTNode.copySubtrees(target, bodyDeclarations()));
452                 return result;
453         }
454
455         /* (omit javadoc for this method)
456          * Method declared on ASTNode.
457          */
458         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
459                 // dispatch to correct overloaded match method
460                 return matcher.match(this, other);
461         }
462         
463         /* (omit javadoc for this method)
464          * Method declared on ASTNode.
465          */
466         void accept0(ASTVisitor visitor) {
467                 boolean visitChildren = visitor.visit(this);
468                 if (visitChildren) {
469                         // visit children in normal left to right reading order
470                         if (this.ast.apiLevel == AST.JLS2_INTERNAL) {
471                                 acceptChild(visitor, getJavadoc());
472                                 acceptChild(visitor, getName());
473                                 acceptChild(visitor, getSuperclass());
474                                 acceptChildren(visitor, this.superInterfaceNames);
475                                 acceptChildren(visitor, this.bodyDeclarations);
476                         }
477                         if (this.ast.apiLevel >= AST.JLS3) {
478                                 acceptChild(visitor, getJavadoc());
479                                 acceptChildren(visitor, this.modifiers);
480                                 acceptChild(visitor, getName());
481                                 acceptChildren(visitor, this.typeParameters);
482                                 acceptChild(visitor, getSuperclassType());
483                                 acceptChildren(visitor, this.superInterfaceTypes);
484                                 acceptChildren(visitor, this.bodyDeclarations);
485                         }
486                 }
487                 visitor.endVisit(this);
488         }
489         
490         /**
491          * Returns whether this type declaration declares a class or an 
492          * interface.
493          * 
494          * @return <code>true</code> if this is an interface declaration,
495          *    and <code>false</code> if this is a class declaration
496          */ 
497         public boolean isInterface() {
498                 return this.isInterface;
499         }
500         
501         /**
502          * Sets whether this type declaration declares a class or an 
503          * interface.
504          * 
505          * @param isInterface <code>true</code> if this is an interface
506          *    declaration, and <code>false</code> if this is a class
507          *        declaration
508          */ 
509         public void setInterface(boolean isInterface) {
510                 preValueChange(INTERFACE_PROPERTY);
511                 this.isInterface = isInterface;
512                 postValueChange(INTERFACE_PROPERTY);
513         }
514
515         /**
516          * Returns the live ordered list of type parameters of this type 
517          * declaration (added in JLS3 API). This list is non-empty for parameterized types.
518          * 
519          * @return the live list of type parameters
520          *    (element type: <code>TypeParameter</code>)
521          * @exception UnsupportedOperationException if this operation is used in
522          * a JLS2 AST
523          * @since 3.1
524          */ 
525         public List typeParameters() {
526                 // more efficient than just calling unsupportedIn2() to check
527                 if (this.typeParameters == null) {
528                         unsupportedIn2();
529                 }
530                 return this.typeParameters;
531         }
532         
533         /**
534          * Returns the name of the superclass declared in this type
535          * declaration, or <code>null</code> if there is none (JLS2 API only).
536          * <p>
537          * Note that this child is not relevant for interface 
538          * declarations (although it does still figure in subtree
539          * equality comparisons).
540          * </p>
541          * 
542          * @return the superclass name node, or <code>null</code> if 
543          *    there is none
544          * @exception UnsupportedOperationException if this operation is used in
545          * an AST later than JLS2
546          * @deprecated In the JLS3 API, this method is replaced by
547          * {@link #getSuperclassType()}, which returns a <code>Type</code>
548          * instead of a <code>Name</code>.
549          */ 
550         public Name getSuperclass() {
551                 return internalGetSuperclass();
552         }
553         
554         /**
555          * Internal synonym for deprecated method. Used to avoid
556          * deprecation warnings.
557          * @since 3.1
558          */
559         /*package*/ final Name internalGetSuperclass() {
560                 supportedOnlyIn2();
561                 return this.optionalSuperclassName;
562         }
563
564         /**
565         * Returns the superclass declared in this type
566         * declaration, or <code>null</code> if there is none (added in JLS3 API).
567         * <p>
568         * Note that this child is not relevant for interface 
569         * declarations (although it does still figure in subtree
570         * equality comparisons).
571         * </p>
572         * 
573         * @return the superclass type node, or <code>null</code> if 
574         *    there is none
575         * @exception UnsupportedOperationException if this operation is used in
576         * a JLS2 AST
577         * @since 3.1
578         */ 
579         public Type getSuperclassType() {
580             unsupportedIn2();
581                 return this.optionalSuperclassType;
582         }
583
584         /**
585          * Sets or clears the name of the superclass declared in this type
586          * declaration (JLS2 API only).
587          * <p>
588          * Note that this child is not relevant for interface 
589          * declarations (although it does still figure in subtree
590          * equality comparisons).
591          * </p>
592          * 
593          * @param superclassName the superclass name node, or <code>null</code> if 
594          *    there is none
595          * @exception IllegalArgumentException if:
596          * <ul>
597          * <li>the node belongs to a different AST</li>
598          * <li>the node already has a parent</li>
599          * </ul>
600          * @exception UnsupportedOperationException if this operation is used in
601          * an AST later than JLS2
602          * @deprecated In the JLS3 API, this method is replaced by 
603          * {@link #setSuperclassType(Type)}, which expects a
604          * <code>Type</code> instead of a <code>Name</code>.
605          */ 
606         public void setSuperclass(Name superclassName) {
607                 internalSetSuperclass(superclassName);
608         }
609         
610         /**
611          * Internal synonym for deprecated method. Used to avoid
612          * deprecation warnings.
613          * @since 3.1
614          */
615         /*package*/ final void internalSetSuperclass(Name superclassName) {
616             supportedOnlyIn2();
617                 ASTNode oldChild = this.optionalSuperclassName;
618                 preReplaceChild(oldChild, superclassName, SUPERCLASS_PROPERTY);
619                 this.optionalSuperclassName = superclassName;
620                 postReplaceChild(oldChild, superclassName, SUPERCLASS_PROPERTY);
621         }
622
623         /**
624          * Sets or clears the superclass declared in this type
625          * declaration (added in JLS3 API).
626          * <p>
627          * Note that this child is not relevant for interface declarations
628          * (although it does still figure in subtree equality comparisons).
629          * </p>
630          * 
631          * @param superclassType the superclass type node, or <code>null</code> if 
632          *    there is none
633          * @exception IllegalArgumentException if:
634          * <ul>
635          * <li>the node belongs to a different AST</li>
636          * <li>the node already has a parent</li>
637          * </ul>
638          * @exception UnsupportedOperationException if this operation is used in
639          * a JLS2 AST
640          * @since 3.1
641          */ 
642         public void setSuperclassType(Type superclassType) {
643             unsupportedIn2();
644                 ASTNode oldChild = this.optionalSuperclassType;
645                 preReplaceChild(oldChild, superclassType, SUPERCLASS_TYPE_PROPERTY);
646                 this.optionalSuperclassType = superclassType;
647                 postReplaceChild(oldChild, superclassType, SUPERCLASS_TYPE_PROPERTY);
648         }
649
650         /**
651          * Returns the live ordered list of names of superinterfaces of this type 
652          * declaration (JLS2 API only). For a class declaration, these are the names
653          * of the interfaces that this class implements; for an interface
654          * declaration, these are the names of the interfaces that this interface
655          * extends.
656          * 
657          * @return the live list of interface names
658          *    (element type: <code>Name</code>)
659          * @exception UnsupportedOperationException if this operation is used in
660          * an AST later than JLS2
661          * @deprecated In the JLS3 API, this method is replaced by 
662          * {@link #superInterfaceTypes()}.
663          */ 
664         public List superInterfaces() {
665                 return internalSuperInterfaces();
666         }
667         
668         /**
669          * Internal synonym for deprecated method. Used to avoid
670          * deprecation warnings.
671          * @since 3.1
672          */
673         /*package*/ final List internalSuperInterfaces() {
674                 // more efficient than just calling supportedOnlyIn2() to check
675                 if (this.superInterfaceNames == null) {
676                         supportedOnlyIn2();
677                 }
678                 return this.superInterfaceNames;
679         }
680         
681         /**
682          * Returns the live ordered list of superinterfaces of this type 
683          * declaration (added in JLS3 API). For a class declaration, these are the interfaces
684          * that this class implements; for an interface declaration,
685          * these are the interfaces that this interface extends.
686          * 
687          * @return the live list of interface types
688          *    (element type: <code>Type</code>)
689          * @exception UnsupportedOperationException if this operation is used in
690          * a JLS2 AST
691          * @since 3.1
692          */ 
693         public List superInterfaceTypes() {
694                 // more efficient than just calling unsupportedIn2() to check
695                 if (this.superInterfaceTypes == null) {
696                         unsupportedIn2();
697                 }
698                 return this.superInterfaceTypes;
699         }
700         
701         /**
702          * Returns the ordered list of field declarations of this type 
703          * declaration. For a class declaration, these are the
704          * field declarations; for an interface declaration, these are
705          * the constant declarations.
706          * <p>
707          * This convenience method returns this node's body declarations
708          * with non-fields filtered out. Unlike <code>bodyDeclarations</code>,
709          * this method does not return a live result.
710          * </p>
711          * 
712          * @return the (possibly empty) list of field declarations
713          */ 
714         public FieldDeclaration[] getFields() {
715                 List bd = bodyDeclarations();
716                 int fieldCount = 0;
717                 for (Iterator it = bd.listIterator(); it.hasNext(); ) {
718                         if (it.next() instanceof FieldDeclaration) {
719                                 fieldCount++;
720                         }
721                 }
722                 FieldDeclaration[] fields = new FieldDeclaration[fieldCount];
723                 int next = 0;
724                 for (Iterator it = bd.listIterator(); it.hasNext(); ) {
725                         Object decl = it.next();
726                         if (decl instanceof FieldDeclaration) {
727                                 fields[next++] = (FieldDeclaration) decl;
728                         }
729                 }
730                 return fields;
731         }
732
733         /**
734          * Returns the ordered list of method declarations of this type 
735          * declaration.
736          * <p>
737          * This convenience method returns this node's body declarations
738          * with non-methods filtered out. Unlike <code>bodyDeclarations</code>,
739          * this method does not return a live result.
740          * </p>
741          * 
742          * @return the (possibly empty) list of method (and constructor) 
743          *    declarations
744          */ 
745         public MethodDeclaration[] getMethods() {
746                 List bd = bodyDeclarations();
747                 int methodCount = 0;
748                 for (Iterator it = bd.listIterator(); it.hasNext(); ) {
749                         if (it.next() instanceof MethodDeclaration) {
750                                 methodCount++;
751                         }
752                 }
753                 MethodDeclaration[] methods = new MethodDeclaration[methodCount];
754                 int next = 0;
755                 for (Iterator it = bd.listIterator(); it.hasNext(); ) {
756                         Object decl = it.next();
757                         if (decl instanceof MethodDeclaration) {
758                                 methods[next++] = (MethodDeclaration) decl;
759                         }
760                 }
761                 return methods;
762         }
763
764         /**
765          * Returns the ordered list of member type declarations of this type 
766          * declaration.
767          * <p>
768          * This convenience method returns this node's body declarations
769          * with non-types filtered out. Unlike <code>bodyDeclarations</code>,
770          * this method does not return a live result.
771          * </p>
772          * 
773          * @return the (possibly empty) list of member type declarations
774          */ 
775         public TypeDeclaration[] getTypes() {
776                 List bd = bodyDeclarations();
777                 int typeCount = 0;
778                 for (Iterator it = bd.listIterator(); it.hasNext(); ) {
779                         if (it.next() instanceof TypeDeclaration) {
780                                 typeCount++;
781                         }
782                 }
783                 TypeDeclaration[] memberTypes = new TypeDeclaration[typeCount];
784                 int next = 0;
785                 for (Iterator it = bd.listIterator(); it.hasNext(); ) {
786                         Object decl = it.next();
787                         if (decl instanceof TypeDeclaration) {
788                                 memberTypes[next++] = (TypeDeclaration) decl;
789                         }
790                 }
791                 return memberTypes;
792         }
793
794         /* (omit javadoc for this method)
795          * Method declared on AsbtractTypeDeclaration.
796          */
797         ITypeBinding internalResolveBinding() {
798                 return this.ast.getBindingResolver().resolveType(this);
799         }
800         
801         /* (omit javadoc for this method)
802          * Method declared on ASTNode.
803          */
804         int memSize() {
805                 return super.memSize() + 6 * 4;
806         }
807         
808         /* (omit javadoc for this method)
809          * Method declared on ASTNode.
810          */
811         int treeSize() {
812                 return memSize()
813                         + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize())
814                         + (this.modifiers == null ? 0 : this.modifiers.listSize())
815                         + (this.typeName == null ? 0 : getName().treeSize())
816                         + (this.typeParameters == null ? 0 : this.typeParameters.listSize())
817                         + (this.optionalSuperclassName == null ? 0 : getSuperclass().treeSize())
818                         + (this.optionalSuperclassType == null ? 0 : getSuperclassType().treeSize())
819                         + (this.superInterfaceNames == null ? 0 : this.superInterfaceNames.listSize())
820                         + (this.superInterfaceTypes == null ? 0 : this.superInterfaceTypes.listSize())
821                         + this.bodyDeclarations.listSize();
822         }
823 }
824