当前位置: 首页>>代码示例>>Java>>正文


Java ParameterizedType.getRawType方法代码示例

本文整理汇总了Java中java.lang.reflect.ParameterizedType.getRawType方法的典型用法代码示例。如果您正苦于以下问题:Java ParameterizedType.getRawType方法的具体用法?Java ParameterizedType.getRawType怎么用?Java ParameterizedType.getRawType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.ParameterizedType的用法示例。


在下文中一共展示了ParameterizedType.getRawType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: canonicalize

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
/**
 * Returns a type that is functionally equal but not necessarily equal according to {@link
 * Object#equals(Object) Object.equals()}.
 */
static Type canonicalize(Type type) {
  if (type instanceof Class) {
    Class<?> c = (Class<?>) type;
    return c.isArray() ? new GenericArrayTypeImpl(canonicalize(c.getComponentType())) : c;

  } else if (type instanceof ParameterizedType) {
    if (type instanceof ParameterizedTypeImpl) return type;
    ParameterizedType p = (ParameterizedType) type;
    return new ParameterizedTypeImpl(p.getOwnerType(),
        p.getRawType(), p.getActualTypeArguments());

  } else if (type instanceof GenericArrayType) {
    if (type instanceof GenericArrayTypeImpl) return type;
    GenericArrayType g = (GenericArrayType) type;
    return new GenericArrayTypeImpl(g.getGenericComponentType());

  } else if (type instanceof WildcardType) {
    if (type instanceof WildcardTypeImpl) return type;
    WildcardType w = (WildcardType) type;
    return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds());

  } else {
    return type; // This type is unsupported!
  }
}
 
开发者ID:hzsweers,项目名称:inspector,代码行数:30,代码来源:Types.java

示例2: getParametrizedTypes

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
/**
 * Getting parametrized classes of {@code JAXBElement<...>} property
 * @param p property which parametrized types we will try to get
 * @return null - if it's not JAXBElement property, or it's not parametrized, and array of parametrized classes in other case
 */
