KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > mirror > util > Types


1 /*
2  * @(#)Types.java 1.3 04/06/07
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.mirror.util;
9
10
11 import java.util.Collection JavaDoc;
12
13 import com.sun.mirror.declaration.*;
14 import com.sun.mirror.type.*;
15
16
17 /**
18  * Utility methods for operating on types.
19  *
20  * @author Joseph D. Darcy
21  * @author Scott Seligman
22  * @version 1.3 04/06/07
23  * @since 1.5
24  */

25
26 public interface Types {
27
28     /**
29      * Tests whether one type is a subtype of the another.
30      * Any type is considered to be a subtype of itself.
31      *
32      * @param t1 the first type
33      * @param t2 the second type
34      * @return <tt>true</tt> if and only if the first type is a subtype
35      * of the second
36      */

37     boolean isSubtype(TypeMirror t1, TypeMirror t2);
38
39     /**
40      * Tests whether one type is assignable to another.
41      *
42      * @param t1 the first type
43      * @param t2 the second type
44      * @return <tt>true</tt> if and only if the first type is assignable
45      * to the second
46      */

47     boolean isAssignable(TypeMirror t1, TypeMirror t2);
48
49     /**
50      * Returns the erasure of a type.
51      *
52      * @param t the type to be erased
53      * @return the erasure of the given type
54      */

55     TypeMirror getErasure(TypeMirror t);
56
57     /**
58      * Returns a primitive type.
59      *
60      * @param kind the kind of primitive type to return
61      * @return a primitive type
62      */

63     PrimitiveType getPrimitiveType(PrimitiveType.Kind kind);
64
65     /**
66      * Returns the pseudo-type representing the type of <tt>void</tt>.
67      *
68      * @return the pseudo-type representing the type of <tt>void</tt>
69      */

70     VoidType getVoidType();
71
72     /**
73      * Returns an array type with the specified component type.
74      *
75      * @param componentType the component type
76      * @return an array type with the specified component type.
77      * @throws IllegalArgumentException if the component type is not valid for
78      * an array
79      */

80     ArrayType getArrayType(TypeMirror componentType);
81
82     /**
83      * Returns the type variable declared by a type parameter.
84      *
85      * @param tparam the type parameter
86      * @return the type variable declared by the type parameter
87      */

88     TypeVariable getTypeVariable(TypeParameterDeclaration tparam);
89
90     /**
91      * Returns a new wildcard.
92      * Either the wildcards's upper bounds or lower bounds may be
93      * specified, or neither, but not both.
94      *
95      * @param upperBounds the upper bounds of this wildcard,
96      * or an empty collection if none
97      * @param lowerBounds the lower bounds of this wildcard,
98      * or an empty collection if none
99      * @return a new wildcard
100      * @throws IllegalArgumentException if bounds are not valid
101      */

102     WildcardType getWildcardType(Collection JavaDoc<ReferenceType> upperBounds,
103                  Collection JavaDoc<ReferenceType> lowerBounds);
104
105     /**
106      * Returns the type corresponding to a type declaration and
107      * actual type arguments.
108      * Given the declaration for <tt>String</tt>, for example, this
109      * method may be used to get the <tt>String</tt> type. It may
110      * then be invoked a second time, with the declaration for <tt>Set</tt>,
111      * to make the parameterized type {@code Set<String>}.
112      *
113      * <p> The number of type arguments must either equal the
114      * number of the declaration's formal type parameters, or must be
115      * zero. If zero, and if the declaration is generic,
116      * then the declaration's raw type is returned.
117      *
118      * <p> If a parameterized type is being returned, its declaration
119      * must not be contained within a generic outer class.
120      * The parameterized type {@code Outer<String>.Inner<Number>},
121      * for example, may be constructed by first using this
122      * method to get the type {@code Outer<String>}, and then invoking
123      * {@link #getDeclaredType(DeclaredType, TypeDeclaration, TypeMirror...)}.
124      *
125      * @param decl the type declaration
126      * @param typeArgs the actual type arguments
127      * @return the type corresponding to the type declaration and
128      * actual type arguments
129      * @throws IllegalArgumentException if too many or too few
130      * type arguments are given, or if an inappropriate type
131      * argument or declaration is provided
132      */

133     DeclaredType getDeclaredType(TypeDeclaration decl,
134                  TypeMirror... typeArgs);
135
136     /**
137      * Returns the type corresponding to a type declaration
138      * and actual arguments, given a
139      * {@linkplain DeclaredType#getContainingType() containing type}
140      * of which it is a member.
141      * The parameterized type {@code Outer<String>.Inner<Number>},
142      * for example, may be constructed by first using
143      * {@link #getDeclaredType(TypeDeclaration, TypeMirror...)}
144      * to get the type {@code Outer<String>}, and then invoking
145      * this method.
146      *
147      * <p> If the containing type is a parameterized type,
148      * the number of type arguments must equal the
149      * number of the declaration's formal type parameters.
150      * If it is not parameterized or if it is <tt>null</tt>, this method is
151      * equivalent to <tt>getDeclaredType(decl, typeArgs)</tt>.
152      *
153      * @param containing the containing type, or <tt>null</tt> if none
154      * @param decl the type declaration
155      * @param typeArgs the actual type arguments
156      * @return the type corresponding to the type declaration and
157      * actual type arguments,
158      * contained within the given type
159      * @throws IllegalArgumentException if too many or too few
160      * type arguments are given, or if an inappropriate type
161      * argument, declaration, or containing type is provided
162      */

163     DeclaredType getDeclaredType(DeclaredType containing,
164                  TypeDeclaration decl,
165                  TypeMirror... typeArgs);
166 }
167
Popular Tags