KickJava   Java API By Example, From Geeks To Geeks.

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


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

26 public class SimpleType extends Type {
27     
28     /**
29      * The "name" structural property of this node type.
30      * @since 3.0
31      */

32     public static final ChildPropertyDescriptor NAME_PROPERTY =
33         new ChildPropertyDescriptor(SimpleType.class, "name", Name.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
34

35     /**
36      * A list of property descriptors (element type:
37      * {@link StructuralPropertyDescriptor}),
38      * or null if uninitialized.
39      */

40     private static final List JavaDoc PROPERTY_DESCRIPTORS;
41     
42     static {
43         List JavaDoc propertyList = new ArrayList JavaDoc(2);
44         createPropertyList(SimpleType.class, propertyList);
45         addProperty(NAME_PROPERTY, propertyList);
46         PROPERTY_DESCRIPTORS = reapPropertyList(propertyList);
47     }
48
49     /**
50      * Returns a list of structural property descriptors for this node type.
51      * Clients must not modify the result.
52      *
53      * @param apiLevel the API level; one of the
54      * <code>AST.JLS*</code> constants
55      * @return a list of property descriptors (element type:
56      * {@link StructuralPropertyDescriptor})
57      * @since 3.0
58      */

59     public static List JavaDoc propertyDescriptors(int apiLevel) {
60         return PROPERTY_DESCRIPTORS;
61     }
62             
63     /**
64      * The type name node; lazily initialized; defaults to a type with
65      * an unspecfied, but legal, name.
66      */

67     private Name typeName = null;
68     
69     /**
70      * Creates a new unparented node for a simple type owned by the given AST.
71      * By default, an unspecified, but legal, name.
72      * <p>
73      * N.B. This constructor is package-private.
74      * </p>
75      *
76      * @param ast the AST that is to own this node
77      */

78     SimpleType(AST ast) {
79         super(ast);
80     }
81
82     /* (omit javadoc for this method)
83      * Method declared on ASTNode.
84      */

85     final List JavaDoc internalStructuralPropertiesForType(int apiLevel) {
86         return propertyDescriptors(apiLevel);
87     }
88     
89     /* (omit javadoc for this method)
90      * Method declared on ASTNode.
91      */

92     final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
93         if (property == NAME_PROPERTY) {
94             if (get) {
95                 return getName();
96             } else {
97                 setName((Name) child);
98                 return null;
99             }
100         }
101         // allow default implementation to flag the error
102
return super.internalGetSetChildProperty(property, get, child);
103     }
104     
105     /* (omit javadoc for this method)
106      * Method declared on ASTNode.
107      */

108     final int getNodeType0() {
109         return SIMPLE_TYPE;
110     }
111
112     /* (omit javadoc for this method)
113      * Method declared on ASTNode.
114      */

115     ASTNode clone0(AST target) {
116         SimpleType result = new SimpleType(target);
117         result.setSourceRange(this.getStartPosition(), this.getLength());
118         result.setName((Name) (getName()).clone(target));
119         return result;
120     }
121
122     /* (omit javadoc for this method)
123      * Method declared on ASTNode.
124      */

125     final boolean subtreeMatch0(ASTMatcher matcher, Object JavaDoc other) {
126         // dispatch to correct overloaded match method
127
return matcher.match(this, other);
128     }
129
130     /* (omit javadoc for this method)
131      * Method declared on ASTNode.
132      */

133     void accept0(ASTVisitor visitor) {
134         boolean visitChildren = visitor.visit(this);
135         if (visitChildren) {
136             acceptChild(visitor, getName());
137         }
138         visitor.endVisit(this);
139     }
140     
141     /**
142      * Returns the name of this simple type.
143      *
144      * @return the name of this simple type
145      */

146     public Name getName() {
147         if (this.typeName == null) {
148             // lazy init must be thread-safe for readers
149
synchronized (this) {
150                 if (this.typeName == null) {
151                     preLazyInit();
152                     this.typeName = new SimpleName(this.ast);
153                     postLazyInit(this.typeName, NAME_PROPERTY);
154                 }
155             }
156         }
157         return this.typeName;
158     }
159     
160     /**
161      * Sets the name of this simple type to the given name.
162      *
163      * @param typeName the new name of this simple type
164      * @exception IllegalArgumentException if:
165      * <ul>
166      * <li>the node belongs to a different AST</li>
167      * <li>the node already has a parent</li>
168      * </ul>
169      */

170     public void setName(Name typeName) {
171         if (typeName == null) {
172             throw new IllegalArgumentException JavaDoc();
173         }
174         ASTNode oldChild = this.typeName;
175         preReplaceChild(oldChild, typeName, NAME_PROPERTY);
176         this.typeName = typeName;
177         postReplaceChild(oldChild, typeName, NAME_PROPERTY);
178     }
179
180     /* (omit javadoc for this method)
181      * Method declared on ASTNode.
182      */

183     int memSize() {
184         // treat Code as free
185
return BASE_NODE_SIZE + 1 * 4;
186     }
187     
188     /* (omit javadoc for this method)
189      * Method declared on ASTNode.
190      */

191     int treeSize() {
192         return
193             memSize()
194             + (this.typeName == null ? 0 : getName().treeSize());
195     }
196 }
197
198
Popular Tags