Top Description Constructors Methods
org.hibernate.annotations.common.reflection.java.generics

pack-priv final Class ApproximatingTypeEnvironment

extends Object
implements TypeEnvironment
Class Inheritance
All Implemented Interfaces
org.hibernate.annotations.common.reflection.java.generics.TypeEnvironment
Imports
java.lang.reflect.Array, .GenericArrayType, .ParameterizedType, .Type, .TypeVariable, .WildcardType

A TypeEnvironment that approximates the unresolved components of a generic simple type or collection to their nearest upper binding. The returned type is always fully resolved.

The concept of "type approximation" is not really sound in general. This class just does what we need within the Hibernate Annotations environment. It's more or less a hack. The idea is that certain types can provide useful information even if they're not fully resolved in the environment. This class tries to turn those types into the nearest fully resolved type that still carries that information.

For example:
T becomes Object.
T extends Foo becomes Foo.
List<T> becomes List<Object>.
List<T extends Foo> becomes List<Foo>.
An array of T extends Foo becomes an array of Foo.

If a type variable has multiple upper bounds, it will be approximated to Object. Lower bounds are ignored.

Wildcards are generally not approximated. Class<?> stays Class<?>. A wildcard within a generic collection is approximated to its upper binding. List<?> becomes List<Object>

Note that Class<T> is not approximated Class<Object>. That would be wrong in any situation. All parametric types that are not type variables, collections or arrays are coarsely approximated to Object.class.

Author
Paolo Perrotta

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Type
bind(final Type type)

Implements org.hibernate.annotations.common.reflection.java.generics.TypeEnvironment.bind.

Binds as many generic components of the given type as possible in this context.
private Type
private Type
fineApproximation(final Type type)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Constructor Detail

ApproximatingTypeEnvironmentback to summary
pack-priv ApproximatingTypeEnvironment()

Method Detail

bindback to summary
public Type bind(final Type type)

Implements org.hibernate.annotations.common.reflection.java.generics.TypeEnvironment.bind.

Doc from org.hibernate.annotations.common.reflection.java.generics.TypeEnvironment.bind.

Binds as many generic components of the given type as possible in this context.

Warning

if the returned Type is a Class, then it's guaranteed to be a regular Java Class. In all other cases, this method might return a custom implementation of some interface that extends Type. Be sure not to mix these objects with Java's implementations of Type to avoid potential identity problems.

This class does not support bindings involving inner classes or upper/lower bounds.

Returns:Type

a type where the generic arguments have been replaced by raw classes whenever this is possible.

coarseApproximationback to summary
private Type coarseApproximation(final Type type)
fineApproximationback to summary
private Type fineApproximation(final Type type)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override