001: /*
002: * @(#)Types.java 1.3 04/06/07
003: *
004: * Copyright (c) 2004, Sun Microsystems, Inc.
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions are met:
009: *
010: * * Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: * * Neither the name of the Sun Microsystems, Inc. nor the names of
016: * its contributors may be used to endorse or promote products derived from
017: * this software without specific prior written permission.
018: *
019: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
020: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
021: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
022: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
023: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
024: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
025: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
026: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
027: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
028: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
029: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030: */
031:
032: package com.sun.mirror.util;
033:
034: import java.util.Collection;
035:
036: import com.sun.mirror.declaration.*;
037: import com.sun.mirror.type.*;
038:
039: /**
040: * Utility methods for operating on types.
041: *
042: * @author Joseph D. Darcy
043: * @author Scott Seligman
044: * @version 1.3 04/06/07
045: * @since 1.5
046: */
047:
048: public interface Types {
049:
050: /**
051: * Tests whether one type is a subtype of the another.
052: * Any type is considered to be a subtype of itself.
053: *
054: * @param t1 the first type
055: * @param t2 the second type
056: * @return <tt>true</tt> if and only if the first type is a subtype
057: * of the second
058: */
059: boolean isSubtype(TypeMirror t1, TypeMirror t2);
060:
061: /**
062: * Tests whether one type is assignable to another.
063: *
064: * @param t1 the first type
065: * @param t2 the second type
066: * @return <tt>true</tt> if and only if the first type is assignable
067: * to the second
068: */
069: boolean isAssignable(TypeMirror t1, TypeMirror t2);
070:
071: /**
072: * Returns the erasure of a type.
073: *
074: * @param t the type to be erased
075: * @return the erasure of the given type
076: */
077: TypeMirror getErasure(TypeMirror t);
078:
079: /**
080: * Returns a primitive type.
081: *
082: * @param kind the kind of primitive type to return
083: * @return a primitive type
084: */
085: PrimitiveType getPrimitiveType(PrimitiveType.Kind kind);
086:
087: /**
088: * Returns the pseudo-type representing the type of <tt>void</tt>.
089: *
090: * @return the pseudo-type representing the type of <tt>void</tt>
091: */
092: VoidType getVoidType();
093:
094: /**
095: * Returns an array type with the specified component type.
096: *
097: * @param componentType the component type
098: * @return an array type with the specified component type.
099: * @throws IllegalArgumentException if the component type is not valid for
100: * an array
101: */
102: ArrayType getArrayType(TypeMirror componentType);
103:
104: /**
105: * Returns the type variable declared by a type parameter.
106: *
107: * @param tparam the type parameter
108: * @return the type variable declared by the type parameter
109: */
110: TypeVariable getTypeVariable(TypeParameterDeclaration tparam);
111:
112: /**
113: * Returns a new wildcard.
114: * Either the wildcards's upper bounds or lower bounds may be
115: * specified, or neither, but not both.
116: *
117: * @param upperBounds the upper bounds of this wildcard,
118: * or an empty collection if none
119: * @param lowerBounds the lower bounds of this wildcard,
120: * or an empty collection if none
121: * @return a new wildcard
122: * @throws IllegalArgumentException if bounds are not valid
123: */
124: WildcardType getWildcardType(Collection<ReferenceType> upperBounds,
125: Collection<ReferenceType> lowerBounds);
126:
127: /**
128: * Returns the type corresponding to a type declaration and
129: * actual type arguments.
130: * Given the declaration for <tt>String</tt>, for example, this
131: * method may be used to get the <tt>String</tt> type. It may
132: * then be invoked a second time, with the declaration for <tt>Set</tt>,
133: * to make the parameterized type {@code Set<String>}.
134: *
135: * <p> The number of type arguments must either equal the
136: * number of the declaration's formal type parameters, or must be
137: * zero. If zero, and if the declaration is generic,
138: * then the declaration's raw type is returned.
139: *
140: * <p> If a parameterized type is being returned, its declaration
141: * must not be contained within a generic outer class.
142: * The parameterized type {@code Outer<String>.Inner<Number>},
143: * for example, may be constructed by first using this
144: * method to get the type {@code Outer<String>}, and then invoking
145: * {@link #getDeclaredType(DeclaredType, TypeDeclaration, TypeMirror...)}.
146: *
147: * @param decl the type declaration
148: * @param typeArgs the actual type arguments
149: * @return the type corresponding to the type declaration and
150: * actual type arguments
151: * @throws IllegalArgumentException if too many or too few
152: * type arguments are given, or if an inappropriate type
153: * argument or declaration is provided
154: */
155: DeclaredType getDeclaredType(TypeDeclaration decl,
156: TypeMirror... typeArgs);
157:
158: /**
159: * Returns the type corresponding to a type declaration
160: * and actual arguments, given a
161: * {@linkplain DeclaredType#getContainingType() containing type}
162: * of which it is a member.
163: * The parameterized type {@code Outer<String>.Inner<Number>},
164: * for example, may be constructed by first using
165: * {@link #getDeclaredType(TypeDeclaration, TypeMirror...)}
166: * to get the type {@code Outer<String>}, and then invoking
167: * this method.
168: *
169: * <p> If the containing type is a parameterized type,
170: * the number of type arguments must equal the
171: * number of the declaration's formal type parameters.
172: * If it is not parameterized or if it is <tt>null</tt>, this method is
173: * equivalent to <tt>getDeclaredType(decl, typeArgs)</tt>.
174: *
175: * @param containing the containing type, or <tt>null</tt> if none
176: * @param decl the type declaration
177: * @param typeArgs the actual type arguments
178: * @return the type corresponding to the type declaration and
179: * actual type arguments,
180: * contained within the given type
181: * @throws IllegalArgumentException if too many or too few
182: * type arguments are given, or if an inappropriate type
183: * argument, declaration, or containing type is provided
184: */
185: DeclaredType getDeclaredType(DeclaredType containing,
186: TypeDeclaration decl, TypeMirror... typeArgs);
187: }
|