Package java.lang.reflect

Examples of java.lang.reflect.Type


        if (genericType instanceof ParameterizedType)
        {
            ParameterizedType paramtype = (ParameterizedType)genericType;
            if (paramtype.getActualTypeArguments().length == 1)
            {
                Type argType = paramtype.getActualTypeArguments()[0];
                if (argType instanceof Class)
                {
                    return (Class) argType;
                }
                else if (argType instanceof ParameterizedType)
                {
                    return (Class) ((ParameterizedType)argType).getRawType();
                }
                else if (argType instanceof GenericArrayType)
                {
                    // Create array of zero length to get class of array type (is there a better way?)
                    Type cmptType = ((GenericArrayType)argType).getGenericComponentType();
                    return Array.newInstance((Class)cmptType, 0).getClass();
                }
                else
                {
                    throw new NucleusUserException("Unsupported generic type: " + argType);
View Full Code Here


        if (genericType instanceof ParameterizedType)
        {
            ParameterizedType paramtype = (ParameterizedType)genericType;
            if (paramtype.getActualTypeArguments().length == 2)
            {
                Type argType = paramtype.getActualTypeArguments()[0];
                if (argType instanceof Class)
                {
                    return (Class) argType;
                }
                else if (argType instanceof ParameterizedType)
                {
                    return (Class) ((ParameterizedType)argType).getRawType();
                }
                else if (argType instanceof GenericArrayType)
                {
                    // Create array of zero length to get class of array type (is there a better way?)
                    Type cmptType = ((GenericArrayType)argType).getGenericComponentType();
                    return Array.newInstance((Class)cmptType, 0).getClass();
                }
                else
                {
                    throw new NucleusUserException("Unsupported generic type: " + argType);
View Full Code Here

        if (genericType instanceof ParameterizedType)
        {
            ParameterizedType paramtype = (ParameterizedType)genericType;
            if (paramtype.getActualTypeArguments().length == 2)
            {
                Type argType = paramtype.getActualTypeArguments()[1];
                if (argType instanceof Class)
                {
                    return (Class) argType;
                }
                else if (argType instanceof ParameterizedType)
                {
                    return (Class) ((ParameterizedType)argType).getRawType();
                }
                else if (argType instanceof GenericArrayType)
                {
                    // Create array of zero length to get class of array type (is there a better way?)
                    Type cmptType = ((GenericArrayType)argType).getGenericComponentType();
                    return Array.newInstance((Class)cmptType, 0).getClass();
                }
                else
                {
                    throw new NucleusUserException("Unsupported generic type: " + argType);
View Full Code Here

                    first = false;
                }
                sb.append("> ");
            }

            Type genRetType = method.getGenericReturnType();

            sb.append(((genRetType instanceof Class)
                    ? getTypeName((Class) genRetType) : genRetType.toString()) + " ");

            sb.append(getTypeName(method.getDeclaringClass())).append(".");

            sb.append(method.getName()).append("(");
            Type[] params = method.getGenericParameterTypes();
View Full Code Here

   * @param p
   *          Field to examine
   * @return The Class<?> of generic type if any, otherwise null
   */
  public static Class<?> getGenericMultivalueType(final Field p) {
    final Type genericType = p.getGenericType();
    if (genericType != null && genericType instanceof ParameterizedType) {
      final ParameterizedType pt = (ParameterizedType) genericType;
      if (pt.getActualTypeArguments() != null && pt.getActualTypeArguments().length > 0) {
        if (pt.getActualTypeArguments()[0] instanceof Class<?>) {
          return (Class<?>) pt.getActualTypeArguments()[0];
View Full Code Here

   */
  public static Type[] getTypeParams(Class<?> klass) {
    if (klass == null || "java.lang.Object".equals(klass.getName()))
      return null;
    // 看看父类
    Type superclass = klass.getGenericSuperclass();
    if (null != superclass && superclass instanceof ParameterizedType)
      return ((ParameterizedType) superclass).getActualTypeArguments();

    // 看看接口
    Type[] interfaces = klass.getGenericInterfaces();
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  public static <T> Class<T> getTypeParam(Class<?> klass, int index) {
    Type[] types = getTypeParams(klass);
    if (index >= 0 && index < types.length) {
      Type t = types[index];
      Class<T> clazz = (Class<T>) Lang.getTypeClass(t);
      if (clazz == null)
        throw Lang.makeThrow("Type '%s' is not a Class", t.toString());
      return clazz;
    }
    throw Lang.makeThrow("Class type param out of range %d/%d", index, types.length);
  }
View Full Code Here

        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 只能做到一层的泛型
View Full Code Here

  @Override
  public ResolvedType getSuperclass() {
    if (superclass == null && getBaseClass() != Object.class) {// superclass
      // of Object
      // is null
      Type t = this.getBaseClass().getGenericSuperclass();
      if (t != null) {
        superclass = typeConverter.fromType(t);
      }
      if (t == null) {
        superclass = getWorld().resolve(UnresolvedType.OBJECT);
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.