@Override public Map<String, Argument<?>> getTypeVariables() { return argument.getTypeVariables(); }
@Override public Map<String, Argument<?>> getTypeVariables() { return argument.getTypeVariables(); }
/** * @return Whether the argument has any type variables */ default boolean hasTypeVariables() { return !getTypeVariables().isEmpty(); }
@Override public boolean equalsType(Argument<?> o) { if (this == o) { return true; } if (o == null) { return false; } return Objects.equals(type, o.getType()) && Objects.equals(typeParameters, o.getTypeVariables()); }
/** * Returns the string representation of the argument type, including generics. * * @param simple If true, output the simple name of types * @return The type string representation */ default String getTypeString(boolean simple) { Class<T> type = getType(); StringBuilder returnType = new StringBuilder(simple ? type.getSimpleName() : type.getName()); Map<String, Argument<?>> generics = getTypeVariables(); if (!generics.isEmpty()) { returnType .append("<") .append(generics.values() .stream() .map(arg -> arg.getTypeString(simple)) .collect(Collectors.joining(", "))) .append(">"); } return returnType.toString(); }
@SuppressWarnings("unchecked") @Override public BindingResult<Observable> bind(ArgumentConversionContext<Observable> context, HttpRequest<?> source) { Collection<Argument<?>> typeVariables = context.getArgument().getTypeVariables().values(); BindingResult<Publisher> result = publisherBodyBinder.bind( ConversionContext.of(Argument.of(Publisher.class, (Argument[]) typeVariables.toArray(new Argument[0]))), source ); if (result.isPresentAndSatisfied()) { return () -> Optional.of(Observable.fromPublisher(result.get())); } return BindingResult.EMPTY; } }
@SuppressWarnings("unchecked") @Override public BindingResult<Single> bind(ArgumentConversionContext<Single> context, HttpRequest<?> source) { Collection<Argument<?>> typeVariables = context.getArgument().getTypeVariables().values(); BindingResult<Publisher> result = publisherBodyBinder.bind( ConversionContext.of(Argument.of(Publisher.class, (Argument[]) typeVariables.toArray(new Argument[0]))), source ); if (result.isPresentAndSatisfied()) { return () -> Optional.of(Single.fromPublisher(result.get())); } return BindingResult.EMPTY; } }
@Override public Map<String, Argument<?>> getTypeVariables() { if (genericReturnType != null) { return genericReturnType.getTypeVariables(); } return Collections.emptyMap(); } }
@Override public Map<String, Argument<?>> getTypeVariables() { if (genericReturnType != null) { return genericReturnType.getTypeVariables(); } return Collections.emptyMap(); } }
private Class resolveGenericType(Argument argument, Class argumentType) { Class genericType; if (argumentType.isArray()) { genericType = argumentType.getComponentType(); } else { Map<String, Argument<?>> genericTypes = argument.getTypeVariables(); if (genericTypes.size() == 1) { genericType = genericTypes.values().iterator().next().getType(); } else { genericType = null; } } return genericType; }
private Class resolveGenericType(Argument argument, Class argumentType) { Class genericType; if (argumentType.isArray()) { genericType = argumentType.getComponentType(); } else { Map<String, Argument<?>> genericTypes = argument.getTypeVariables(); if (genericTypes.size() == 1) { genericType = genericTypes.values().iterator().next().getType(); } else { genericType = null; } } return genericType; }
private JavaType[] toJavaTypeArray(TypeFactory typeFactory, Map<String, Argument<?>> typeVariables) { List<JavaType> javaTypes = new ArrayList<>(); for (Argument<?> argument : typeVariables.values()) { if (argument.hasTypeVariables()) { javaTypes.add(typeFactory.constructParametricType(argument.getType(), toJavaTypeArray(typeFactory, argument.getTypeVariables()))); } else { javaTypes.add(typeFactory.constructType(argument.getType())); } } return javaTypes.toArray(new JavaType[javaTypes.size()]); } }
private <T> JavaType constructJavaType(Argument<T> type) { Map<String, Argument<?>> typeVariables = type.getTypeVariables(); TypeFactory typeFactory = objectMapper.getTypeFactory(); JavaType[] objects = toJavaTypeArray(typeFactory, typeVariables); return typeFactory.constructParametricType( type.getType(), objects ); }
/** * Obtains all bean definitions for a constructor argument at the given index * <p> * Warning: this method is used by internal generated code and should not be called by user code. * * @param resolutionContext The resolution context * @param context The context * @param constructorInjectionPoint The constructor injection point * @param argument The argument * @return The resolved bean */ @SuppressWarnings("WeakerAccess") @Internal protected final Collection getBeansOfTypeForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, @SuppressWarnings("unused") ConstructorInjectionPoint<T> constructorInjectionPoint, Argument argument) { return resolveBeanWithGenericsFromConstructorArgument(resolutionContext, argument, (beanType, qualifier) -> { boolean hasNoGenerics = !argument.getType().isArray() && argument.getTypeVariables().isEmpty(); if (hasNoGenerics) { return ((DefaultBeanContext) context).getBean(resolutionContext, beanType, qualifier); } else { return ((DefaultBeanContext) context).getBeansOfType(resolutionContext, beanType, qualifier); } } ); }
/** * Obtains all bean definitions for the method at the given index and the argument at the given index * <p> * Warning: this method is used by internal generated code and should not be called by user code. * * @param resolutionContext The resolution context * @param context The context * @param injectionPoint The method injection point * @param argument The argument * @return The resolved bean */ @SuppressWarnings("WeakerAccess") @Internal protected final Collection getBeansOfTypeForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, MethodInjectionPoint injectionPoint, Argument argument) { return resolveBeanWithGenericsFromMethodArgument(resolutionContext, injectionPoint, argument, (beanType, qualifier) -> { boolean hasNoGenerics = !argument.getType().isArray() && argument.getTypeVariables().isEmpty(); if (hasNoGenerics) { return ((DefaultBeanContext) context).getBean(resolutionContext, beanType, qualifier); } else { return ((DefaultBeanContext) context).getBeansOfType(resolutionContext, beanType, qualifier); } } ); }
/** * Obtains all bean definitions for the method at the given index and the argument at the given index * <p> * Warning: this method is used by internal generated code and should not be called by user code. * * @param resolutionContext The resolution context * @param context The context * @param injectionPoint The method injection point * @param argument The argument * @return The resolved bean */ @SuppressWarnings("WeakerAccess") @Internal protected final Collection getBeansOfTypeForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, MethodInjectionPoint injectionPoint, Argument argument) { return resolveBeanWithGenericsFromMethodArgument(resolutionContext, injectionPoint, argument, (beanType, qualifier) -> { boolean hasNoGenerics = !argument.getType().isArray() && argument.getTypeVariables().isEmpty(); if (hasNoGenerics) { return ((DefaultBeanContext) context).getBean(resolutionContext, beanType, qualifier); } else { return ((DefaultBeanContext) context).getBeansOfType(resolutionContext, beanType, qualifier); } } ); }
/** * Obtains all bean definitions for a constructor argument at the given index * <p> * Warning: this method is used by internal generated code and should not be called by user code. * * @param resolutionContext The resolution context * @param context The context * @param constructorInjectionPoint The constructor injection point * @param argument The argument * @return The resolved bean */ @SuppressWarnings("WeakerAccess") @Internal protected final Collection getBeansOfTypeForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, @SuppressWarnings("unused") ConstructorInjectionPoint<T> constructorInjectionPoint, Argument argument) { return resolveBeanWithGenericsFromConstructorArgument(resolutionContext, argument, (beanType, qualifier) -> { boolean hasNoGenerics = !argument.getType().isArray() && argument.getTypeVariables().isEmpty(); if (hasNoGenerics) { return ((DefaultBeanContext) context).getBean(resolutionContext, beanType, qualifier); } else { return ((DefaultBeanContext) context).getBeansOfType(resolutionContext, beanType, qualifier); } } ); }
/** * Obtains a bean definition for the field at the given index and the argument at the given index * <p> * Warning: this method is used by internal generated code and should not be called by user code. * * @param resolutionContext The resolution context * @param context The context * @param injectionPoint The field injection point * @return The resolved bean */ @SuppressWarnings("WeakerAccess") @Internal protected final Collection getBeansOfTypeForField(BeanResolutionContext resolutionContext, BeanContext context, FieldInjectionPoint injectionPoint) { return resolveBeanWithGenericsForField(resolutionContext, injectionPoint, (beanType, qualifier) -> { boolean hasNoGenerics = !injectionPoint.getType().isArray() && injectionPoint.asArgument().getTypeVariables().isEmpty(); if (hasNoGenerics) { return ((DefaultBeanContext) context).getBean(resolutionContext, beanType, qualifier); } else { return ((DefaultBeanContext) context).getBeansOfType(resolutionContext, beanType, qualifier); } } ); }
/** * Obtains a bean definition for the field at the given index and the argument at the given index * <p> * Warning: this method is used by internal generated code and should not be called by user code. * * @param resolutionContext The resolution context * @param context The context * @param injectionPoint The field injection point * @return The resolved bean */ @SuppressWarnings("WeakerAccess") @Internal protected final Collection getBeansOfTypeForField(BeanResolutionContext resolutionContext, BeanContext context, FieldInjectionPoint injectionPoint) { return resolveBeanWithGenericsForField(resolutionContext, injectionPoint, (beanType, qualifier) -> { boolean hasNoGenerics = !injectionPoint.getType().isArray() && injectionPoint.asArgument().getTypeVariables().isEmpty(); if (hasNoGenerics) { return ((DefaultBeanContext) context).getBean(resolutionContext, beanType, qualifier); } else { return ((DefaultBeanContext) context).getBeansOfType(resolutionContext, beanType, qualifier); } } ); }