Lines Matching refs:type

29  * Super type token; allows capturing generic types at runtime by forcing them to be reified.
43 * <p>See <a href="http://gafter.blogspot.com/2007/05/limitation-of-super-type-tokens.html">
44 * http://gafter.blogspot.com/2007/05/limitation-of-super-type-tokens.html</a>
52 * Create a new type reference for {@code T}.
54 * @throws IllegalArgumentException if {@code T}'s actual type contains a type variable
65 * Prohibit type references with type variables such as
69 * Since the "T" there is not known without an instance of T, type equality would
71 * some of the type safety of a type reference.
75 "Including a type variable in a type reference is not allowed");
81 * Return the dynamic {@link Type} corresponding to the captured type {@code T}.
87 private TypeReference(Type type) {
88 mType = type;
91 "Including a type variable in a type reference is not allowed");
104 public SpecializedBaseTypeReference(Type type) {
105 super(type);
110 * Create a specialized type reference from a dynamic class instance,
113 * <p>As with a regular type reference, the {@code klass} must not contain
114 * any type variables.</p>
118 * @return a type reference which captures {@code T} at runtime
120 * @throws IllegalArgumentException if {@code T} had any type variables
127 * Create a specialized type reference from a dynamic {@link Type} instance,
130 * <p>As with a regular type reference, the {@code type} must not contain
131 * any type variables.</p>
133 * @param type a non-{@code null} {@link Type} instance
135 * @return a type reference which captures {@code T} at runtime
137 * @throws IllegalArgumentException if {@code type} had any type variables
139 public static TypeReference<?> createSpecializedTypeReference(Type type) {
140 return new SpecializedBaseTypeReference(type);
144 * Returns the raw type of T.
148 * <li>If T is a ParameterizedType, the raw type of the parameterized type is returned.
149 * <li>If T is a GenericArrayType, the returned type is the corresponding array class.
151 * <li>If T is a type variable or a wildcard type, the raw type of the first upper bound is
155 * @return the raw type of {@code T}
162 private static final Class<?> getRawType(Type type) {
163 if (type == null) {
164 throw new NullPointerException("type must not be null");
167 if (type instanceof Class<?>) {
168 return (Class<?>)type;
169 } else if (type instanceof ParameterizedType) {
170 return (Class<?>)(((ParameterizedType)type).getRawType());
171 } else if (type instanceof GenericArrayType) {
172 return getArrayClass(getRawType(((GenericArrayType)type).getGenericComponentType()));
173 } else if (type instanceof WildcardType) {
175 return getRawType(((WildcardType) type).getUpperBounds());
176 } else if (type instanceof TypeVariable) {
177 throw new AssertionError("Type variables are not allowed in type references");
180 throw new AssertionError("Unhandled branch to get raw type for type " + type);
189 for (Type type : types) {
190 Class<?> klass = getRawType(type);
204 * Get the component type, e.g. {@code T} from {@code T[]}.
206 * @return component type, or {@code null} if {@code T} is not an array
216 private static Type getComponentType(Type type) {
217 checkNotNull(type, "type must not be null");
219 if (type instanceof Class<?>) {
220 return ((Class<?>) type).getComponentType();
221 } else if (type instanceof ParameterizedType) {
223 } else if (type instanceof GenericArrayType) {
224 return ((GenericArrayType)type).getGenericComponentType();
225 } else if (type instanceof WildcardType) {
228 } else if (type instanceof TypeVariable) {
229 throw new AssertionError("Type variables are not allowed in type references");
232 throw new AssertionError("Unhandled branch to get component type for type " + type);
239 * <p>A TypeReference is only equal to another TypeReference if their captured type {@code T}
245 // with nested type variables; therefore we ban type variables in the constructor.
258 * Check if the {@code type} contains a {@link TypeVariable} recursively.
260 * <p>Intuitively, a type variable is a type in a type expression that refers to a generic
261 * type which is not known at the definition of the expression (commonly seen when
262 * type parameters are used, e.g. {@code class Foo<T>}).</p>
266 * for a more formal definition of a type variable</p>.
268 * @param type a type object ({@code null} is allowed)
269 * @return {@code true} if there were nested type variables; {@code false} otherwise
271 public static boolean containsTypeVariable(Type type) {
272 if (type == null) {
275 } else if (type instanceof TypeVariable<?>) {
280 } else if (type instanceof Class<?>) {
282 * class Foo -> no type variable
283 * class Foo<T> - has a type variable
286 * since everything on the right hand side would either include a type variable T
287 * or have no type variables.
289 Class<?> klass = (Class<?>)type;
295 // Does the outer class(es) contain any type variables?
304 * In this case 'Inner' has no type parameters itself, but it still has a type
305 * variable as part of the type definition.
309 } else if (type instanceof ParameterizedType) {
313 * // no type variables here, T1-Tn are known at this definition
316 * // T1 is a type variable, T2-Tn are known at this definition
319 ParameterizedType p = (ParameterizedType) type;
329 } else if (type instanceof WildcardType) {
330 WildcardType wild = (WildcardType) type;
335 * Foo<?> --> unbounded; trivially no type variables
336 * Foo<? super T> --> lower bound; does T have a type variable?
337 * Foo<? extends T> --> upper bound; does T have a type variable?
369 private static void toString(Type type, StringBuilder out) {
370 if (type == null) {
372 } else if (type instanceof TypeVariable<?>) {
374 out.append(((TypeVariable<?>)type).getName());
375 } else if (type instanceof Class<?>) {
376 Class<?> klass = (Class<?>)type;
380 } else if (type instanceof ParameterizedType) {
382 ParameterizedType p = (ParameterizedType) type;
386 } else if (type instanceof GenericArrayType) {
387 GenericArrayType gat = (GenericArrayType)type;
393 out.append(type.toString());
417 * Check if any of the elements in this array contained a type variable.
419 * <p>Empty and null arrays trivially have no type variables.</p>
422 * @return true if any elements contained a type variable; false otherwise
429 for (Type type : typeArray) {
430 if (containsTypeVariable(type)) {