KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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 org.eclipse.jdt.core.dom;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
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  */

31 public class AnonymousClassDeclaration extends ASTNode {
32
33     /**
34      * The "bodyDeclarations" structural property of this node type.
35      * @since 3.0
36      */

37     public static final ChildListPropertyDescriptor BODY_DECLARATIONS_PROPERTY =
38         new ChildListPropertyDescriptor(AnonymousClassDeclaration.class, "bodyDeclarations", BodyDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
39

40     /**
41      * A list of property descriptors (element type:
42      * {@link StructuralPropertyDescriptor}),
43      * or null if uninitialized.
44      */

45     private static final List JavaDoc PROPERTY_DESCRIPTORS;
46     
47     static {
48         List JavaDoc properyList = new ArrayList JavaDoc(2);
49         createPropertyList(AnonymousClassDeclaration.class, properyList);
50         addProperty(BODY_DECLARATIONS_PROPERTY, properyList);
51         PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
52     }
53
54     /**
55      * Returns a list of structural property descriptors for this node type.
56      * Clients must not modify the result.
57      *
58      * @param apiLevel the API level; one of the
59      * <code>AST.JLS&ast;</code> constants
60
61      * @return a list of property descriptors (element type:
62      * {@link StructuralPropertyDescriptor})
63      * @since 3.0
64      */

65     public static List JavaDoc propertyDescriptors(int apiLevel) {
66         return PROPERTY_DESCRIPTORS;
67     }
68             
69     /**
70      * The body declarations (element type: <code>BodyDeclaration</code>).
71      * Defaults to none.
72      */

73     private ASTNode.NodeList bodyDeclarations =
74         new ASTNode.NodeList(BODY_DECLARATIONS_PROPERTY);
75
76     /**
77      * Creates a new AST node for an anonymous class declaration owned
78      * by the given AST. By default, the list of body declarations is empty.
79      * <p>
80      * N.B. This constructor is package-private; all subclasses must be
81      * declared in the same package; clients are unable to declare
82      * additional subclasses.
83      * </p>
84      *
85      * @param ast the AST that is to own this node
86      */

87     AnonymousClassDeclaration(AST ast) {
88         super(ast);
89     }
90
91     /* (omit javadoc for this method)
92      * Method declared on ASTNode.
93      */

94     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
95         return propertyDescriptors(apiLevel);
96     }
97     
98     /* (omit javadoc for this method)
99      * Method declared on ASTNode.
100      */

101     final List JavaDoc internalGetChildListProperty(ChildListPropertyDescriptor property) {
102         if (property == BODY_DECLARATIONS_PROPERTY) {
103             return bodyDeclarations();
104         }
105         // allow default implementation to flag the error
106
return super.internalGetChildListProperty(property);
107     }
108     
109     /* (omit javadoc for this method)
110      * Method declared on ASTNode.
111      */

112     final int getNodeType0() {
113         return ANONYMOUS_CLASS_DECLARATION;
114     }
115
116     /* (omit javadoc for this method)
117      * Method declared on ASTNode.
118      */

119     ASTNode clone0(AST target) {
120         AnonymousClassDeclaration result = new AnonymousClassDeclaration(target);
121         result.setSourceRange(this.getStartPosition(), this.getLength());
122         result.bodyDeclarations().addAll(
123             ASTNode.copySubtrees(target, bodyDeclarations()));
124         return result;
125     }
126
127     /* (omit javadoc for this method)
128      * Method declared on ASTNode.
129      */

130     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
131         // dispatch to correct overloaded match method
132
return matcher.match(this, other);
133     }
134
135     /* (omit javadoc for this method)
136      * Method declared on ASTNode.
137      */

138     void accept0(ASTVisitor visitor) {
139         boolean visitChildren = visitor.visit(this);
140         if (visitChildren) {
141             // visit children in normal left to right reading order
142
acceptChildren(visitor, bodyDeclarations);
143         }
144         visitor.endVisit(this);
145     }
146     
147     /**
148      * Returns the live ordered list of body declarations of this
149      * anonymous class declaration.
150      *
151      * @return the live list of body declarations
152      * (element type: <code>BodyDeclaration</code>)
153      */

154     public List JavaDoc bodyDeclarations() {
155         return this.bodyDeclarations;
156     }
157
158     /**
159      * Resolves and returns the binding for the anonymous class declared in
160      * this declaration.
161      * <p>
162      * Note that bindings are generally unavailable unless requested when the
163      * AST is being built.
164      * </p>
165      *
166      * @return the binding, or <code>null</code> if the binding cannot be
167      * resolved
168      */

169     public ITypeBinding resolveBinding() {
170         return this.ast.getBindingResolver().resolveType(this);
171     }
172     
173     /* (omit javadoc for this method)
174      * Method declared on ASTNode.
175      */

176     int memSize() {
177         // treat Code as free
178
return BASE_NODE_SIZE + 4;
179     }
180     
181     /* (omit javadoc for this method)
182      * Method declared on ASTNode.
183      */

184     int treeSize() {
185         return
186             memSize()
187             + this.bodyDeclarations.listSize();
188     }
189 }
190
Popular Tags