return getTypeArguments(type, toClass, null);
/** * <p> * Constructs a new {@code Diff} for the given field name. * </p> * * @param fieldName * the name of the field */ protected Diff(final String fieldName) { this.type = ObjectUtils.defaultIfNull( TypeUtils.getTypeArguments(getClass(), Diff.class).get( Diff.class.getTypeParameters()[0]), Object.class); this.fieldName = fieldName; }
/** * <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); }
/** * The default constructor. */ protected TypeLiteral() { this.value = Validate.notNull(TypeUtils.getTypeArguments(getClass(), TypeLiteral.class).get(T), "%s does not assign type parameter %s", getClass(), TypeUtils.toLongString(T)); this.toString = String.format("%s<%s>", TypeLiteral.class.getSimpleName(), TypeUtils.toString(value)); }
final Map<TypeVariable<?>, Type> subtypeVarAssigns) { if (type instanceof Class<?>) { return getTypeArguments((Class<?>) type, toClass, subtypeVarAssigns); return getTypeArguments((ParameterizedType) type, toClass, subtypeVarAssigns); return getTypeArguments(((GenericArrayType) type).getGenericComponentType(), toClass .isArray() ? toClass.getComponentType() : toClass, subtypeVarAssigns); return getTypeArguments(bound, toClass, subtypeVarAssigns); return getTypeArguments(bound, toClass, subtypeVarAssigns);
@Autowired public JacksonRequestStreamHandler(ObjectMapper mapper, RequestHandler<IN, OUT> innerHandler) { this.innerHandler = innerHandler; Map<TypeVariable<?>, Type> arguments = TypeUtils.getTypeArguments(innerHandler.getClass(), RequestHandler.class); Type inputType = arguments.get(PARAMETERS[0]); Type outputType = arguments.get(PARAMETERS[1]); this.reader = mapper.readerFor(mapper.constructType(inputType)); this.writer = mapper.writerFor(mapper.constructType(outputType)); }
typeVarAssigns = getTypeArguments(parameterizedOwnerType, getRawType(parameterizedOwnerType), subtypeVarAssigns); } else { return getTypeArguments(getClosestParentType(cls, toClass), toClass, typeVarAssigns);
return getTypeArguments(getClosestParentType(cls, toClass), toClass, typeVarAssigns);
final Map<TypeVariable<?>, Type> typeArguments = TypeUtils.getTypeArguments(declaringClass, m.getDeclaringClass()); for (int i = 0; i < parameterTypes.length; i++) { final Type childType = TypeUtils.unrollVariables(typeArguments, method.getGenericParameterTypes()[i]);
final Map<TypeVariable<?>, Type> fromTypeVarAssigns = getTypeArguments(type, toClass, null); final Map<TypeVariable<?>, Type> toTypeVarAssigns = getTypeArguments(toParameterizedType, toClass, typeVarAssigns);
final Map<TypeVariable<?>, Type> typeVarAssigns = getTypeArguments(assigningType, (Class<?>) genericDeclaration);
final GenericDeclaration genericDeclaration = tv.getGenericDeclaration(); if (null != clazz && genericDeclaration instanceof Class) { final Map<TypeVariable<?>, Type> typeArgs = TypeUtils.getTypeArguments(clazz, (Class) genericDeclaration); if (null != typeArgs) { final Type propType = typeArgs.get(tv);
} else { parameterizedTypeArguments = new HashMap<>(typeArguments); parameterizedTypeArguments.putAll(getTypeArguments(p));
return getTypeArguments(superType, superClass, null);
typeVarAssigns = TypeUtils.getTypeArguments(Integer.class, Comparable.class); treeSetTypeVar = Comparable.class.getTypeParameters()[0]; assertTrue("Type var assigns for Comparable from Integer: " + typeVarAssigns, typeVarAssigns = TypeUtils.getTypeArguments(int.class, Comparable.class); treeSetTypeVar = Comparable.class.getTypeParameters()[0]; assertTrue("Type var assigns for Comparable from int: " + typeVarAssigns, typeVarAssigns = TypeUtils.getTypeArguments(List.class, Collection.class); treeSetTypeVar = Comparable.class.getTypeParameters()[0]; assertFalse("Type var assigns for Collection from List: " + typeVarAssigns, typeVarAssigns.containsKey(treeSetTypeVar)); typeVarAssigns = TypeUtils.getTypeArguments(AAAClass.BBBClass.class, AAClass.BBClass.class); assertEquals(2, typeVarAssigns.size()); assertEquals(String.class, typeVarAssigns.get(AAClass.class.getTypeParameters()[0])); assertEquals(String.class, typeVarAssigns.get(AAClass.BBClass.class.getTypeParameters()[0])); typeVarAssigns = TypeUtils.getTypeArguments(Other.class, This.class); assertEquals(2, typeVarAssigns.size()); assertEquals(String.class, typeVarAssigns.get(This.class.getTypeParameters()[0])); assertEquals(Other.class.getTypeParameters()[0], typeVarAssigns.get(This.class.getTypeParameters()[1])); typeVarAssigns = TypeUtils.getTypeArguments(And.class, This.class); assertEquals(2, typeVarAssigns.size()); assertEquals(Number.class, typeVarAssigns.get(This.class.getTypeParameters()[0])); assertEquals(Number.class, typeVarAssigns.get(This.class.getTypeParameters()[1])); typeVarAssigns = TypeUtils.getTypeArguments(Thing.class, Other.class);
Map<TypeVariable<?>, Type> args = TypeUtils.getTypeArguments(t, Property.class); Type rt = args.get(Property.class.getTypeParameters()[0]); type = TypeUtils.getRawType(rt, Object.class);
@Inject public CommandBodyMapProvider(Set<CommandAction<?>> commandSet) { for( CommandAction<?> command : commandSet ) { Map<TypeVariable<?>,Type> genericMap = TypeUtils.getTypeArguments(command.getClass(), CommandAction.class); Type bodyType = genericMap.get(CommandAction.class.getTypeParameters()[0]); if( bodyType instanceof Class<?> ) bodyTypeMap.put(command.getName(), (Class<?>)bodyType); else { log.error("Could not identify message body type for command {}:{}.", command.getName(), command.getClass().getName()); } } }
/** * The default constructor. */ protected TypeLiteral() { this.value = Validate.notNull(TypeUtils.getTypeArguments(getClass(), TypeLiteral.class).get(T), "%s does not assign type parameter %s", getClass(), TypeUtils.toLongString(T)); this.toString = String.format("%s<%s>", TypeLiteral.class.getSimpleName(), TypeUtils.toString(value)); }
/** * The default constructor. */ protected TypeLiteral() { this.value = Validate.notNull(TypeUtils.getTypeArguments(getClass(), TypeLiteral.class).get(T), "%s does not assign type parameter %s", getClass(), TypeUtils.toLongString(T)); this.toString = String.format("%s<%s>", TypeLiteral.class.getSimpleName(), TypeUtils.toString(value)); }
/** * The default constructor. */ protected TypeLiteral() { this.value = Validate.notNull(TypeUtils.getTypeArguments(getClass(), TypeLiteral.class).get(T), "%s does not assign type parameter %s", getClass(), TypeUtils.toLongString(T)); this.toString = String.format("%s<%s>", TypeLiteral.class.getSimpleName(), TypeUtils.toString(value)); }