Package java.lang.reflect

Examples of java.lang.reflect.ParameterizedType


                    else
                    {
                        // Try to derive element type from generics info
                        if (member.getGenericType() instanceof ParameterizedType)
                        {
                            ParameterizedType paramtype = (ParameterizedType)member.getGenericType();
                            if (paramtype.getActualTypeArguments().length == 1)
                            {
                                collectionElementType = ((Class)paramtype.getActualTypeArguments()[0]);
                                elementTypeStr.append(collectionElementType.getName());
                            }
                        }
                    }

                    contmd = new CollectionMetaData(mmd, elementTypeStr.toString(),
                        embeddedElement, dependentElement, serializedElement);

                    // Add any embedded element mappings
                    if (embeddedElementMembers != null)
                    {
                        EmbeddedMetaData embmd = elemmd.getEmbeddedMetaData();
                        for (int j=0;j<embeddedElementMembers.length;j++)
                        {
                            // Add the metadata for the embedded element to the embedded metadata
                            String memberName = embeddedElementMembers[j].name();
                            if (memberName.indexOf('.') > 0)
                            {
                                memberName = memberName.substring(memberName.lastIndexOf('.')+1);
                            }
                            AbstractMemberMetaData embfmd = getFieldMetaDataForPersistent(embmd, embeddedElementMembers[j],
                                isMemberOfClassAField(collectionElementType, memberName));
                            embmd.addMember(embfmd);
                        }
                    }
                }
                else if (member.getType().isArray())
                {
                    StringBuffer elementTypeStr = new StringBuffer();
                    if (elementTypes != null && elementTypes.length > 0 && elementTypes[0] != void.class)
                    {
                        // User-specified element type(s)
                        for (int j=0;j<elementTypes.length;j++)
                        {
                            if (elementTypeStr.length() > 0)
                            {
                                elementTypeStr.append(',');
                            }
                            elementTypeStr.append(elementTypes[j].getName());
                        }
                    }
                    else
                    {
                        // Derive from component type
                        elementTypeStr.append(member.getType().getComponentType().getName());
                    }
                    contmd = new ArrayMetaData(mmd, elementTypeStr.toString(),
                        embeddedElement, dependentElement, serializedElement);
                }
                else if (Map.class.isAssignableFrom(member.getType()))
                {
                    Class mapKeyType = null;
                    if (keyType != null && keyType != void.class)
                    {
                        // User-specified key type
                        mapKeyType = keyType;
                    }
                    else
                    {
                        // Try to derive key type from generics info
                        if (member.getGenericType() instanceof ParameterizedType)
                        {
                            ParameterizedType paramtype = (ParameterizedType)member.getGenericType();
                            if (paramtype.getActualTypeArguments().length == 2)
                            {
                                mapKeyType = ((Class)paramtype.getActualTypeArguments()[0]);
                            }
                        }
                    }

                    Class mapValueType = null;
                    if (valueType != null && valueType != void.class)
                    {
                        // User-specified value type
                        mapValueType = valueType;
                    }
                    else
                    {
                        // Try to derive value type from generics info
                        if (member.getGenericType() instanceof ParameterizedType)
                        {
                            ParameterizedType paramtype = (ParameterizedType)member.getGenericType();
                            if (paramtype.getActualTypeArguments().length == 2)
                            {
                                mapValueType = ((Class)paramtype.getActualTypeArguments()[1]);
                            }
                        }
                    }

                    contmd = new MapMetaData(mmd,
View Full Code Here


    // prove access to generic type information
    Method setter = UserGroupPrime.class.getMethod("setUsers", List.class);
    Type[] parameterTypes = setter.getGenericParameterTypes();
    assertEquals(1, parameterTypes.length);
    ParameterizedType parameterType = (ParameterizedType) parameterTypes[0];
    assertEquals(List.class, parameterType.getRawType());
    assertEquals(UserPrime.class, parameterType.getActualTypeArguments()[0]);

    // check group
    assertNotNull(userGroupPrime);
    assertEquals(userGroup.getName(), userGroupPrime.getName());
View Full Code Here

            return null;
        else if (value instanceof Map) {
            Class<?> itemClass = Object.class;
            Type itemType = null;
            if (type != null && type instanceof ParameterizedType) {
                ParameterizedType ptype = (ParameterizedType) type;
                itemType = ptype.getActualTypeArguments()[1];
                if (itemType.getClass().equals(Class.class)) {
                    itemClass = (Class<?>) itemType;
                } else {
                    itemClass = (Class<?>) ((ParameterizedType) itemType).getRawType();
                }
View Full Code Here

            return null;
       
        Class<?> itemClass = Object.class;
        Type itemType = null;
        if (type != null && type instanceof ParameterizedType) {
            ParameterizedType ptype = (ParameterizedType) type;
            itemType = ptype.getActualTypeArguments()[0];
            if (itemType.getClass().equals(Class.class)) {
                itemClass = (Class<?>) itemType;
            } else {
                itemClass = (Class<?>) ((ParameterizedType) itemType).getRawType();
            }
View Full Code Here

    for (Type type : genericInterfaces)
    {
      if (type instanceof ParameterizedType)
      {
        ParameterizedType t = (ParameterizedType) type;
        Type rawType = t.getRawType();

        if (rawType instanceof Class && rawType.equals(genericInterface))
        {
          Type[] actualTypeArguments = t.getActualTypeArguments();

          if (actualTypeArguments.length > 0)
          {
            Type arg = actualTypeArguments[0];
View Full Code Here

  public static Type[] getGenericTypes(Class c, Class genericInterface)
  {

    Class inputClass = c;

    ParameterizedType genericType = null;

    do
    {
      genericType = getParameterizedType(genericInterface, inputClass);
    }
    while (genericType == null && ((inputClass = inputClass.getSuperclass()) != null));

    if (genericType != null)
    {

      Type[] actualTypeArguments = genericType.getActualTypeArguments();
      return actualTypeArguments;
    }

    return null;
View Full Code Here

  static ParameterizedType getParameterizedType(Class genericInterface, Class inputClass)
  {
    Type[] genericInterfaces = inputClass.getGenericInterfaces();

    ParameterizedType genericType = null;

    for (Type type : genericInterfaces)
    {
      if (type instanceof ParameterizedType)
      {
        ParameterizedType t = (ParameterizedType) type;
        Type rawType = t.getRawType();

        if (rawType instanceof Class && rawType.equals(genericInterface))
        {
          genericType = t;
          break;
View Full Code Here

    {
      return type.toString();
    }
    else if (type instanceof ParameterizedType)
    {
      ParameterizedType pType = (ParameterizedType) type;
      String typeDescription = "parameterized " + getTypeDescription(pType.getRawType());

      Type[] args = pType.getActualTypeArguments();
      String typesDescription = getTypeArrayDescription(args);
      typeDescription = typeDescription + " " + typesDescription;

      return typeDescription;
    }
View Full Code Here

   */
  private static void collectActualTypeArguments(final Type[] genericInterfaces,
                                                 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

                if (f.getAnnotation(org.hibernate.search.annotations.Field.class) != null) fields.add(f.getName());
                if (f.getAnnotation(IndexedEmbedded.class) != null) {
                    String[] subfields;
                    Class<?> fieldClass = f.getType();
                    if (Collection.class.isAssignableFrom(fieldClass)) {
                        ParameterizedType coltype = (ParameterizedType) f.getGenericType();
                        subfields = getAllIndexedFields((Class<?>) coltype.getActualTypeArguments()[0], "allentityfields");
                    } else subfields = getAllIndexedFields(fieldClass, "allentityfields");
                    for (String sf : subfields) fields.add(f.getName() + "." + sf);
                }
            }
        } else fields.add(field);
View Full Code Here

TOP

Related Classes of java.lang.reflect.ParameterizedType

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.