本文整理汇总了Java中com.googlecode.gentyref.GenericTypeReflector.erase方法的典型用法代码示例。如果您正苦于以下问题:Java GenericTypeReflector.erase方法的具体用法?Java GenericTypeReflector.erase怎么用?Java GenericTypeReflector.erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.gentyref.GenericTypeReflector
的用法示例。
在下文中一共展示了GenericTypeReflector.erase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inferCollection
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
private static GenericType inferCollection(Type type) {
CollectionGenericType ret = new CollectionGenericType();
Type valueType = GenericTypeReflector.getTypeParameter(type, Collection.class.getTypeParameters()[0]);
ret.isInferred = valueType != null;
if (valueType == null) {
return ret;
}
ret.valueType = GenericTypeReflector.erase(valueType);
if (Map.class.isAssignableFrom(ret.valueType)) {
ret.nestedGenericValue = inferMap(valueType);
} else if (Collection.class.isAssignableFrom(ret.valueType)) {
ret.nestedGenericValue = inferCollection(valueType);
}
return ret;
}
示例2: mapTypeParameters
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
/**
* Maps type parameters in a type to their values.
*
* @param toMapType
* Type possibly containing type arguments
* @param typeAndParams
* must be either ParameterizedType, or (in case there are no
* type arguments, or it's a raw type) Class
* @return toMapType, but with type parameters from typeAndParams replaced.
*/
protected Type mapTypeParameters(Type toMapType, Type typeAndParams) {
if (isMissingTypeParameters(typeAndParams)) {
logger.debug("Is missing type parameters, so erasing types");
return GenericTypeReflector.erase(toMapType);
} else {
VarMap varMap = new VarMap();
Type handlingTypeAndParams = typeAndParams;
while (handlingTypeAndParams instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) handlingTypeAndParams;
Class<?> clazz = (Class<?>) pType.getRawType(); // getRawType should always be Class
varMap.addAll(clazz.getTypeParameters(), pType.getActualTypeArguments());
handlingTypeAndParams = pType.getOwnerType();
}
varMap.addAll(getTypeVariableMap());
return varMap.map(toMapType);
}
}
示例3: calculateExactType
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
private void calculateExactType(ParameterizedType type) {
logger.info("Calculating exact tyep for parameterized type " + type);
Class<?> rawClass = GenericTypeReflector.erase(type);
Type exactType = type;
for (VariableReference var : typeMap.get(type)) {
ParameterizedType currentType = (ParameterizedType) var.getType();
logger.info("Assigned variable of type: " + currentType);
Type candidateType = GenericTypeReflector.getExactSuperType(currentType,
rawClass);
logger.info("Resulting type: " + candidateType);
if (TypeUtils.isAssignable(candidateType, exactType)) {
exactType = candidateType;
}
}
logger.info("Result: " + exactType);
}
示例4: fromJSON
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public @CheckForNull <T> T fromJSON(@CheckForNull Object from, Type toType, double version, @CheckForNull AnnotatedElement toAnnos, @CheckForNull Object enclosing) throws SourJsonException {
if (from == null)
return null;
Class<?> toClass = GenericTypeReflector.erase(toType);
TypeAndAnnos info = new TypeAndAnnos(toType, toAnnos);
if (toClass.isPrimitive()) {
toClass = SJUtils.PRIMITIVES_TO_WRAPPERS.get(toClass);
toType = toClass;
}
if (from instanceof JSONObject && ((JSONObject)from).containsKey("!type")) {
String className = (String)((JSONObject)from).get("!type");
try {
info.type = Class.forName(className);
}
catch (ClassNotFoundException e) {
throw new SourJsonException("Could not find class " + className);
}
}
return (T)tcache.getTranslater(info, this).deserialize(from, enclosing, version, this);
}
示例5: inferMap
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
private static GenericType inferMap(Type type) {
MapGenericType ret = new MapGenericType();
Type keyType = GenericTypeReflector.getTypeParameter(type, Map.class.getTypeParameters()[0]);
Type valueType = GenericTypeReflector.getTypeParameter(type, Map.class.getTypeParameters()[1]);
ret.isInferred = keyType != null && valueType != null;
if (keyType == null || valueType == null) {
return ret;
}
ret.keyType = GenericTypeReflector.erase(keyType);
ret.valueType = GenericTypeReflector.erase(valueType);
if (!ret.isInferred) {
return ret;
}
if (Map.class.isAssignableFrom(ret.keyType)) {
ret.nestedGenericKey = inferMap(keyType);
} else if (Collection.class.isAssignableFrom(ret.keyType)) {
ret.nestedGenericKey = inferCollection(keyType);
}
if (Map.class.isAssignableFrom(ret.valueType)) {
ret.nestedGenericValue = inferMap(valueType);
} else if (Collection.class.isAssignableFrom(ret.valueType)) {
ret.nestedGenericValue = inferCollection(valueType);
}
return ret;
}
示例6: isSpecialCase
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
/**
* True if this type variable is one of the java.* special cases
*
* @return
*/
private boolean isSpecialCase(TypeVariable<?> typeVariable) {
for (Type bound : typeVariable.getBounds()) {
Class<?> clazz = GenericTypeReflector.erase(bound);
if (specialCases.contains(clazz))
return true;
}
return false;
}
示例7: CollectionTranslater
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public CollectionTranslater(TypeAndAnnos info) {
colType = GenericTypeReflector.erase(info.type);
colParamType = GenericTypeReflector.getTypeParameter(info.type, Collection.class.getTypeParameters()[0]);
if (colParamType == null)
colParamType = Object.class;
strictType = info.annos.isAnnotationPresent(StrictType.class);
el = info.annos;
}
示例8: makeSerializer
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
private static <T> InternalTranslater<T> makeSerializer(TypeAndAnnos info, SourJson sour) {
Class<T> fromClass = (Class<T>) GenericTypeReflector.erase(info.type);
SJTranslater<T> translater = sour.getTranslater(fromClass);
if (translater != null)
return new SJTranslaterTranslater<>(translater, info);
if ( JSONObject.class.isAssignableFrom(fromClass) || JSONArray.class.isAssignableFrom(fromClass)
|| Number.class.isAssignableFrom(fromClass) || Boolean.class.isAssignableFrom(fromClass)
|| JSONAware.class.isAssignableFrom(fromClass) || JSONStreamAware.class.isAssignableFrom(fromClass)
|| String.class.isAssignableFrom(fromClass) || fromClass.isPrimitive()
) {
return new SelfTranslater<>(fromClass);
}
if (Collection.class.isAssignableFrom(fromClass))
return new CollectionTranslater<>(info);
if (fromClass.isArray())
return new ArrayTranslater<>(info);
if (Map.class.isAssignableFrom(fromClass))
return new MapTranslater<>(info);
if (fromClass.isEnum())
return new EnumTranslater<>(info.type);
if (SJUtils.isSystem(fromClass))
return new StringTranslater<>(fromClass);
if (!sour.isClassKnown(fromClass))
throw new UnknownClassException(fromClass);
return new ObjectTranslater<>(info.type);
}
示例9: MapTranslater
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public MapTranslater(TypeAndAnnos info) {
mapClass = (Class<T>) GenericTypeReflector.erase(info.type);
mapKType = GenericTypeReflector.getTypeParameter(info.type, Map.class.getTypeParameters()[0]);
mapVType = GenericTypeReflector.getTypeParameter(info.type, Map.class.getTypeParameters()[1]);
if (mapVType == null)
mapVType = Object.class;
strictType = info.annos.isAnnotationPresent(StrictType.class);
el = info.annos;
}
示例10: JSONUserType
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public JSONUserType(final TypeReference<?> typeReference) {
//noinspection unchecked
this.classType = (Class<T>)GenericTypeReflector.erase(typeReference.getType());
this.javaType = MAPPER.getTypeFactory().constructType(typeReference);
}
示例11: getParameterString
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
private String getParameterString(Type[] parameterTypes,
List<VariableReference> parameters, boolean isGenericMethod,
boolean isOverloaded, int startPos) {
String parameterString = "";
for (int i = startPos; i < parameters.size(); i++) {
if (i > startPos) {
parameterString += ", ";
}
Type declaredParamType = parameterTypes[i];
Type actualParamType = parameters.get(i).getType();
String name = getVariableName(parameters.get(i));
Class<?> rawParamClass = declaredParamType instanceof WildcardType ? Object.class : GenericTypeReflector.erase(declaredParamType);
if (rawParamClass.isPrimitive() && name.equals("null")) {
parameterString += getPrimitiveNullCast(rawParamClass);
} else if (isGenericMethod && !(declaredParamType instanceof WildcardType )) {
if (!declaredParamType.equals(actualParamType) || name.equals("null")) {
parameterString += "(" + getTypeName(declaredParamType) + ") ";
if (name.contains("(short"))
name = name.replace("(short)", "");
if (name.contains("(byte"))
name = name.replace("(byte)", "");
}
} else if (name.equals("null")) {
parameterString += "(" + getTypeName(declaredParamType) + ") ";
} else if (!GenericClass.isAssignable(declaredParamType, actualParamType)) {
if (TypeUtils.isArrayType(declaredParamType)
&& TypeUtils.isArrayType(actualParamType)) {
Class<?> componentClass = GenericTypeReflector.erase(declaredParamType).getComponentType();
if (componentClass.equals(Object.class)) {
GenericClass genericComponentClass = new GenericClass(
componentClass);
if (genericComponentClass.hasWildcardOrTypeVariables()) {
// If we are assigning a generic array, then we don't need to cast
} else {
// If we are assigning a non-generic array, then we do need to cast
parameterString += "(" + getTypeName(declaredParamType)
+ ") ";
}
} else { //if (!GenericClass.isAssignable(GenericTypeReflector.getArrayComponentType(declaredParamType), GenericTypeReflector.getArrayComponentType(actualParamType))) {
parameterString += "(" + getTypeName(declaredParamType) + ") ";
}
} else if (!(actualParamType instanceof ParameterizedType)) {
parameterString += "(" + getTypeName(declaredParamType) + ") ";
}
if (name.contains("(short"))
name = name.replace("(short)", "");
if (name.contains("(byte"))
name = name.replace("(byte)", "");
//}
} else {
// We have to cast between wrappers and primitives in case there
// are overloaded signatures. This could be optimized by checking
// if there actually is a problem of overloaded signatures
GenericClass parameterClass = new GenericClass(declaredParamType);
if (parameterClass.isWrapperType() && parameters.get(i).isPrimitive()) {
parameterString += "(" + getTypeName(declaredParamType) + ") ";
} else if (parameterClass.isPrimitive()
&& parameters.get(i).isWrapperType()) {
parameterString += "(" + getTypeName(declaredParamType) + ") ";
} else if (isOverloaded) {
// If there is an overloaded method, we need to cast to make sure we use the right version
if (!declaredParamType.equals(actualParamType)) {
parameterString += "(" + getTypeName(declaredParamType) + ") ";
}
}
}
parameterString += name;
}
return parameterString;
}
示例12: toJSON
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public @CheckForNull Object toJSON(@CheckForNull Object from, Type fromType, double version, @CheckForNull AnnotatedElement fromAnnos, @CheckForNull Object enclosing) throws SourJsonException {
if (from == null)
return null;
Class<?> fromClass = GenericTypeReflector.erase(fromType);
if (Void.class.isAssignableFrom(fromClass))
return null;
if (!fromClass.isAssignableFrom(from.getClass()))
throw new SourJsonException(from.toString() + " is not an instance of " + fromType);
TypeAndAnnos info = new TypeAndAnnos(fromType, fromAnnos);
return tcache.getTranslater(info, this).serialize(from, enclosing, version, this);
}
示例13: EnumTranslater
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public EnumTranslater(Type fromType) {
typeName = GenericTypeReflector.getTypeName(fromType);
enumClass = (Class<T>) GenericTypeReflector.erase(fromType);
}
示例14: ArrayTranslater
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public ArrayTranslater(TypeAndAnnos info) {
arrayComponentType = GenericTypeReflector.getArrayComponentType(info.type);
arrayComponentClass = (Class<T[]>) GenericTypeReflector.erase(arrayComponentType);
strictType = info.annos.isAnnotationPresent(StrictType.class);
el = info.annos;
}
示例15: ObjectTranslater
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public ObjectTranslater(Type fromType) {
fromClass = (Class<T>) GenericTypeReflector.erase(fromType);
typeName = GenericTypeReflector.getTypeName(fromType);
Type t = fromType;
while (t != null) {
Class<?> cls = GenericTypeReflector.erase(t);
for (Field field : cls.getDeclaredFields()) {
if (!SJUtils.IsJSONPrintable(field))
continue ;
FieldCache fc = new FieldCache();
fc.name = SJUtils.getFieldName(field);
Until until = field.getAnnotation(Until.class);
if (until != null)
fc.until = until.value();
Since since = field.getAnnotation(Since.class);
if (since != null)
fc.since = since.value();
fc.type = GenericTypeReflector.getExactFieldType(field, fromType);
Class<?> fieldClass = GenericTypeReflector.erase(fc.type);
if (fieldClass.isPrimitive()) {
fieldClass = SJUtils.PRIMITIVES_TO_WRAPPERS.get(fieldClass);
fc.type = fieldClass;
}
fc.strictType = field.isAnnotationPresent(StrictType.class) || Map.class.isAssignableFrom(fieldClass) || Collection.class.isAssignableFrom(fieldClass);
fc.checkForNull = field.isAnnotationPresent(SCheckForNull.class);
fc.field = field;
fields.add(fc);
}
t = SJUtils.getParent(cls);
}
}