removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / AnonymousClassDeclaration.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 package net.sourceforge.phpdt.core.dom;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 /**
17  * Anonymous class declaration AST node type. For JLS2, this type of node appears
18  * only as a child on a class instance creation expression.
19  * For JLS3, this type of node appears may also appear as the child of
20  * an enum constant declaration.
21  *
22  * <pre>
23  * AnonymousClassDeclaration:
24  *        <b>{</b> ClassBodyDeclaration <b>}</b>
25  * </pre>
26  * 
27  * @see ClassInstanceCreation
28  * @see EnumConstantDeclaration
29  * @since 2.0
30  * @noinstantiate This class is not intended to be instantiated by clients.
31  */
32 public class AnonymousClassDeclaration extends ASTNode {
33
34         /**
35          * The "bodyDeclarations" structural property of this node type.
36          * @since 3.0
37          */
38         public static final ChildListPropertyDescriptor BODY_DECLARATIONS_PROPERTY = 
39                 new ChildListPropertyDescriptor(AnonymousClassDeclaration.class, "bodyDeclarations", BodyDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
40         
41         /**
42          * A list of property descriptors (element type: 
43          * {@link StructuralPropertyDescriptor}),
44          * or null if uninitialized.
45          */
46         private static final List PROPERTY_DESCRIPTORS;
47         
48         static {
49                 List properyList = new ArrayList(2);
50                 createPropertyList(AnonymousClassDeclaration.class, properyList);
51                 addProperty(BODY_DECLARATIONS_PROPERTY, properyList);
52                 PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
53         }
54
55         /**
56          * Returns a list of structural property descriptors for this node type.
57          * Clients must not modify the result.
58          * 
59          * @param apiLevel the API level; one of the
60          * <code>AST.JLS*</code> constants
61
62          * @return a list of property descriptors (element type: 
63          * {@link StructuralPropertyDescriptor})
64          * @since 3.0
65          */
66         public static List propertyDescriptors(int apiLevel) {
67                 return PROPERTY_DESCRIPTORS;
68         }
69                         
70         /**
71          * The body declarations (element type: <code>BodyDeclaration</code>).
72          * Defaults to none.
73          */
74         private ASTNode.NodeList bodyDeclarations = 
75                 new ASTNode.NodeList(BODY_DECLARATIONS_PROPERTY);
76
77         /**
78          * Creates a new AST node for an anonymous class declaration owned 
79          * by the given AST. By default, the list of body declarations is empty.
80          * <p>
81          * N.B. This constructor is package-private; all subclasses must be 
82          * declared in the same package; clients are unable to declare 
83          * additional subclasses.
84          * </p>
85          * 
86          * @param ast the AST that is to own this node
87          */
88         AnonymousClassDeclaration(AST ast) {
89                 super(ast);
90         }
91
92         /* (omit javadoc for this method)
93          * Method declared on ASTNode.
94          */
95         final List internalStructuralPropertiesForType(int apiLevel) {
96                 return propertyDescriptors(apiLevel);
97         }
98         
99         /* (omit javadoc for this method)
100          * Method declared on ASTNode.
101          */
102         final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
103                 if (property == BODY_DECLARATIONS_PROPERTY) {
104                         return bodyDeclarations();
105                 }
106                 // allow default implementation to flag the error
107                 return super.internalGetChildListProperty(property);
108         }
109         
110         /* (omit javadoc for this method)
111          * Method declared on ASTNode.
112          */
113         final int getNodeType0() {
114                 return ANONYMOUS_CLASS_DECLARATION;
115         }
116
117         /* (omit javadoc for this method)
118          * Method declared on ASTNode.
119          */
120         ASTNode clone0(AST target) {
121                 AnonymousClassDeclaration result = new AnonymousClassDeclaration(target);
122                 result.setSourceRange(this.getStartPosition(), this.getLength());
123                 result.bodyDeclarations().addAll(
124                         ASTNode.copySubtrees(target, bodyDeclarations()));
125                 return result;
126         }
127
128         /* (omit javadoc for this method)
129          * Method declared on ASTNode.
130          */
131         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
132                 // dispatch to correct overloaded match method
133                 return matcher.match(this, other);
134         }
135
136         /* (omit javadoc for this method)
137          * Method declared on ASTNode.
138          */
139         void accept0(ASTVisitor visitor) {
140                 boolean visitChildren = visitor.visit(this);
141                 if (visitChildren) {
142                         // visit children in normal left to right reading order
143                         acceptChildren(visitor, bodyDeclarations);
144                 }
145                 visitor.endVisit(this);
146         }
147         
148         /**
149          * Returns the live ordered list of body declarations of this
150          * anonymous class declaration.
151          * 
152          * @return the live list of body declarations
153          *    (element type: <code>BodyDeclaration</code>)
154          */ 
155         public List bodyDeclarations() {
156                 return this.bodyDeclarations;
157         }
158
159         /**
160          * Resolves and returns the binding for the anonymous class declared in
161          * this declaration.
162          * <p>
163          * Note that bindings are generally unavailable unless requested when the
164          * AST is being built.
165          * </p>
166          * 
167          * @return the binding, or <code>null</code> if the binding cannot be 
168          *    resolved
169          */     
170         public ITypeBinding resolveBinding() {
171                 return this.ast.getBindingResolver().resolveType(this);
172         }
173         
174         /* (omit javadoc for this method)
175          * Method declared on ASTNode.
176          */
177         int memSize() {
178                 // treat Code as free
179                 return BASE_NODE_SIZE + 4;
180         }
181         
182         /* (omit javadoc for this method)
183          * Method declared on ASTNode.
184          */
185         int treeSize() {
186                 return 
187                         memSize()
188                         + this.bodyDeclarations.listSize();
189         }
190 }