private Class[] getParametrizedTypes(PropertyInfo p) {
    try {
        Type pType = ((RuntimePropertyInfo) p).getIndividualType();
        if (pType instanceof ParameterizedType) {
            ParameterizedType prmzdType = (ParameterizedType) pType;
            if (prmzdType.getRawType() == JAXBElement.class) {
                Type[] actualTypes = prmzdType.getActualTypeArguments();
                Class[] result = new Class[actualTypes.length];
                for (int i = 0; i < actualTypes.length; i++) {
                    result[i] = (Class) actualTypes[i];
                }
                return result;
            }
        }
    } catch (Exception e) {
        logger.log(Level.FINE, "Error in ModelBuilder.getParametrizedTypes. " + e.getMessage());
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ModelBuilder.java

示例3: convert

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
private static Object convert(Type targetType, Object sourceObject, ViewDecoration decoration, ViewGraphDetails graphDetails) {
    if (targetType instanceof ParameterizedType) {
        ParameterizedType parameterizedTargetType = (ParameterizedType) targetType;
        if (parameterizedTargetType.getRawType() instanceof Class) {
            Class<?> rawClass = (Class<?>) parameterizedTargetType.getRawType();
            if (Iterable.class.isAssignableFrom(rawClass)) {
                Type targetElementType = getElementType(parameterizedTargetType, 0);
                return convertCollectionInternal(rawClass, targetElementType, (Iterable<?>) sourceObject, decoration, graphDetails);
            }
            if (Map.class.isAssignableFrom(rawClass)) {
                Type targetKeyType = getElementType(parameterizedTargetType, 0);
                Type targetValueType = getElementType(parameterizedTargetType, 1);
                return convertMap(rawClass, targetKeyType, targetValueType, (Map<?, ?>) sourceObject, decoration, graphDetails);
            }
        }
    }
    if (targetType instanceof Class) {
        if (((Class) targetType).isPrimitive()) {
            return sourceObject;
        }
        return createView((Class) targetType, sourceObject, decoration, graphDetails);
    }
    throw new UnsupportedOperationException(String.format("Cannot convert object of %s to %s.", sourceObject.getClass(), targetType));
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:25,代码来源:ProtocolToModelAdapter.java

示例4: deserialze

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    ParameterizedType paramType = (ParameterizedType) type;
    Type itemType = paramType.getActualTypeArguments()[0];

    Object itemObject = parser.parseObject(itemType);

    Type rawType = paramType.getRawType();
    if (rawType == AtomicReference.class) {
        return (T) new AtomicReference(itemObject);
    }

    if (rawType == WeakReference.class) {
        return (T) new WeakReference(itemObject);
    }

    if (rawType == SoftReference.class) {
        return (T) new SoftReference(itemObject);
    }

    throw new UnsupportedOperationException(rawType.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:ReferenceCodec.java

示例5: getGenericInterfaceType

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
/**
 * Gets the generic type parameter from an interface of type interfaceClass declared on class declaringClass.
 */
public static final Type getGenericInterfaceType(final Class<?> declaringClass, final Class<?> interfaceClass)
{
	for (Type type : declaringClass.getGenericInterfaces())
	{
		if (type instanceof ParameterizedType)
		{
			final ParameterizedType parameterizedType = (ParameterizedType)type;
			if (parameterizedType.getRawType() == interfaceClass)
			{
				return parameterizedType.getActualTypeArguments()[0];
			}
		}
	}
	return null;
}
 
开发者ID:crazysnailboy,项目名称:VillagerInventory,代码行数:19,代码来源:ReflectionHelper.java

示例6: onParameterizdType

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
public Type onParameterizdType(ParameterizedType p, BinderArg args) {
    Type[] params = p.getActualTypeArguments();

    boolean different = false;
    for (int i = 0; i < params.length; i++) {
        Type t = params[i];
        params[i] = visit(t, args);
        different |= t != params[i];
    }

    Type newOwner = p.getOwnerType();
    if (newOwner != null) {
        newOwner = visit(newOwner, args);
    }
    different |= p.getOwnerType() != newOwner;

    if (!different) {
        return p;
    }

    return new ParameterizedTypeImpl((Class<?>) p.getRawType(), params, newOwner);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ReflectionNavigator.java

示例7: typeArg

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
static Type typeArg(Type type, Class<?> wantedRawType, int index) {
    if (type instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) type;
        Type rawType = parameterizedType.getRawType();
        if (rawType instanceof Class && wantedRawType.isAssignableFrom((Class) rawType)) {
            Type result = parameterizedType.getActualTypeArguments()[index];
            if (result instanceof TypeVariable) {
                throw new ParserException("Generic types must be explicit");
            }
            return result;
        } else {
            return null;
        }
    } else {
        return null;
    }
}
 
开发者ID:andrewjc,项目名称:kheera-testrunner-android,代码行数:18,代码来源:TableConverter.java

示例8: toStringPT

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
static String toStringPT(ParameterizedType pt) {
    StringBuilder sb = new StringBuilder();
    Type ownerType = pt.getOwnerType();
    Class<?> rawType = (Class<?>) pt.getRawType();
    Type[] actualTypeArguments = pt.getActualTypeArguments();
    sb.append(rawType.getName().replace('$', '.'));

    if (actualTypeArguments != null && actualTypeArguments.length > 0) {
        sb.append("<");
        boolean first = true;
        for (Type t : actualTypeArguments) {
            if (!first)
                sb.append(", ");
            sb.append(((Class<?>) t).getName());
            first = false;
        }
        sb.append(">");
    }

    return sb.toString();
}
 
开发者ID:sap-nocops,项目名称:Jerkoff,代码行数:22,代码来源:GsonTest.java

示例9: equals

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
@Override
public boolean equals(Object o) {
  if (o instanceof ParameterizedType) {
    ParameterizedType that = (ParameterizedType) o;
    if (this == that) {
      return true;
    }
    Type thatOwner = that.getOwnerType();
    Type thatRawType = that.getRawType();
    return Objects.equals(ownerType, thatOwner) &&
        Objects.equals(rawType, thatRawType) &&
        Arrays.equals(actualTypeArguments, that.getActualTypeArguments());
  } else {
    return false;
  }
}
 
开发者ID:XDean,项目名称:Java-EX,代码行数:17,代码来源:ParameterizedTypeImpl.java

示例10: canonicalize

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
/**
 * Returns a type that is functionally equal but not necessarily equal according to {@link
 * Object#equals(Object) Object.equals()}.
 */
private static Type canonicalize(Type type) {
  if (type instanceof Class) {
    Class<?> c = (Class<?>) type;
    return c.isArray() ? new GenericArrayTypeImpl(canonicalize(c.getComponentType())) : c;
  } else if (type instanceof ParameterizedType) {
    if (type instanceof ParameterizedTypeImpl) return type;
    ParameterizedType p = (ParameterizedType) type;
    return new ParameterizedTypeImpl(p.getOwnerType(),
      p.getRawType(), p.getActualTypeArguments());
  } else if (type instanceof GenericArrayType) {
    if (type instanceof GenericArrayTypeImpl) return type;
    GenericArrayType g = (GenericArrayType) type;
    return new GenericArrayTypeImpl(g.getGenericComponentType());
  } else if (type instanceof WildcardType) {
    if (type instanceof WildcardTypeImpl) return type;
    WildcardType w = (WildcardType) type;
    return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds());
  } else {
    return type; // This type is unsupported!
  }
}
 
开发者ID:rogues-dev,项目名称:hoard,代码行数:26,代码来源:Types.java

示例11: canonicalize

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
/**
 * Returns a type that is functionally equal but not necessarily equal according to {@link
 * Object#equals(Object) Object.equals()}.
 */
public static Type canonicalize(Type type) {
    if (type instanceof Class) {
        Class<?> c = (Class<?>) type;
        return c.isArray() ? new GenericArrayTypeImpl(canonicalize(c.getComponentType())) : c;

    } else if (type instanceof ParameterizedType) {
        if (type instanceof ParameterizedTypeImpl) return type;
        ParameterizedType p = (ParameterizedType) type;
        return new ParameterizedTypeImpl(p.getOwnerType(),
                                                p.getRawType(), p.getActualTypeArguments());

    } else if (type instanceof GenericArrayType) {
        if (type instanceof GenericArrayTypeImpl) return type;
        GenericArrayType g = (GenericArrayType) type;
        return new GenericArrayTypeImpl(g.getGenericComponentType());

    } else if (type instanceof WildcardType) {
        if (type instanceof WildcardTypeImpl) return type;
        WildcardType w = (WildcardType) type;
        return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds());

    } else {
        return type; // This type is unsupported!
    }
}
 
开发者ID:pCloud,项目名称:pcloud-networking-java,代码行数:30,代码来源:Types.java

示例12: getRawType

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
static Class<?> getRawType(Type type) {
    if (type == null) throw new NullPointerException("type == null");

    if (type instanceof Class<?>) {
        // Type is a normal class.
        return (Class<?>) type;
    }
    if (type instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) type;

        // I'm not exactly sure why getRawType() returns Type instead of Class. Neal isn't either but
        // suspects some pathological case related to nested classes exists.
        Type rawType = parameterizedType.getRawType();
        if (!(rawType instanceof Class)) throw new IllegalArgumentException();
        return (Class<?>) rawType;
    }
    if (type instanceof GenericArrayType) {
        Type componentType = ((GenericArrayType) type).getGenericComponentType();
        return Array.newInstance(getRawType(componentType), 0).getClass();
    }
    if (type instanceof TypeVariable) {
        // We could use the variable's bounds, but that won't work if there are multiple. Having a raw
        // type that's more general than necessary is okay.
        return Object.class;
    }
    if (type instanceof WildcardType) {
        return getRawType(((WildcardType) type).getUpperBounds()[0]);
    }

    throw new IllegalArgumentException("Expected a Class, ParameterizedType, or "
            + "GenericArrayType, but <" + type + "> is of type " + type.getClass().getName());
}
 
开发者ID:SKT-ThingPlug,项目名称:thingplug-sdk-android,代码行数:33,代码来源:MQTTUtils.java

示例13: getRawType

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
public static Class<?> getRawType(Type type) {
  if (type instanceof Class<?>) {
    // type is a normal class.
    return (Class<?>) type;

  } else if (type instanceof ParameterizedType) {
    ParameterizedType parameterizedType = (ParameterizedType) type;

    // I'm not exactly sure why getRawType() returns Type instead of Class.
    // Neal isn't either but suspects some pathological case related
    // to nested classes exists.
    Type rawType = parameterizedType.getRawType();
    checkArgument(rawType instanceof Class);
    return (Class<?>) rawType;

  } else if (type instanceof GenericArrayType) {
    Type componentType = ((GenericArrayType)type).getGenericComponentType();
    return Array.newInstance(getRawType(componentType), 0).getClass();

  } else if (type instanceof TypeVariable) {
    // we could use the variable's bounds, but that won't work if there are multiple.
    // having a raw type that's more general than necessary is okay
    return Object.class;

  } else if (type instanceof WildcardType) {
    return getRawType(((WildcardType) type).getUpperBounds()[0]);

  } else {
    String className = type == null ? "null" : type.getClass().getName();
    throw new IllegalArgumentException("Expected a Class, ParameterizedType, or "
        + "GenericArrayType, but <" + type + "> is of type " + className);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:$Gson$Types.java

示例14: getRawType

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
private Class<?> getRawType(Type type) {
    if (type == null) throw new NullPointerException("type == null");

    if (type instanceof Class<?>) {
        // Type is a normal class.
        return (Class<?>) type;
    }
    if (type instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) type;

        // I'm not exactly sure why getRawType() returns Type instead of Class. Neal isn't either but
        // suspects some pathological case related to nested classes exists.
        Type rawType = parameterizedType.getRawType();
        if (!(rawType instanceof Class)) throw new IllegalArgumentException();
        return (Class<?>) rawType;
    }
    if (type instanceof GenericArrayType) {
        Type componentType = ((GenericArrayType) type).getGenericComponentType();
        return Array.newInstance(getRawType(componentType), 0).getClass();
    }
    if (type instanceof TypeVariable) {
        // We could use the variable's bounds, but that won't work if there are multiple. Having a raw
        // type that's more general than necessary is okay.
        return Object.class;
    }
    if (type instanceof WildcardType) {
        return getRawType(((WildcardType) type).getUpperBounds()[0]);
    }

    throw new IllegalArgumentException("Expected a Class, ParameterizedType, or "
            + "GenericArrayType, but <" + type + "> is of type " + type.getClass().getName());
}
 
开发者ID:TUBB,项目名称:AFRouter,代码行数:33,代码来源:Wrapper.java

示例15: gen

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
/**
 * 创建解析器
 *
 * @param cacheKey
 * @param type
 * @param annotations
 * @return
 */
private static Decoder gen(String cacheKey, Type type, Annotation[] annotations) {
    Decoder decoder = getDecoder(cacheKey);
    if (decoder != null) {
        return decoder;
    }

    type = ReflectKit.chooseImpl(type);

    Type[] typeArgs = new Type[0];
    Class clazz;
    if (type instanceof ParameterizedType) {
        ParameterizedType pType = (ParameterizedType) type;
        clazz = (Class) pType.getRawType();
        typeArgs = pType.getActualTypeArguments();
    } else {
        clazz = (Class) type;
    }
    decoder = NATIVE_DECODERS.get(clazz);//基本数据类型
    if (decoder != null) {
        return decoder;
    }
    decoder = registerDecoder.get(clazz); //自定义的解析器
    if (decoder == null) {
        decoder = ReflectionDecoderFactory.create(clazz, annotations, typeArgs);  //注解解析器
    }
    cacheDecoder(cacheKey, decoder);
    return decoder;
}
 
开发者ID:zdongcoding,项目名称:jsouplib,代码行数:37,代码来源:AnalysisDecoder.java


注:本文中的java.lang.reflect.ParameterizedType.getRawType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。