/** * <p>Retrieves all the type arguments for this parameterized type * including owner hierarchy arguments such as * {@code Outer<K,V>.Inner<T>.DeepInner<E>} . * The arguments are returned in a * {@link Map} specifying the argument type for each {@link TypeVariable}. * </p> * * @param type specifies the subject parameterized type from which to * harvest the parameters. * @return a {@code Map} of the type arguments to their respective type * variables. */ public static Map<TypeVariable<?>, Type> getTypeArguments(final ParameterizedType type) { return getTypeArguments(type, getRawType(type), null); }
return getRawType((ParameterizedType) type); return getRawType(typeArgument, assigningType); final Class<?> rawComponentType = getRawType(((GenericArrayType) type) .getGenericComponentType(), assigningType);
final TypeVariable<?>[] typeVars = getRawType(parameterizedType).getTypeParameters();
midClass = getRawType((ParameterizedType) midType); } else if (midType instanceof Class<?>) { midClass = (Class<?>) midType;
final ParameterizedType parameterizedType, final Class<?> toClass, final Map<TypeVariable<?>, Type> subtypeVarAssigns) { final Class<?> cls = getRawType(parameterizedType); getRawType(parameterizedOwnerType), subtypeVarAssigns); } else {
return isAssignable(getRawType((ParameterizedType) type), toClass);
Validate.notNull(superType, "superType is null"); final Class<?> superClass = getRawType(superType); final Class<?> midClass = getRawType(midParameterizedType);
@Test public void testGetRawType() throws SecurityException, NoSuchFieldException { final Type stringParentFieldType = GenericTypeHolder.class.getDeclaredField("stringParent") .getGenericType(); final Type integerParentFieldType = GenericTypeHolder.class.getDeclaredField("integerParent") .getGenericType(); final Type foosFieldType = GenericTypeHolder.class.getDeclaredField("foos").getGenericType(); final Type genericParentT = GenericParent.class.getTypeParameters()[0]; assertEquals(GenericParent.class, TypeUtils.getRawType(stringParentFieldType, null)); assertEquals(GenericParent.class, TypeUtils.getRawType(integerParentFieldType, null)); assertEquals(List.class, TypeUtils.getRawType(foosFieldType, null)); assertEquals(String.class, TypeUtils.getRawType(genericParentT, StringParameterizedChild.class)); assertEquals(String.class, TypeUtils.getRawType(genericParentT, stringParentFieldType)); assertEquals(Foo.class, TypeUtils.getRawType(Iterable.class.getTypeParameters()[0], foosFieldType)); assertEquals(Foo.class, TypeUtils.getRawType(List.class.getTypeParameters()[0], foosFieldType)); assertNull(TypeUtils.getRawType(genericParentT, GenericParent.class)); assertEquals(GenericParent[].class, TypeUtils.getRawType(GenericTypeHolder.class .getDeclaredField("barParents").getGenericType(), null)); }
final Class<?> toClass = getRawType(toParameterizedType);
@Override public boolean shouldIgnoreType(Type type, Set<Type> typesToSkip) { Class<?> clazz = TypeUtils.getRawType(type, type); if (clazz == null) { return false; } String clazzName = clazz.getName(); switch (clazzName) { case "javax.servlet.ServletRequest": case "javax.servlet.ServletResponse": case "javax.servlet.http.HttpSession": case "javax.servlet.http.PushBuilder": case "java.security.Principal": case "java.io.OutputStream": case "java.io.Writer": return true; default: } return clazzName.startsWith("org.springframework") && !"org.springframework.web.multipart.MultipartFile".equals(clazzName); } }
private boolean isRequestParamType(Type type, Map<Class<?>, Annotation> annotations) { RequestParam requestParam = (RequestParam) annotations.get(RequestParam.class); return requestParam != null || (BeanUtils.isSimpleProperty(TypeUtils.getRawType(type, type)) && !hasClassStartingWith(annotations.keySet(), "org.springframework.web.bind.annotation")); }
@Override public List<Parameter> extractParameters(List<Annotation> annotations, Type type, Set<Type> typesToSkip, Iterator<SwaggerExtension> chain) { Class<?> cls = TypeUtils.getRawType(type, type); if (shouldIgnoreClass(cls) || typesToSkip.contains(type)) { // stop the processing chain typesToSkip.add(type); return Lists.newArrayList(); } for (Annotation annotation : annotations) { if (annotation instanceof BeanParam || annotation instanceof InjectParam) { return reader.extractTypes(cls, typesToSkip, Lists.newArrayList()); } } return super.extractParameters(annotations, type, typesToSkip, chain); }
protected List<Parameter> getParameters(Type type, List<Annotation> annotations, Set<Type> typesToSkip) { if (!hasValidAnnotations(annotations) || isApiParamHidden(annotations)) { return Collections.emptyList(); } Iterator<SwaggerExtension> chain = SwaggerExtensions.chain(); List<Parameter> parameters = new ArrayList<>(); Class<?> cls = TypeUtils.getRawType(type, type); LOG.debug("Looking for path/query/header/form/cookie params in " + cls); if (chain.hasNext()) { SwaggerExtension extension = chain.next(); LOG.debug("trying extension " + extension); parameters = extension.extractParameters(annotations, type, typesToSkip, chain); } if (!parameters.isEmpty()) { for (Parameter parameter : parameters) { ParameterProcessor.applyAnnotations(swagger, parameter, type, annotations); } } else { LOG.debug("Looking for body params in " + cls); // parameters is guaranteed to be empty at this point, replace it with a mutable collection parameters = Lists.newArrayList(); if (!typesToSkip.contains(type)) { Parameter param = ParameterProcessor.applyAnnotations(swagger, null, type, annotations); if (param != null) { parameters.add(param); } } } return parameters; }
private List<Parameter> extractParametersFromModelAttributeAnnotation(Type type, Map<Class<?>, Annotation> annotations) { ModelAttribute modelAttribute = (ModelAttribute)annotations.get(ModelAttribute.class); if ((modelAttribute == null || !hasClassStartingWith(annotations.keySet(), "org.springframework.web.bind.annotation"))&& BeanUtils.isSimpleProperty(TypeUtils.getRawType(type, null))) { return Collections.emptyList(); Class<?> clazz = TypeUtils.getRawType(type, type); for (PropertyDescriptor propertyDescriptor : BeanUtils.getPropertyDescriptors(clazz)) {
Map<TypeVariable<?>, Type> args = TypeUtils.getTypeArguments(t, Property.class); Type rt = args.get(Property.class.getTypeParameters()[0]); type = TypeUtils.getRawType(rt, Object.class); set = (v) -> ((Property) prop.getProperty(lenskit)).set(v);
/** * Set the type of the expression processed thus far. * * @param type */ protected void setType(Type type) { this.rawType = TypeUtils.getRawType(type, this.type); this.type = type; }
protected Class<?> determineTargetType(Class<? extends ConstraintValidator<?, ?>> validatorClass) { TypeVariable<?> typeVar = ConstraintValidator.class.getTypeParameters()[1]; return TypeUtils.getRawType(typeVar, validatorClass); }
protected Class<?> determineTargetType(Class<? extends ConstraintValidator<?, ?>> validatorClass) { TypeVariable<?> typeVar = ConstraintValidator.class.getTypeParameters()[1]; return TypeUtils.getRawType(typeVar, validatorClass); }
/** * <p>Retrieves all the type arguments for this parameterized type * including owner hierarchy arguments such as * {@code Outer<K,V>.Inner<T>.DeepInner<E>} . * The arguments are returned in a * {@link Map} specifying the argument type for each {@link TypeVariable}. * </p> * * @param type specifies the subject parameterized type from which to * harvest the parameters. * @return a {@code Map} of the type arguments to their respective type * variables. */ public static Map<TypeVariable<?>, Type> getTypeArguments(final ParameterizedType type) { return getTypeArguments(type, getRawType(type), null); }
private Class<?> resolveTypeParameter() { Class<?> typeParameter = null; if (this.isCollectionType) { typeParameter = getRawType(getParameterTypeOf(this.genericFieldType), this.modelType); } else if (getType().isArray()) { typeParameter = getType().getComponentType(); } return typeParameter; }