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


Java GenericTypeReflector.erase方法代码示例

本文整理汇总了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;
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:17,代码来源:FieldUtils.java

示例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);
	}
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:28,代码来源:GenericAccessibleObject.java

示例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);
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:17,代码来源:GenericTypeInference.java

示例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);

}
 
开发者ID:salomonbrys-deprecated,项目名称:SourJSON,代码行数:27,代码来源:SourJson.java

示例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;
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:30,代码来源:FieldUtils.java

示例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;
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:14,代码来源:CastClassManager.java

示例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;
}
 
开发者ID:salomonbrys-deprecated,项目名称:SourJSON,代码行数:9,代码来源:CollectionTranslater.java

示例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);
	}
 
开发者ID:salomonbrys-deprecated,项目名称:SourJSON,代码行数:37,代码来源:TranslaterCache.java

示例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;
}
 
开发者ID:salomonbrys-deprecated,项目名称:SourJSON,代码行数:10,代码来源:MapTranslater.java

示例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);
}
 
开发者ID:stickfigure,项目名称:postguice,代码行数:6,代码来源:JSONUserType.java

示例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;
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:77,代码来源:TestCodeVisitor.java

示例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);
	}
 
开发者ID:salomonbrys-deprecated,项目名称:SourJSON,代码行数:18,代码来源:SourJson.java

示例13: EnumTranslater

import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public EnumTranslater(Type fromType) {
	typeName = GenericTypeReflector.getTypeName(fromType);
	enumClass = (Class<T>) GenericTypeReflector.erase(fromType);
}
 
开发者ID:salomonbrys-deprecated,项目名称:SourJSON,代码行数:5,代码来源:EnumTranslater.java

示例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;
}
 
开发者ID:salomonbrys-deprecated,项目名称:SourJSON,代码行数:7,代码来源:ArrayTranslater.java

示例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);
	}
}
 
开发者ID:salomonbrys-deprecated,项目名称:SourJSON,代码行数:45,代码来源:ObjectTranslater.java


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