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