Type.java revision 2571:10fc81ac75b4
1/*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.javadoc;
27
28/**
29 * Represents a type.  A type can be a class or interface, an
30 * invocation (like {@code List<String>}) of a generic class or interface,
31 * a type variable, a wildcard type ("{@code ?}"),
32 * or a primitive data type (like {@code char}).
33 *
34 * @since 1.2
35 * @author Kaiyang Liu (original)
36 * @author Robert Field (rewrite)
37 * @author Scott Seligman (generics)
38 */
39public interface Type {
40
41    /**
42     * Return unqualified name of type excluding any dimension information.
43     * <p>
44     * For example, a two dimensional array of String returns
45     * "{@code String}".
46     * @return unqualified name of type excluding any dimension information.
47     */
48    String typeName();
49
50    /**
51     * Return qualified name of type excluding any dimension information.
52     *<p>
53     * For example, a two dimensional array of String
54     * returns "{@code java.lang.String}".
55     * @return qualified name of this type excluding any dimension information.
56     */
57    String qualifiedTypeName();
58
59    /**
60     * Return the simple name of this type excluding any dimension information.
61     * This is the unqualified name of the type, except that for nested types
62     * only the identifier of the innermost type is included.
63     * <p>
64     * For example, the class {@code Outer.Inner} returns
65     * "{@code Inner}".
66     *
67     * @since 1.5
68     * @return the simple name of this type excluding any dimension information.
69     */
70    String simpleTypeName();
71
72    /**
73     * Return the type's dimension information, as a string.
74     * <p>
75     * For example, a two dimensional array of String returns
76     * "{@code [][]}".
77     * @return the type's dimension information as a string.
78     */
79    String dimension();
80
81    /**
82     * Return a string representation of the type.
83     * This includes any dimension information and type arguments.
84     * <p>
85     * For example, a two dimensional array of String may return
86     * "{@code java.lang.String[][]}",
87     * and the parameterized type {@code List<Integer>} may return
88     * "{@code java.util.List<java.lang.Integer>}".
89     *
90     * @return a string representation of the type.
91     */
92    String toString();
93
94    /**
95     * Return true if this type represents a primitive type.
96     *
97     * @return true if this type represents a primitive type.
98     * @since 1.5
99     */
100    boolean isPrimitive();
101
102    /**
103     * Return this type as a {@code ClassDoc} if it represents a class
104     * or interface.  Array dimensions are ignored.
105     * If this type is a {@code ParameterizedType},
106     * {@code TypeVariable}, or {@code WildcardType}, return
107     * the {@code ClassDoc} of the type's erasure.  If this is an
108     * {@code AnnotationTypeDoc}, return this as a {@code ClassDoc}
109     * (but see {@link #asAnnotationTypeDoc()}).
110     * If this is a primitive type, return null.
111     *
112     * @return the {@code ClassDoc} of this type,
113     *         or null if it is a primitive type.
114     */
115    ClassDoc asClassDoc();
116
117    /**
118     * Return this type as a {@code ParameterizedType} if it represents
119     * an invocation of a generic class or interface.  Array dimensions
120     * are ignored.
121     *
122     * @return a {@code ParameterizedType} if the type is an
123     *         invocation of a generic type, or null if it is not.
124     * @since 1.5
125     */
126    ParameterizedType asParameterizedType();
127
128    /**
129     * Return this type as a {@code TypeVariable} if it represents
130     * a type variable.  Array dimensions are ignored.
131     *
132     * @return a {@code TypeVariable} if the type is a type variable,
133     *         or null if it is not.
134     * @since 1.5
135     */
136    TypeVariable asTypeVariable();
137
138    /**
139     * Return this type as a {@code WildcardType} if it represents
140     * a wildcard type.
141     *
142     * @return a {@code WildcardType} if the type is a wildcard type,
143     *         or null if it is not.
144     * @since 1.5
145     */
146    WildcardType asWildcardType();
147
148    /**
149     * Returns this type as a {@code AnnotatedType} if it represents
150     * an annotated type.
151     *
152     * @return a {@code AnnotatedType} if the type if an annotated type,
153     *         or null if it is not
154     * @since 1.8
155     */
156    AnnotatedType asAnnotatedType();
157
158    /**
159     * Return this type as an {@code AnnotationTypeDoc} if it represents
160     * an annotation type.  Array dimensions are ignored.
161     *
162     * @return an {@code AnnotationTypeDoc} if the type is an annotation
163     *         type, or null if it is not.
164     * @since 1.5
165     */
166    AnnotationTypeDoc asAnnotationTypeDoc();
167
168    /**
169     * If this type is an array type, return the element type of the
170     * array. Otherwise, return null.
171     *
172     * @return a {@code Type} representing the element type or null.
173     * @since 1.8
174     */
175    Type getElementType();
176}
177