public int getAssignabilityWeight(Class<?>[] paramTypes) { for (int i = 0; i < paramTypes.length; i++) { if (!ClassUtils.isAssignableValue(paramTypes[i], this.arguments[i])) { return Integer.MAX_VALUE; } } for (int i = 0; i < paramTypes.length; i++) { if (!ClassUtils.isAssignableValue(paramTypes[i], this.rawArguments[i])) { return Integer.MAX_VALUE - 512; } } return Integer.MAX_VALUE - 1024; }
@Override @Nullable public Object fromMessage(Message<?> message, Class<?> targetClass) { Object payload = message.getPayload(); return (ClassUtils.isAssignableValue(targetClass, payload) ? payload : null); }
public int getAssignabilityWeight(Class<?>[] paramTypes) { for (int i = 0; i < paramTypes.length; i++) { if (!ClassUtils.isAssignableValue(paramTypes[i], this.arguments[i])) { return Integer.MAX_VALUE; } } for (int i = 0; i < paramTypes.length; i++) { if (!ClassUtils.isAssignableValue(paramTypes[i], this.rawArguments[i])) { return Integer.MAX_VALUE - 512; } } return Integer.MAX_VALUE - 1024; }
/** * Returns {@code true} if the specified listener is one of the supported types. * @param listener the listener to test * @return if the listener is of a supported type */ public static boolean isSupportedType(EventListener listener) { for (Class<?> type : SUPPORTED_TYPES) { if (ClassUtils.isAssignableValue(type, listener)) { return true; } } return false; }
/** * Check if the supplied value is the first entry in the array represented by the possibleArray value. * @param value the value to check for in the array * @param possibleArray an array object that may have the supplied value as the first element * @return true if the supplied value is the first entry in the array */ private static boolean isFirstEntryInArray(Object value, @Nullable Object possibleArray) { if (possibleArray == null) { return false; } Class<?> type = possibleArray.getClass(); if (!type.isArray() || Array.getLength(possibleArray) == 0 || !ClassUtils.isAssignableValue(type.getComponentType(), value)) { return false; } Object arrayValue = Array.get(possibleArray, 0); return (type.getComponentType().isPrimitive() ? arrayValue.equals(value) : arrayValue == value); }
/** * Following AspectJ semantics, if a return value is null (or return type is void), * then the return type of target method should be used to determine whether advice * is invoked or not. Also, even if the return type is void, if the type of argument * declared in the advice method is Object, then the advice must still get invoked. * @param type the type of argument declared in advice method * @param method the advice method * @param returnValue the return value of the target method * @return whether to invoke the advice method for the given return value and type */ private boolean matchesReturnValue(Class<?> type, Method method, @Nullable Object returnValue) { if (returnValue != null) { return ClassUtils.isAssignableValue(type, returnValue); } else if (Object.class == type && void.class == method.getReturnType()) { return true; } else { return ClassUtils.isAssignable(type, method.getReturnType()); } }
/** * Delegate to the {@link WebArgumentResolver} instance. * @throws IllegalStateException if the resolved value is not assignable * to the method parameter. */ @Override @Nullable public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { Class<?> paramType = parameter.getParameterType(); Object result = this.adaptee.resolveArgument(parameter, webRequest); if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) { throw new IllegalStateException( "Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() + "resolved to incompatible value of type [" + (result != null ? result.getClass() : null) + "]. Consider declaring the argument type in a less specific fashion."); } return result; }
private void assertNotBuilder(Object toCheck, String name) { Assert.isTrue(!ClassUtils.isAssignableValue(ConditionalExpressionBuilder.class, toCheck), String.format("%s must not be of type %s", name, ConditionalExpressionBuilder.class.getSimpleName())); }
@Override @Nullable public Object fromMessage(Message<?> message, Class<?> targetClass) { Object payload = message.getPayload(); if (this.conversionService.canConvert(payload.getClass(), targetClass)) { try { return this.conversionService.convert(payload, targetClass); } catch (ConversionException ex) { throw new MessageConversionException(message, "Failed to convert message payload '" + payload + "' to '" + targetClass.getName() + "'", ex); } } return (ClassUtils.isAssignableValue(targetClass, payload) ? payload : null); }
/** * Actually resolve the value and check the resolved value is not * {@link WebArgumentResolver#UNRESOLVED} absorbing _any_ exceptions. */ @Override public boolean supportsParameter(MethodParameter parameter) { try { NativeWebRequest webRequest = getWebRequest(); Object result = this.adaptee.resolveArgument(parameter, webRequest); if (result == WebArgumentResolver.UNRESOLVED) { return false; } else { return ClassUtils.isAssignableValue(parameter.getParameterType(), result); } } catch (Exception ex) { // ignore (see class-level doc) logger.debug("Error in checking support for parameter [" + parameter + "], message: " + ex.getMessage()); return false; } }
int result = 0; for (int i = 0; i < paramTypes.length; i++) { if (!ClassUtils.isAssignableValue(paramTypes[i], args[i])) { return Integer.MAX_VALUE;
/** * Convert the given value to the specified target type, if necessary. * @param value the original property value * @param targetType the specified target type for property retrieval * @return the converted value, or the original value if no conversion * is necessary * @since 4.3.5 */ @SuppressWarnings("unchecked") @Nullable protected <T> T convertValueIfNecessary(Object value, @Nullable Class<T> targetType) { if (targetType == null) { return (T) value; } ConversionService conversionServiceToUse = this.conversionService; if (conversionServiceToUse == null) { // Avoid initialization of shared DefaultConversionService if // no standard type conversion is needed in the first place... if (ClassUtils.isAssignableValue(targetType, value)) { return (T) value; } conversionServiceToUse = DefaultConversionService.getSharedInstance(); } return conversionServiceToUse.convert(value, targetType); }
/** * Delegate to the {@link WebArgumentResolver} instance. * @throws IllegalStateException if the resolved value is not assignable * to the method parameter. */ @Override @Nullable public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { Class<?> paramType = parameter.getParameterType(); Object result = this.adaptee.resolveArgument(parameter, webRequest); if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) { throw new IllegalStateException( "Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() + "resolved to incompatible value of type [" + (result != null ? result.getClass() : null) + "]. Consider declaring the argument type in a less specific fashion."); } return result; }
/** * Actually resolve the value and check the resolved value is not * {@link WebArgumentResolver#UNRESOLVED} absorbing _any_ exceptions. */ @Override public boolean supportsParameter(MethodParameter parameter) { try { NativeWebRequest webRequest = getWebRequest(); Object result = this.adaptee.resolveArgument(parameter, webRequest); if (result == WebArgumentResolver.UNRESOLVED) { return false; } else { return ClassUtils.isAssignableValue(parameter.getParameterType(), result); } } catch (Exception ex) { // ignore (see class-level doc) logger.debug("Error in checking support for parameter [" + parameter + "], message: " + ex.getMessage()); return false; } }
/** * Determines if there is a type converter available in the specified context and * attempts to use it to convert the supplied value to the specified type. Throws an * exception if conversion is not possible. * @param context the evaluation context that may define a type converter * @param typedValue the value to convert and a type descriptor describing it * @param targetType the type to attempt conversion to * @return the converted value * @throws EvaluationException if there is a problem during conversion or conversion * of the value to the specified type is not supported */ @SuppressWarnings("unchecked") @Nullable public static <T> T convertTypedValue( @Nullable EvaluationContext context, TypedValue typedValue, @Nullable Class<T> targetType) { Object value = typedValue.getValue(); if (targetType == null) { return (T) value; } if (context != null) { return (T) context.getTypeConverter().convertValue( value, typedValue.getTypeDescriptor(), TypeDescriptor.valueOf(targetType)); } if (ClassUtils.isAssignableValue(targetType, value)) { return (T) value; } throw new EvaluationException("Cannot convert value '" + value + "' to type '" + targetType.getName() + "'"); }
if (!ClassUtils.isAssignableValue(beanMethod.getReturnType(), beanInstance)) {
!ClassUtils.isAssignableValue(requiredType, valueHolder.getValue())) { continue;
return null; if (ClassUtils.isAssignableValue(targetClass, result)) { return result;
@Override @Nullable public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { NamedValueInfo namedValueInfo = getNamedValueInfo(parameter); MethodParameter nestedParameter = parameter.nestedIfOptional(); Object resolvedName = resolveStringValue(namedValueInfo.name); if (resolvedName == null) { throw new IllegalArgumentException( "Specified name must not resolve to null: [" + namedValueInfo.name + "]"); } Object arg = resolveArgumentInternal(nestedParameter, message, resolvedName.toString()); if (arg == null) { if (namedValueInfo.defaultValue != null) { arg = resolveStringValue(namedValueInfo.defaultValue); } else if (namedValueInfo.required && !nestedParameter.isOptional()) { handleMissingValue(namedValueInfo.name, nestedParameter, message); } arg = handleNullValue(namedValueInfo.name, arg, nestedParameter.getNestedParameterType()); } else if ("".equals(arg) && namedValueInfo.defaultValue != null) { arg = resolveStringValue(namedValueInfo.defaultValue); } if (parameter != nestedParameter || !ClassUtils.isAssignableValue(parameter.getParameterType(), arg)) { arg = this.conversionService.convert(arg, TypeDescriptor.forObject(arg), new TypeDescriptor(parameter)); } handleResolvedValue(arg, namedValueInfo.name, parameter, message); return arg; }
@Override @SuppressWarnings("unchecked") public <T> T getPropertyValue(RedisPersistentProperty property) { Object value = readProperty(path, source, property); if (value == null || ClassUtils.isAssignableValue(property.getType(), value)) { return (T) value; } return (T) conversionService.convert(value, property.getType()); } }