removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / TypeParameter.java
1 /*******************************************************************************
2  * Copyright (c) 2003, 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.List;
16
17 /**
18  * Type parameter node (added in JLS3 API).
19  * <pre>
20  * TypeParameter:
21  *    TypeVariable [ <b>extends</b> Type { <b>&</b> Type } ]
22  * </pre>
23  * 
24  * @since 3.1
25  * @noinstantiate This class is not intended to be instantiated by clients.
26  */
27 public class TypeParameter extends ASTNode {
28         
29         /**
30          * The "name" structural property of this node type.
31          */
32         public static final ChildPropertyDescriptor NAME_PROPERTY = 
33                 new ChildPropertyDescriptor(TypeParameter.class, "name", SimpleName.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
34
35         /**
36          * The "typeBounds" structural property of this node type.
37          */
38         public static final ChildListPropertyDescriptor TYPE_BOUNDS_PROPERTY = 
39                 new ChildListPropertyDescriptor(TypeParameter.class, "typeBounds", Type.class, NO_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 propertyList = new ArrayList(3);
50                 createPropertyList(TypeParameter.class, propertyList);
51                 addProperty(NAME_PROPERTY, propertyList);
52                 addProperty(TYPE_BOUNDS_PROPERTY, propertyList);
53                 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
54         }
55
56         /**
57          * Returns a list of structural property descriptors for this node type.
58          * Clients must not modify the result.
59          * 
60          * @param apiLevel the API level; one of the
61          * <code>AST.JLS*</code> constants
62
63          * @return a list of property descriptors (element type: 
64          * {@link StructuralPropertyDescriptor})
65          */
66         public static List propertyDescriptors(int apiLevel) {
67                 return PROPERTY_DESCRIPTORS;
68         }
69                         
70         /** 
71          * The type variable node; lazily initialized; defaults to an unspecfied, 
72          * but legal, name.
73          */
74         private SimpleName typeVariableName = null;
75         
76         /**
77          * The type bounds (element type: <code>Type</code>). 
78          * Defaults to an empty list.
79          */
80         private ASTNode.NodeList typeBounds =
81                 new ASTNode.NodeList(TYPE_BOUNDS_PROPERTY);
82         
83         /**
84          * Creates a new unparented node for a parameterized type owned by the
85          * given AST. By default, an unspecified, but legal, type variable name, 
86          * and no type bounds.
87          * <p>
88          * N.B. This constructor is package-private.
89          * </p>
90          * 
91          * @param ast the AST that is to own this node
92          */
93         TypeParameter(AST ast) {
94                 super(ast);
95             unsupportedIn2();
96         }
97
98         /* (omit javadoc for this method)
99          * Method declared on ASTNode.
100          */
101         final List internalStructuralPropertiesForType(int apiLevel) {
102                 return propertyDescriptors(apiLevel);
103         }
104         
105         /* (omit javadoc for this method)
106          * Method declared on ASTNode.
107          */
108         final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
109                 if (property == NAME_PROPERTY) {
110                         if (get) {
111                                 return getName();
112                         } else {
113                                 setName((SimpleName) child);
114                                 return null;
115                         }
116                 }
117                 // allow default implementation to flag the error
118                 return super.internalGetSetChildProperty(property, get, child);
119         }
120         
121         /* (omit javadoc for this method)
122          * Method declared on ASTNode.
123          */
124         final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
125                 if (property == TYPE_BOUNDS_PROPERTY) {
126                         return typeBounds();
127                 }
128                 // allow default implementation to flag the error
129                 return super.internalGetChildListProperty(property);
130         }
131         
132         /* (omit javadoc for this method)
133          * Method declared on ASTNode.
134          */
135         final int getNodeType0() {
136                 return TYPE_PARAMETER;
137         }
138
139         /* (omit javadoc for this method)
140          * Method declared on ASTNode.
141          */
142         ASTNode clone0(AST target) {
143                 TypeParameter result = new TypeParameter(target);
144                 result.setSourceRange(this.getStartPosition(), this.getLength());
145                 result.setName((SimpleName) ((ASTNode) getName()).clone(target));
146                 result.typeBounds().addAll(
147                         ASTNode.copySubtrees(target, typeBounds()));
148                 return result;
149         }
150
151         /* (omit javadoc for this method)
152          * Method declared on ASTNode.
153          */
154         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
155                 // dispatch to correct overloaded match method
156                 return matcher.match(this, other);
157         }
158
159         /* (omit javadoc for this method)
160          * Method declared on ASTNode.
161          */
162         void accept0(ASTVisitor visitor) {
163                 boolean visitChildren = visitor.visit(this);
164                 if (visitChildren) {
165                         // visit children in normal left to right reading order
166                         acceptChild(visitor, getName());
167                         acceptChildren(visitor, this.typeBounds);
168                 }
169                 visitor.endVisit(this);
170         }
171         
172         /**
173          * Returns the name of the type variable declared in this type parameter.
174          * 
175          * @return the name of the type variable
176          */ 
177         public SimpleName getName() {
178                 if (this.typeVariableName == null) {
179                         // lazy init must be thread-safe for readers
180                         synchronized (this) {
181                                 if (this.typeVariableName == null) {
182                                         preLazyInit();
183                                         this.typeVariableName = new SimpleName(this.ast);
184                                         postLazyInit(this.typeVariableName, NAME_PROPERTY);
185                                 }
186                         }
187                 }
188                 return this.typeVariableName;
189         }
190         
191         /**
192          * Resolves and returns the binding for this type parameter.
193          * <p>
194          * Note that bindings are generally unavailable unless requested when the
195          * AST is being built.
196          * </p>
197          * 
198          * @return the binding, or <code>null</code> if the binding cannot be 
199          *    resolved
200          */     
201         public final ITypeBinding resolveBinding() {
202                 return this.ast.getBindingResolver().resolveTypeParameter(this);
203         }
204         
205         /**
206          * Sets the name of the type variable of this type parameter to the given
207          * name.
208          * 
209          * @param typeName the new name of this type parameter 
210          * @exception IllegalArgumentException if:
211          * <ul>
212          * <li>the node belongs to a different AST</li>
213          * <li>the node already has a parent</li>
214          * </ul>
215          */ 
216         public void setName(SimpleName typeName) {
217                 if (typeName == null) {
218                         throw new IllegalArgumentException();
219                 }
220                 ASTNode oldChild = this.typeVariableName;
221                 preReplaceChild(oldChild, typeName, NAME_PROPERTY);
222                 this.typeVariableName = typeName;
223                 postReplaceChild(oldChild, typeName, NAME_PROPERTY);
224         }
225
226         /**
227          * Returns the live ordered list of type bounds of this type parameter.
228          * For the type parameter to be plausible, there can be at most one
229          * class in the list, and it must be first, and the remaining ones must be
230          * interfaces; the list should not contain primitive types (but array types
231          * and parameterized types are allowed).
232          * 
233          * @return the live list of type bounds
234          *    (element type: <code>Type</code>)
235          */ 
236         public List typeBounds() {
237                 return this.typeBounds;
238         }
239         
240         /* (omit javadoc for this method)
241          * Method declared on ASTNode.
242          */
243         int memSize() {
244                 // treat Code as free
245                 return BASE_NODE_SIZE + 2 * 4;
246         }
247         
248         /* (omit javadoc for this method)
249          * Method declared on ASTNode.
250          */
251         int treeSize() {
252                 return 
253                         memSize()
254                         + (this.typeVariableName == null ? 0 : getName().treeSize())
255                         + this.typeBounds.listSize();
256         }
257 }
258