removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / SimpleType.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.List;
16
17 /**
18  * Type node for a named class type, a named interface type, or a type variable.
19  * <p>
20  * This kind of node is used to convert a name (<code>Name</code>) into a type
21  * (<code>Type</code>) by wrapping it.
22  * </p>
23  * 
24  * @since 2.0
25  * @noinstantiate This class is not intended to be instantiated by clients.
26  */
27 public class SimpleType extends Type {
28         
29         /**
30          * The "name" structural property of this node type.
31          * @since 3.0
32          */
33         public static final ChildPropertyDescriptor NAME_PROPERTY = 
34                 new ChildPropertyDescriptor(SimpleType.class, "name", Name.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
35
36         /**
37          * A list of property descriptors (element type: 
38          * {@link StructuralPropertyDescriptor}),
39          * or null if uninitialized.
40          */
41         private static final List PROPERTY_DESCRIPTORS;
42         
43         static {
44                 List propertyList = new ArrayList(2);
45                 createPropertyList(SimpleType.class, propertyList);
46                 addProperty(NAME_PROPERTY, propertyList);
47                 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
48         }
49
50         /**
51          * Returns a list of structural property descriptors for this node type.
52          * Clients must not modify the result.
53          * 
54          * @param apiLevel the API level; one of the
55          * <code>AST.JLS*</code> constants
56          * @return a list of property descriptors (element type: 
57          * {@link StructuralPropertyDescriptor})
58          * @since 3.0
59          */
60         public static List propertyDescriptors(int apiLevel) {
61                 return PROPERTY_DESCRIPTORS;
62         }
63                         
64         /** 
65          * The type name node; lazily initialized; defaults to a type with
66          * an unspecfied, but legal, name.
67          */
68         private Name typeName = null;
69         
70         /**
71          * Creates a new unparented node for a simple type owned by the given AST.
72          * By default, an unspecified, but legal, name.
73          * <p>
74          * N.B. This constructor is package-private.
75          * </p>
76          * 
77          * @param ast the AST that is to own this node
78          */
79         SimpleType(AST ast) {
80                 super(ast);
81         }
82
83         /* (omit javadoc for this method)
84          * Method declared on ASTNode.
85          */
86         final List internalStructuralPropertiesForType(int apiLevel) {
87                 return propertyDescriptors(apiLevel);
88         }
89         
90         /* (omit javadoc for this method)
91          * Method declared on ASTNode.
92          */
93         final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
94                 if (property == NAME_PROPERTY) {
95                         if (get) {
96                                 return getName();
97                         } else {
98                                 setName((Name) child);
99                                 return null;
100                         }
101                 }
102                 // allow default implementation to flag the error
103                 return super.internalGetSetChildProperty(property, get, child);
104         }
105         
106         /* (omit javadoc for this method)
107          * Method declared on ASTNode.
108          */
109         final int getNodeType0() {
110                 return SIMPLE_TYPE;
111         }
112
113         /* (omit javadoc for this method)
114          * Method declared on ASTNode.
115          */
116         ASTNode clone0(AST target) {
117                 SimpleType result = new SimpleType(target);
118                 result.setSourceRange(this.getStartPosition(), this.getLength());
119                 result.setName((Name) (getName()).clone(target));
120                 return result;
121         }
122
123         /* (omit javadoc for this method)
124          * Method declared on ASTNode.
125          */
126         final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
127                 // dispatch to correct overloaded match method
128                 return matcher.match(this, other);
129         }
130
131         /* (omit javadoc for this method)
132          * Method declared on ASTNode.
133          */
134         void accept0(ASTVisitor visitor) {
135                 boolean visitChildren = visitor.visit(this);
136                 if (visitChildren) {
137                         acceptChild(visitor, getName());
138                 }
139                 visitor.endVisit(this);
140         }
141         
142         /**
143          * Returns the name of this simple type.
144          * 
145          * @return the name of this simple type
146          */ 
147         public Name getName() {
148                 if (this.typeName == null) {
149                         // lazy init must be thread-safe for readers
150                         synchronized (this) {
151                                 if (this.typeName == null) {
152                                         preLazyInit();
153                                         this.typeName = new SimpleName(this.ast);
154                                         postLazyInit(this.typeName, NAME_PROPERTY);
155                                 }
156                         }
157                 }
158                 return this.typeName;
159         }
160         
161         /**
162          * Sets the name of this simple type to the given name.
163          * 
164          * @param typeName the new name of this simple type
165          * @exception IllegalArgumentException if:
166          * <ul>
167          * <li>the node belongs to a different AST</li>
168          * <li>the node already has a parent</li>
169          * </ul>
170          */ 
171         public void setName(Name typeName) {
172                 if (typeName == null) {
173                         throw new IllegalArgumentException();
174                 }
175                 ASTNode oldChild = this.typeName;
176                 preReplaceChild(oldChild, typeName, NAME_PROPERTY);
177                 this.typeName = typeName;
178                 postReplaceChild(oldChild, typeName, NAME_PROPERTY);
179         }
180
181         /* (omit javadoc for this method)
182          * Method declared on ASTNode.
183          */
184         int memSize() {
185                 // treat Code as free
186                 return BASE_NODE_SIZE + 1 * 4;
187         }
188         
189         /* (omit javadoc for this method)
190          * Method declared on ASTNode.
191          */
192         int treeSize() {
193                 return 
194                         memSize()
195                         + (this.typeName == null ? 0 : getName().treeSize());
196         }
197 }
198