KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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 /**
15  * Abstract base class of all type AST node types. A type node represents a
16  * reference to a primitive type (including void), to an array type, or to a
17  * simple named type (or type variable), to a qualified type, to a
18  * parameterized type, or to a wildcard type. Note that not all of these
19  * are meaningful in all contexts; for example, a wildcard type is only
20  * meaningful in the type argument position of a parameterized type.
21  * <p>
22  * <pre>
23  * Type:
24  * PrimitiveType
25  * ArrayType
26  * SimpleType
27  * QualifiedType
28  * ParameterizedType
29  * WildcardType
30  * PrimitiveType:
31  * <b>byte</b>
32  * <b>short</b>
33  * <b>char</b>
34  * <b>int</b>
35  * <b>long</b>
36  * <b>float</b>
37  * <b>double</b>
38  * <b>boolean</b>
39  * <b>void</b>
40  * ArrayType:
41  * Type <b>[</b> <b>]</b>
42  * SimpleType:
43  * TypeName
44  * ParameterizedType:
45  * Type <b>&lt;</b> Type { <b>,</b> Type } <b>&gt;</b>
46  * QualifiedType:
47  * Type <b>.</b> SimpleName
48  * WildcardType:
49  * <b>?</b> [ ( <b>extends</b> | <b>super</b>) Type ]
50  * </pre>
51  * </p>
52  *
53  * @since 2.0
54  */

55 public abstract class Type extends ASTNode {
56     
57     /**
58      * Creates a new AST node for a type owned by the given AST.
59      * <p>
60      * N.B. This constructor is package-private.
61      * </p>
62      *
63      * @param ast the AST that is to own this node
64      */

65     Type(AST ast) {
66         super(ast);
67     }
68     
69     /**
70      * Returns whether this type is a primitive type
71      * (<code>PrimitiveType</code>).
72      *
73      * @return <code>true</code> if this is a primitive type, and
74      * <code>false</code> otherwise
75      */

76     public final boolean isPrimitiveType() {
77         return (this instanceof PrimitiveType);
78     }
79
80     /**
81      * Returns whether this type is a simple type
82      * (<code>SimpleType</code>).
83      *
84      * @return <code>true</code> if this is a simple type, and
85      * <code>false</code> otherwise
86      */

87     public final boolean isSimpleType() {
88         return (this instanceof SimpleType);
89     }
90
91     /**
92      * Returns whether this type is an array type
93      * (<code>ArrayType</code>).
94      *
95      * @return <code>true</code> if this is an array type, and
96      * <code>false</code> otherwise
97      */

98     public final boolean isArrayType() {
99         return (this instanceof ArrayType);
100     }
101
102     /**
103      * Returns whether this type is a parameterized type
104      * (<code>ParameterizedType</code>).
105      *
106      * @return <code>true</code> if this is a parameterized type, and
107      * <code>false</code> otherwise
108      * @since 3.1
109      */

110     public final boolean isParameterizedType() {
111         return (this instanceof ParameterizedType);
112     }
113
114     /**
115      * Returns whether this type is a qualified type
116      * (<code>QualifiedType</code>).
117      * <p>
118      * Note that a type like "A.B" can be represented either of two ways:
119      * <ol>
120      * <li>
121      * <code>QualifiedType(SimpleType(SimpleName("A")),SimpleName("B"))</code>
122      * </li>
123      * <li>
124      * <code>SimpleType(QualifiedName(SimpleName("A"),SimpleName("B")))</code>
125      * </li>
126      * </ol>
127      * The first form is preferred when "A" is known to be a type. However, a
128      * parser cannot always determine this. Clients should be prepared to handle
129      * either rather than make assumptions. (Note also that the first form
130      * became possible as of JLS3; only the second form existed in the
131      * JLS2 API.)
132      * </p>
133      *
134      * @return <code>true</code> if this is a qualified type, and
135      * <code>false</code> otherwise
136      * @since 3.1
137      */

138     public final boolean isQualifiedType() {
139         return (this instanceof QualifiedType);
140     }
141
142     /**
143      * Returns whether this type is a wildcard type
144      * (<code>WildcardType</code>).
145      * <p>
146      * Note that a wildcard type is only meaningful as a
147      * type argument of a <code>ParameterizedType</code> node.
148      * </p>
149      *
150      * @return <code>true</code> if this is a wildcard type, and
151      * <code>false</code> otherwise
152      * @since 3.1
153      */

154     public final boolean isWildcardType() {
155         return (this instanceof WildcardType);
156     }
157
158     /**
159      * Resolves and returns the binding for this type.
160      * <p>
161      * Note that bindings are generally unavailable unless requested when the
162      * AST is being built.
163      * </p>
164      *
165      * @return the type binding, or <code>null</code> if the binding cannot be
166      * resolved
167      */

168     public final ITypeBinding resolveBinding() {
169         return this.ast.getBindingResolver().resolveType(this);
170     }
171 }
172
Popular Tags