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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.core.dom;
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.
41 * Type <b>[</b> <b>]</b>
45 * Type <b><</b> Type { <b>,</b> Type } <b>></b>
47 * Type <b>.</b> SimpleName
49 * <b>?</b> [ ( <b>extends</b> | <b>super</b>) Type ]
55 public abstract class Type extends ASTNode {
58 * Creates a new AST node for a type owned by the given AST.
60 * N.B. This constructor is package-private.
63 * @param ast the AST that is to own this node
70 * Returns whether this type is a primitive type
71 * (<code>PrimitiveType</code>).
73 * @return <code>true</code> if this is a primitive type, and
74 * <code>false</code> otherwise
76 public final boolean isPrimitiveType() {
77 return (this instanceof PrimitiveType);
81 * Returns whether this type is a simple type
82 * (<code>SimpleType</code>).
84 * @return <code>true</code> if this is a simple type, and
85 * <code>false</code> otherwise
87 public final boolean isSimpleType() {
88 return (this instanceof SimpleType);
92 * Returns whether this type is an array type
93 * (<code>ArrayType</code>).
95 * @return <code>true</code> if this is an array type, and
96 * <code>false</code> otherwise
98 public final boolean isArrayType() {
99 return (this instanceof ArrayType);
103 * Returns whether this type is a parameterized type
104 * (<code>ParameterizedType</code>).
106 * @return <code>true</code> if this is a parameterized type, and
107 * <code>false</code> otherwise
110 public final boolean isParameterizedType() {
111 return (this instanceof ParameterizedType);
115 * Returns whether this type is a qualified type
116 * (<code>QualifiedType</code>).
118 * Note that a type like "A.B" can be represented either of two ways:
121 * <code>QualifiedType(SimpleType(SimpleName("A")),SimpleName("B"))</code>
124 * <code>SimpleType(QualifiedName(SimpleName("A"),SimpleName("B")))</code>
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
134 * @return <code>true</code> if this is a qualified type, and
135 * <code>false</code> otherwise
138 public final boolean isQualifiedType() {
139 return (this instanceof QualifiedType);
143 * Returns whether this type is a wildcard type
144 * (<code>WildcardType</code>).
146 * Note that a wildcard type is only meaningful as a
147 * type argument of a <code>ParameterizedType</code> node.
150 * @return <code>true</code> if this is a wildcard type, and
151 * <code>false</code> otherwise
154 public final boolean isWildcardType() {
155 return (this instanceof WildcardType);
159 * Resolves and returns the binding for this type.
161 * Note that bindings are generally unavailable unless requested when the
162 * AST is being built.
165 * @return the type binding, or <code>null</code> if the binding cannot be
168 public final ITypeBinding resolveBinding() {
169 return this.ast.getBindingResolver().resolveType(this);