/** * <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); }
/** * <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); }
/** * <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 static Class<?> getValidatedType(Class<? extends ConstraintValidator<?, ?>> validatorType) { final Type result = TypeUtils.getTypeArguments(validatorType, ConstraintValidator.class) .get(ConstraintValidator.class.getTypeParameters()[1]); if (!isSupported(result)) { Exceptions.raise(ConstraintDefinitionException::new, "Validated type %s declared by %s %s is unsupported", result, CV, validatorType.getName()); } return TypeUtils.getRawType(result, null); }
private static Class<?> getValidatedType(Class<? extends ConstraintValidator<?, ?>> validatorType) { final Type result = TypeUtils.getTypeArguments(validatorType, ConstraintValidator.class) .get(ConstraintValidator.class.getTypeParameters()[1]); if (!isSupported(result)) { Exceptions.raise(ConstraintDefinitionException::new, "Validated type %s declared by %s %s is unsupported", result, CV, validatorType.getName()); } return TypeUtils.getRawType(result, null); }
@Override public ElementD<?, ?> element() { final Class<?> beanClass = TypeUtils.getRawType(type, null); return beanClass == null ? null : (BeanD<?>) validatorContext.getDescriptorManager().getBeanDescriptor(beanClass); } }
@Override public Class<?> getElementClass() { return TypeUtils.getRawType(getGenericType(), parent.getElementClass()); }
@Override public ElementD<?, ?> element() { final Class<?> beanClass = TypeUtils.getRawType(type, null); return beanClass == null ? null : (BeanD<?>) validatorContext.getDescriptorManager().getBeanDescriptor(beanClass); } }
@Override public Class<?> getElementClass() { return TypeUtils.getRawType(getGenericType(), parent.getElementClass()); }
/** * {@inheritDoc} */ @Override public Object get(Object instance) { if (instance instanceof Map<?, ?>) { Map<?, ?> map = (Map<?, ?>) instance; Map<TypeVariable<?>, Type> typeArguments = TypeUtils.getTypeArguments(containerType, Map.class); Type keyType = TypeUtils.unrollVariables(typeArguments, MAP_TYPEVARS[0]); if (key == null || keyType == null || TypeUtils.isInstance(key, keyType)) { return map.get(key); } if (key instanceof String) { String name = (String) key; Class<?> rawKeyType = TypeUtils.getRawType(keyType, containerType); if (rawKeyType.isEnum()) { @SuppressWarnings({ "unchecked", "rawtypes" }) final Object result = map.get(Enum.valueOf((Class<? extends Enum>) rawKeyType, name)); return result; } for (Map.Entry<?, ?> e : map.entrySet()) { if (name.equals(e.getKey())) { return e.getValue(); } } } } return null; }
midClass = getRawType((ParameterizedType) midType); } else if (midType instanceof Class<?>) { midClass = (Class<?>) midType;
midClass = getRawType((ParameterizedType) midType); } else if (midType instanceof Class<?>) { midClass = (Class<?>) midType;
midClass = getRawType((ParameterizedType) midType); } else if (midType instanceof Class<?>) { midClass = (Class<?>) midType;
public ContainerElementKey(AnnotatedType containerType, Integer typeArgumentIndex) { super(); Validate.notNull(containerType, "containerType"); this.containerClass = TypeUtils.getRawType(containerType.getType(), null); this.typeArgumentIndex = validTypeArgumentIndex(typeArgumentIndex, containerClass); this.annotatedType = typeArgumentIndex == null ? containerType : ((AnnotatedParameterizedType) containerType) .getAnnotatedActualTypeArguments()[typeArgumentIndex.intValue()]; }
public ContainerElementKey(AnnotatedType containerType, Integer typeArgumentIndex) { super(); Validate.notNull(containerType, "containerType"); this.containerClass = TypeUtils.getRawType(containerType.getType(), null); this.typeArgumentIndex = validTypeArgumentIndex(typeArgumentIndex, containerClass); this.annotatedType = typeArgumentIndex == null ? containerType : ((AnnotatedParameterizedType) containerType) .getAnnotatedActualTypeArguments()[typeArgumentIndex.intValue()]; }
private Class<?> resolveType() { final Class<?> declaringClass = getTarget().getDeclaringExecutable().getDeclaringClass(); Type t = getTarget().getParameterizedType(); int arrayDepth = 0; while (t instanceof GenericArrayType) { arrayDepth++; t = ((GenericArrayType) t).getGenericComponentType(); } Class<?> result = null; while (result == null) { result = TypeUtils.getRawType(t, declaringClass); if (result != null) { break; } if (t instanceof TypeVariable<?>) { final TypeVariable<?> tv = (TypeVariable<?>) t; t = tv.getBounds()[0]; } } return arrayDepth > 0 ? Array.newInstance(result, new int[arrayDepth]).getClass() : result; } }
private Class<?> resolveType() { final Class<?> declaringClass = getTarget().getDeclaringExecutable().getDeclaringClass(); Type t = getTarget().getParameterizedType(); int arrayDepth = 0; while (t instanceof GenericArrayType) { arrayDepth++; t = ((GenericArrayType) t).getGenericComponentType(); } Class<?> result = null; while (result == null) { result = TypeUtils.getRawType(t, declaringClass); if (result != null) { break; } if (t instanceof TypeVariable<?>) { final TypeVariable<?> tv = (TypeVariable<?>) t; t = tv.getBounds()[0]; } } return arrayDepth > 0 ? Array.newInstance(result, new int[arrayDepth]).getClass() : result; } }
/** * Resolve the type of this property to a class. * @return Class, <code>null</code> if cannot be determined */ public Class<?> getTypeClass() { Type targetType = type instanceof DynaType ? ((DynaType) type).getRawType() : type; if (targetType == null) { return null; } Type assigningType = getParentMetaBean() == null ? null : getParentMetaBean().getBeanClass(); return TypeUtils.getRawType(targetType, assigningType); }
private Set<ContainerElementKey> containerElements(Meta<?> meta, List<ContainerElementTypeType> containerElementTypes) { if (containerElementTypes.isEmpty()) { return Collections.emptySet(); } final Class<?> containerType = TypeUtils.getRawType(meta.getType(), null); final int typeParameterCount = containerType.getTypeParameters().length; if (typeParameterCount == 0) { Exceptions.raise(ValidationException::new, "Cannot specify container element types for %s", meta.describeHost()); } return containerElementTypes.stream().map(e -> { Integer typeArgumentIndex = e.getTypeArgumentIndex(); if (typeArgumentIndex == null) { if (typeParameterCount > 1) { Exceptions.raise(ValidationException::new, "Unable to resolve unspecified type argument index for %s", meta.describeHost()); } typeArgumentIndex = Integer.valueOf(0); } final ContainerElementKey result = new ContainerElementKey(containerType, typeArgumentIndex); final Meta.ForContainerElement elementMeta = new Meta.ForContainerElement(meta, result); constraints(elementMeta, e.getConstraint()); containerElements(elementMeta, e.getContainerElementType()); return result; }).collect(Collectors.toMap(Function.identity(), ContainerElementKey::getTypeArgumentIndex, enforceUniqueness( "Duplicate XML constrained container element %d of " + meta.describeHost(), Function.identity()))).keySet(); }
private Set<ContainerElementKey> containerElements(Meta<?> meta, List<ContainerElementTypeType> containerElementTypes) { if (containerElementTypes.isEmpty()) { return Collections.emptySet(); } final Class<?> containerType = TypeUtils.getRawType(meta.getType(), null); final int typeParameterCount = containerType.getTypeParameters().length; if (typeParameterCount == 0) { Exceptions.raise(ValidationException::new, "Cannot specify container element types for %s", meta.describeHost()); } return containerElementTypes.stream().map(e -> { Integer typeArgumentIndex = e.getTypeArgumentIndex(); if (typeArgumentIndex == null) { if (typeParameterCount > 1) { Exceptions.raise(ValidationException::new, "Unable to resolve unspecified type argument index for %s", meta.describeHost()); } typeArgumentIndex = Integer.valueOf(0); } final ContainerElementKey result = new ContainerElementKey(containerType, typeArgumentIndex); final Meta.ForContainerElement elementMeta = new Meta.ForContainerElement(meta, result); constraints(elementMeta, e.getConstraint()); containerElements(elementMeta, e.getContainerElementType()); return result; }).collect(Collectors.toMap(Function.identity(), ContainerElementKey::getTypeArgumentIndex, enforceUniqueness( "Duplicate XML constrained container element %d of " + meta.describeHost(), Function.identity()))).keySet(); }