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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.core.dom;
13 import java.util.ArrayList;
14 import java.util.List;
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.
23 * AnonymousClassDeclaration:
24 * <b>{</b> ClassBodyDeclaration <b>}</b>
27 * @see ClassInstanceCreation
28 * @see EnumConstantDeclaration
30 * @noinstantiate This class is not intended to be instantiated by clients.
32 public class AnonymousClassDeclaration extends ASTNode {
35 * The "bodyDeclarations" structural property of this node type.
38 public static final ChildListPropertyDescriptor BODY_DECLARATIONS_PROPERTY =
39 new ChildListPropertyDescriptor(AnonymousClassDeclaration.class, "bodyDeclarations", BodyDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
42 * A list of property descriptors (element type:
43 * {@link StructuralPropertyDescriptor}),
44 * or null if uninitialized.
46 private static final List PROPERTY_DESCRIPTORS;
49 List properyList = new ArrayList(2);
50 createPropertyList(AnonymousClassDeclaration.class, properyList);
51 addProperty(BODY_DECLARATIONS_PROPERTY, properyList);
52 PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
56 * Returns a list of structural property descriptors for this node type.
57 * Clients must not modify the result.
59 * @param apiLevel the API level; one of the
60 * <code>AST.JLS*</code> constants
62 * @return a list of property descriptors (element type:
63 * {@link StructuralPropertyDescriptor})
66 public static List propertyDescriptors(int apiLevel) {
67 return PROPERTY_DESCRIPTORS;
71 * The body declarations (element type: <code>BodyDeclaration</code>).
74 private ASTNode.NodeList bodyDeclarations =
75 new ASTNode.NodeList(BODY_DECLARATIONS_PROPERTY);
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.
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.
86 * @param ast the AST that is to own this node
88 AnonymousClassDeclaration(AST ast) {
92 /* (omit javadoc for this method)
93 * Method declared on ASTNode.
95 final List internalStructuralPropertiesForType(int apiLevel) {
96 return propertyDescriptors(apiLevel);
99 /* (omit javadoc for this method)
100 * Method declared on ASTNode.
102 final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
103 if (property == BODY_DECLARATIONS_PROPERTY) {
104 return bodyDeclarations();
106 // allow default implementation to flag the error
107 return super.internalGetChildListProperty(property);
110 /* (omit javadoc for this method)
111 * Method declared on ASTNode.
113 final int getNodeType0() {
114 return ANONYMOUS_CLASS_DECLARATION;
117 /* (omit javadoc for this method)
118 * Method declared on ASTNode.
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()));
128 /* (omit javadoc for this method)
129 * Method declared on ASTNode.
131 final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
132 // dispatch to correct overloaded match method
133 return matcher.match(this, other);
136 /* (omit javadoc for this method)
137 * Method declared on ASTNode.
139 void accept0(ASTVisitor visitor) {
140 boolean visitChildren = visitor.visit(this);
142 // visit children in normal left to right reading order
143 acceptChildren(visitor, bodyDeclarations);
145 visitor.endVisit(this);
149 * Returns the live ordered list of body declarations of this
150 * anonymous class declaration.
152 * @return the live list of body declarations
153 * (element type: <code>BodyDeclaration</code>)
155 public List bodyDeclarations() {
156 return this.bodyDeclarations;
160 * Resolves and returns the binding for the anonymous class declared in
163 * Note that bindings are generally unavailable unless requested when the
164 * AST is being built.
167 * @return the binding, or <code>null</code> if the binding cannot be
170 public ITypeBinding resolveBinding() {
171 return this.ast.getBindingResolver().resolveType(this);
174 /* (omit javadoc for this method)
175 * Method declared on ASTNode.
178 // treat Code as free
179 return BASE_NODE_SIZE + 4;
182 /* (omit javadoc for this method)
183 * Method declared on ASTNode.
188 + this.bodyDeclarations.listSize();