@Override public boolean isAssignableFrom(Class<?> other) { return (clazz == null || ClassUtils.isAssignable(clazz, other)); } @Override
/** * 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()); } }
@Override public boolean isAssignableFrom(Class<?> other) { return (clazz == null || ClassUtils.isAssignable(clazz, other)); } @Override
superClass = null; else if (ClassUtils.isAssignable(paramType, superClass)) { result = result + 2; superClass = superClass.getSuperclass();
/** * Determine if the given type is assignable from the given value, * assuming setting by reflection. Considers primitive wrapper classes * as assignable to the corresponding primitive types. * @param type the target type * @param value the value that should be assigned to the type * @return if the type is assignable from the value */ public static boolean isAssignableValue(Class<?> type, @Nullable Object value) { Assert.notNull(type, "Type must not be null"); return (value != null ? isAssignable(type, value.getClass()) : !type.isPrimitive()); }
private static boolean isApplicable(Member member, Class<?> sourceClass) { if (member instanceof Method) { Method method = (Method) member; return (!Modifier.isStatic(method.getModifiers()) ? ClassUtils.isAssignable(method.getDeclaringClass(), sourceClass) : method.getParameterTypes()[0] == sourceClass); } else if (member instanceof Constructor) { Constructor<?> ctor = (Constructor<?>) member; return (ctor.getParameterTypes()[0] == sourceClass); } else { return false; } }
@Nullable private PropertyEditor getPropertyEditor(@Nullable Class<?> requiredType) { // Special case: If no required type specified, which usually only happens for // Collection elements, or required type is not assignable to registered type, // which usually only happens for generic properties of type Object - // then return PropertyEditor if not registered for Collection or array type. // (If not registered for Collection or array, it is assumed to be intended // for elements.) if (this.registeredType == null || (requiredType != null && (ClassUtils.isAssignable(this.registeredType, requiredType) || ClassUtils.isAssignable(requiredType, this.registeredType))) || (requiredType == null && (!Collection.class.isAssignableFrom(this.registeredType) && !this.registeredType.isArray()))) { return this.propertyEditor; } else { return null; } } }
@Nullable private static Method determineToMethod(Class<?> targetClass, Class<?> sourceClass) { if (String.class == targetClass || String.class == sourceClass) { // Do not accept a toString() method or any to methods on String itself return null; } Method method = ClassUtils.getMethodIfAvailable(sourceClass, "to" + targetClass.getSimpleName()); return (method != null && !Modifier.isStatic(method.getModifiers()) && ClassUtils.isAssignable(targetClass, method.getReturnType()) ? method : null); }
@Override public boolean isAssignableFrom(ResolvableType other) { Class<?> otherClass = other.getRawClass(); return (otherClass != null && (clazz == null || ClassUtils.isAssignable(clazz, otherClass))); } };
/** * Determine if the given type is assignable from the given value, * assuming setting by reflection. Considers primitive wrapper classes * as assignable to the corresponding primitive types. * @param type the target type * @param value the value that should be assigned to the type * @return if the type is assignable from the value */ public static boolean isAssignableValue(Class<?> type, @Nullable Object value) { Assert.notNull(type, "Type must not be null"); return (value != null ? isAssignable(type, value.getClass()) : !type.isPrimitive()); }
@Override public boolean test(Class<?> controllerType) { if (!hasSelectors()) { return true; } else if (controllerType != null) { for (String basePackage : this.basePackages) { if (controllerType.getName().startsWith(basePackage)) { return true; } } for (Class<?> clazz : this.assignableTypes) { if (ClassUtils.isAssignable(clazz, controllerType)) { return true; } } for (Class<? extends Annotation> annotationClass : this.annotations) { if (AnnotationUtils.findAnnotation(controllerType, annotationClass) != null) { return true; } } } return false; }
private static boolean isApplicable(Member member, Class<?> sourceClass) { if (member instanceof Method) { Method method = (Method) member; return (!Modifier.isStatic(method.getModifiers()) ? ClassUtils.isAssignable(method.getDeclaringClass(), sourceClass) : method.getParameterTypes()[0] == sourceClass); } else if (member instanceof Constructor) { Constructor<?> ctor = (Constructor<?>) member; return (ctor.getParameterTypes()[0] == sourceClass); } else { return false; } }
@Nullable private static Method determineToMethod(Class<?> targetClass, Class<?> sourceClass) { if (String.class == targetClass || String.class == sourceClass) { // Do not accept a toString() method or any to methods on String itself return null; } Method method = ClassUtils.getMethodIfAvailable(sourceClass, "to" + targetClass.getSimpleName()); return (method != null && !Modifier.isStatic(method.getModifiers()) && ClassUtils.isAssignable(targetClass, method.getReturnType()) ? method : null); }
@Override public boolean isAssignableFrom(ResolvableType other) { Class<?> otherClass = other.getRawClass(); return (otherClass != null && (clazz == null || ClassUtils.isAssignable(clazz, otherClass))); } };
Method readMethod = sourcePd.getReadMethod(); if (readMethod != null && ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], readMethod.getReturnType())) { try { if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
if (!ClassUtils.isAssignable(paramTypeClazz, argType.getType())) { return Integer.MAX_VALUE; superClass = null; else if (ClassUtils.isAssignable(paramTypeClazz, superClass)) { result = result + 2; superClass = superClass.getSuperclass();
return ClassUtils.isAssignable(lhsClass, (Class<?>) rhsType); return ClassUtils.isAssignable(lhsClass, (Class<?>) rhsRaw); return ClassUtils.isAssignable((Class<?>) lhsRaw, (Class<?>) rhsType);
@Test public void testIsAssignable() { assertTrue(ClassUtils.isAssignable(Object.class, Object.class)); assertTrue(ClassUtils.isAssignable(String.class, String.class)); assertTrue(ClassUtils.isAssignable(Object.class, String.class)); assertTrue(ClassUtils.isAssignable(Object.class, Integer.class)); assertTrue(ClassUtils.isAssignable(Number.class, Integer.class)); assertTrue(ClassUtils.isAssignable(Number.class, int.class)); assertTrue(ClassUtils.isAssignable(Integer.class, int.class)); assertTrue(ClassUtils.isAssignable(int.class, Integer.class)); assertFalse(ClassUtils.isAssignable(String.class, Object.class)); assertFalse(ClassUtils.isAssignable(Integer.class, Number.class)); assertFalse(ClassUtils.isAssignable(Integer.class, double.class)); assertFalse(ClassUtils.isAssignable(double.class, Integer.class)); }
/** * Check if a given type requires a type hint (aka {@literal _class} attribute) when writing to the document. * * @param type must not be {@literal null}. * @return {@literal true} if not a simple type, {@link Collection} or type with custom write target. */ private boolean requiresTypeHint(Class<?> type) { return !conversions.isSimpleType(type) && !ClassUtils.isAssignable(Collection.class, type) && !conversions.hasCustomWriteTarget(type, Document.class); }
if (ClassUtils.isAssignable(targetClass, payloadClass)) { validate(message, parameter, payload); return payload;