Package java.lang.reflect

Examples of java.lang.reflect.ParameterizedType


  public static Class<?> getTypeClass(Type type) {
    Class<?> clazz = null;
    if (type instanceof Class<?>) {
      clazz = (Class<?>) type;
    } else if (type instanceof ParameterizedType) {
      ParameterizedType pt = (ParameterizedType) type;
      clazz = (Class<?>) pt.getRawType();
    } else if (type instanceof GenericArrayType) {
      GenericArrayType gat = (GenericArrayType) type;
      Class<?> typeClass = getTypeClass(gat.getGenericComponentType());
      return Array.newInstance(typeClass, 0).getClass();
    } else if (type instanceof TypeVariable) {
View Full Code Here


   * @param index The index of the possible parameterized type
   * @return The concrete class (minimum/base) for the generic type, or null if it could not be determined or was not declared
   */
  public static Class<?> getConcreteGeneric (Type type, int index) {
    if (type instanceof ParameterizedType) {
      ParameterizedType pt = (ParameterizedType) type;
      if (pt.getActualTypeArguments().length <= index) return null;
      return pt.getActualTypeArguments()[index] instanceof ParameterizedType ?
        getConcreteGeneric(pt.getRawType(), 0) : getConcreteGeneric(pt.getActualTypeArguments()[index], 0);
    } else if (type instanceof WildcardType) {
      WildcardType wt = (WildcardType) type;
      return wt.getUpperBounds().length <= index ? null : getConcreteGeneric(wt.getUpperBounds()[index], 0);
    } else if (type instanceof TypeVariable) {
      TypeVariable tt = (TypeVariable) type;
View Full Code Here

        re = new HashMap();
      else
        re = (Map) me.born();
      if (type instanceof ParameterizedType) {
        // 看来有泛型信息哦
        ParameterizedType pt = (ParameterizedType) type;
        Type[] ts = pt.getActualTypeArguments();
        Type tt = null;
        if (ts != null && ts.length > 1)
          tt = Lang.getTypeClass(ts[1]);// TODO 只能做到一层的泛型
        for (Entry<String, Object> entry : map.entrySet()) {
          re.put(entry.getKey(), convert(tt, entry.getValue()));
View Full Code Here

  @SuppressWarnings({"unchecked", "rawtypes"})
  Object list2Object(Type type, List<Object> list) {
    Class<?> clazz = Lang.getTypeClass(type);
    Type tt = null;
    if (type instanceof ParameterizedType) {
      ParameterizedType pt = (ParameterizedType) type;
      Type[] ts = pt.getActualTypeArguments();
      if (ts != null && ts.length > 0)
        tt = Lang.getTypeClass(ts[0]);// TODO 只能做到一层的泛型
    }
    if (clazz.isArray()) {// 看来是数组
      List re = new ArrayList(list.size());
View Full Code Here

        return getWorld().resolve(ut);
      } else {
        return getWorld().resolve(name);
      }
    } else if (aType instanceof ParameterizedType) {
      ParameterizedType pt = (ParameterizedType) aType;
      ResolvedType baseType = fromType(pt.getRawType());
      Type[] args = pt.getActualTypeArguments();
      ResolvedType[] resolvedArgs = fromTypes(args);
/*      StringBuilder sb = new StringBuilder();
      for (int i = 0; i < resolvedArgs.length; i++) {
        sb.append(resolvedArgs[i]).append(" ");
      }
View Full Code Here

    Class cl = service.getClass();
    Type[] interfaces = cl.getGenericInterfaces();

    for (int i = 0; i < interfaces.length; i++) {
      if (interfaces[i] instanceof ParameterizedType) {
        ParameterizedType pType = (ParameterizedType) interfaces[i];

        if (Provider.class.equals(pType.getRawType())) {
          Type[] args = pType.getActualTypeArguments();

          if (args.length == 1) {
            if (Source.class.equals(args[0]))
              return new SourceProviderEncoding(service);
            else if (SOAPMessage.class.equals(args[0]))
View Full Code Here

        return new SkeletonProperty(skel);
      else
        return null;
    }
    else if (type instanceof ParameterizedType) {
      ParameterizedType ptype = (ParameterizedType) type;
      Type rawType = ptype.getRawType();

      if (rawType instanceof Class) {
        Class rawClass = (Class) rawType;

        if (Map.class.isAssignableFrom(rawClass)) {
          Type[] args = ptype.getActualTypeArguments();

          if (args.length != 2)
            throw new JAXBException(L.l("unexpected number of generic arguments for Map<>: {0}", args.length));

          Property keyProperty = createProperty(args[0], anyType);
          Property valueProperty = createProperty(args[1], anyType);

          return new MapProperty(rawClass, keyProperty, valueProperty);
        }

        if (Collection.class.isAssignableFrom(rawClass)) {
          Type[] args = ptype.getActualTypeArguments();

          if (args.length != 1)
            throw new JAXBException(L.l("unexpected number of generic arguments for List<>: {0}", args.length));

          Property componentProperty = createProperty(args[0], anyType);
View Full Code Here

        ClassSkeleton skeleton = null;
        QName root = null;

        if (cl.equals(JAXBElement.class)) {
          ParameterizedType type =
            (ParameterizedType) method.getGenericReturnType();
          cl = (Class) type.getActualTypeArguments()[0];

          skeleton = new JAXBElementSkeleton(this, cl, method, objectFactory);
          _jaxbElementSkeletons.put(cl, (JAXBElementSkeleton) skeleton);
        }
        else {
View Full Code Here

   **/
  public static Type getActualParameterType(Type type)
    throws JAXBException
  {
    if (type instanceof ParameterizedType) {
      ParameterizedType ptype = (ParameterizedType) type;

      if (ptype.getRawType().equals(Holder.class)) {
        Type[] arguments = ptype.getActualTypeArguments();

        if (arguments.length != 1)
          throw new JAXBException("Holder has incorrect number of arguments");

        return arguments[0];
View Full Code Here

      if (! cl.isInterface())
        jaxbClasses.add((Class) type);
    }
    else if (type instanceof ParameterizedType) {
      ParameterizedType pType = (ParameterizedType) type;

      introspectType(pType.getRawType(), jaxbClasses);
      introspectType(pType.getOwnerType(), jaxbClasses);

      Type[] arguments = pType.getActualTypeArguments();

      for (Type argument : arguments)
        introspectType(argument, jaxbClasses);
    }
    else if (type instanceof GenericArrayType) {
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.