/** * Local helper method to unroll variables in a type bounds array. * * @param typeArguments assignments {@link Map} * @param bounds in which to expand variables * @return {@code bounds} with any variables reassigned */ private static Type[] unrollBounds(final Map<TypeVariable<?>, Type> typeArguments, final Type[] bounds) { Type[] result = bounds; int i = 0; for (; i < result.length; i++) { final Type unrolled = unrollVariables(typeArguments, result[i]); if (unrolled == null) { List<Type> types = Arrays.asList(result); types.remove(i--); result = types.toArray(new Type[types.size()]); } else { result[i] = unrolled; } } return result; }
/** * Local helper method to unroll variables in a type bounds array. * * @param typeArguments assignments {@link Map} * @param bounds in which to expand variables * @return {@code bounds} with any variables reassigned */ private static Type[] unrollBounds(final Map<TypeVariable<?>, Type> typeArguments, final Type[] bounds) { Type[] result = bounds; int i = 0; for (; i < result.length; i++) { final Type unrolled = unrollVariables(typeArguments, result[i]); if (unrolled == null) { List<Type> types = Arrays.asList(result); types.remove(i--); result = types.toArray(new Type[types.size()]); } else { result[i] = unrolled; } } return result; }
/** * Local helper method to unroll variables in a type bounds array. * * @param typeArguments assignments {@link Map} * @param bounds in which to expand variables * @return {@code bounds} with any variables reassigned */ private static Type[] unrollBounds(final Map<TypeVariable<?>, Type> typeArguments, final Type[] bounds) { Type[] result = bounds; int i = 0; for (; i < result.length; i++) { final Type unrolled = unrollVariables(typeArguments, result[i]); if (unrolled == null) { List<Type> types = Arrays.asList(result); types.remove(i--); result = types.toArray(new Type[types.size()]); } else { result[i] = unrolled; } } return result; }
/** * {@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; }
@Override public final Type getGenericType() { if (TypeUtils.containsTypeVariables(genericType)) { final Map<TypeVariable<?>, Type> args = TypeUtils.getTypeArguments(parent.getGenericType(), Object.class); return TypeUtils.unrollVariables(args, genericType); } return genericType; }
@Override public final Type getGenericType() { if (TypeUtils.containsTypeVariables(genericType)) { final Map<TypeVariable<?>, Type> args = TypeUtils.getTypeArguments(parent.getGenericType(), Object.class); return TypeUtils.unrollVariables(args, genericType); } return genericType; }
/** * Get the Java element type of a particular container type. * * @param containerType * @return Type or <code>null</code> if <code>containerType</code> is not * some kind of {@link Map} */ public static Type getJavaElementType(Type containerType) { if (TypeUtils.isAssignable(containerType, Map.class)) { Map<TypeVariable<?>, Type> typeArguments = TypeUtils.getTypeArguments(containerType, Map.class); return ObjectUtils.defaultIfNull(TypeUtils.unrollVariables(typeArguments, MAP_TYPEVARS[1]), Object.class); } return null; }
return unrollVariables(typeArguments, typeArguments.get(type)); final Type unrolled = unrollVariables(parameterizedTypeArguments, args[i]); if (unrolled != null) { args[i] = unrolled;
return unrollVariables(typeArguments, typeArguments.get(type)); final Type unrolled = unrollVariables(parameterizedTypeArguments, args[i]); if (unrolled != null) { args[i] = unrolled;
return unrollVariables(typeArguments, typeArguments.get(type)); final Type unrolled = unrollVariables(parameterizedTypeArguments, args[i]); if (unrolled != null) { args[i] = unrolled;
/** * Get the Java element type of a particular container type. * * @param containerType * @return Type or <code>null</code> if <code>containerType</code> is not * some type of {@link Iterable} or array */ public static Type getJavaElementType(Type containerType) { if (TypeUtils.isArrayType(containerType)) { return TypeUtils.getArrayComponentType(containerType); } if (TypeUtils.isAssignable(containerType, Iterable.class)) { Map<TypeVariable<?>, Type> typeArguments = TypeUtils.getTypeArguments(containerType, Iterable.class); Type type = TypeUtils.unrollVariables(typeArguments, ITERABLE_TYPE); return type != null ? type : Object.class; } return null; }