Package java.lang.reflect

Examples of java.lang.reflect.Type


    if (!(type instanceof TypeVariable<?>)) {
      return null;
    }

    Type targetType = null;
    Map<TypeVariable<?>, Type> typeMap = getTypeMap(targetClass);
    for (Map.Entry<TypeVariable<?>, Type> typeVariableEntry : typeMap.entrySet()) {
      TypeVariable<?> typeVariable = typeVariableEntry.getKey();
      if (typeVariable.getName().equals(((TypeVariable) type).getName())) {
        targetType = typeVariableEntry.getValue();
View Full Code Here


    // build a new TypeVariable -> Type map
    Map<TypeVariable<?>, Type> map = new HashMap<TypeVariable<?>, Type>();
    Class<?> clazz = targetClass;

    while (!Object.class.equals(clazz)) {
      Type genericSuperClass = clazz.getGenericSuperclass();
      if (genericSuperClass instanceof ParameterizedType) {
        collectActualTypeArguments((ParameterizedType) genericSuperClass, map);
      }
      collectActualTypeArguments(clazz.getGenericInterfaces(), map);
      clazz = clazz.getSuperclass();
View Full Code Here

                                                 final Map<TypeVariable<?>, Type> map) {
    for (Type genericInterface : genericInterfaces) {
      if (genericInterface instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) genericInterface;
        collectActualTypeArguments(parameterizedType, map);
        Type rawType = parameterizedType.getRawType();
        collectActualTypeArguments(getGenericInterfaces(rawType), map);

      } else {
        collectActualTypeArguments(getGenericInterfaces(genericInterface), map);
      }
View Full Code Here

   * collects all TypeVariable -> Type mappings from a parameterizedType
   */
  private static void collectActualTypeArguments(final ParameterizedType parameterizedType,
                                                 final Map<TypeVariable<?>, Type> map) {
    // get the raw type of the parameterized class and validate its a class
    Type rawType = parameterizedType.getRawType();
    if (!(rawType instanceof Class))
      return;

    // get variables and types and store them into the map
    TypeVariable<?>[] variables = ((Class<?>) rawType).getTypeParameters();
View Full Code Here

      assertEquals(values[1], convertedList.get(1));

      // List<String> (Generic type)

      // Isn't there an easier way of getting a generic type than this??
      Type t = RemotingTest.class.getMethod("dummy").getGenericReturnType();

      List<String> stringList = (List<String>) wrapper.convert(t);
      assert values.length == stringList.size();
      assertEquals(values[0], stringList.get(0));
      assertEquals(values[1], stringList.get(1));
View Full Code Here

      assert m.containsKey("foo");
      assert m.containsKey("bar");
      assert "aaaaa".equals(m.get("foo"));
      assert "zzzzz".equals(m.get("bar"));

      Type t = RemotingTest.class.getMethod("dummyMap").getGenericReturnType();
      m = (Map) wrapper.convert(t);
      assert m.containsKey("foo");
      assert m.containsKey("bar");
      assert "aaaaa".equals(m.get("foo"));
      assert "zzzzz".equals(m.get("bar"));
View Full Code Here

    } else if (fieldConfig.isForeignCollection()) {
      if (clazz != Collection.class && !ForeignCollection.class.isAssignableFrom(clazz)) {
        throw new SQLException("Field class for '" + field.getName() + "' must be of class "
            + ForeignCollection.class.getSimpleName() + " or Collection.");
      }
      Type type = field.getGenericType();
      if (!(type instanceof ParameterizedType)) {
        throw new SQLException("Field class for '" + field.getName() + "' must be a parameterized Collection.");
      }
      Type[] genericArguments = ((ParameterizedType) type).getActualTypeArguments();
      if (genericArguments.length == 0) {
View Full Code Here

    } else if (fieldConfig.isForeignCollection()) {
      if (clazz != Collection.class && !ForeignCollection.class.isAssignableFrom(clazz)) {
        throw new SQLException("Field class for '" + field.getName() + "' must be of class "
            + ForeignCollection.class.getSimpleName() + " or Collection.");
      }
      Type type = field.getGenericType();
      if (!(type instanceof ParameterizedType)) {
        throw new SQLException("Field class for '" + field.getName() + "' must be a parameterized Collection.");
      }
      Type[] genericArguments = ((ParameterizedType) type).getActualTypeArguments();
      if (genericArguments.length == 0) {
View Full Code Here

@SuppressWarnings("unchecked")
public class FullTextSearcherProvider implements Provider<FullTextSearcher> {
  public FullTextSearcher get() {
      Field field = InjectorContext.currentField();
      Class<?> clazz = String.class;
      Type genericType = field.getGenericType();
      if(genericType instanceof ParameterizedTypeImpl){
        ParameterizedTypeImpl pgType = (ParameterizedTypeImpl)genericType;
        Type[] actualTypeArguments = pgType.getActualTypeArguments();
        clazz = (Class<?>)actualTypeArguments[1];
      }
View Full Code Here

@SuppressWarnings("unchecked")
public class BaseEntityManagerProvider implements Provider<BaseEntityManager> {
    public BaseEntityManager get() {
      Field field = InjectorContext.currentField();
      Class<?> clazz = String.class;
      Type genericType = field.getGenericType();
      if(genericType instanceof ParameterizedTypeImpl){
        ParameterizedTypeImpl pgType = (ParameterizedTypeImpl)genericType;
        Type[] actualTypeArguments = pgType.getActualTypeArguments();
        clazz = (Class<?>)actualTypeArguments[1];
      }
View Full Code Here

TOP

Related Classes of java.lang.reflect.Type

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.