public DefaultParameterNameDiscoverer() { if (!GraalDetector.inImageCode()) { if (KotlinDetector.isKotlinReflectPresent()) { addDiscoverer(new KotlinReflectionParameterNameDiscoverer()); } addDiscoverer(new StandardReflectionParameterNameDiscoverer()); addDiscoverer(new LocalVariableTableParameterNameDiscoverer()); } }
@Override public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) { ReactiveAdapter adapter = this.adapterRegistry.getAdapter(returnType.getParameterType(), returnValue); return (adapter != null && !adapter.isMultiValue() && !adapter.isNoValue()); }
private Class<?> getPayloadType(MethodParameter parameter) { Type genericParamType = parameter.getGenericParameterType(); ResolvableType resolvableType = ResolvableType.forType(genericParamType).as(Message.class); return resolvableType.getGeneric().toClass(); }
/** * Return whether this method indicates a parameter which is not required: * either in the form of Java 8's {@link java.util.Optional}, any variant * of a parameter-level {@code Nullable} annotation (such as from JSR-305 * or the FindBugs set of annotations), or a language-level nullable type * declaration in Kotlin. * @since 4.3 */ public boolean isOptional() { return (getParameterType() == Optional.class || hasNullableAnnotation() || (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(getContainingClass()) && KotlinDelegate.isOptional(this))); }
@Override public boolean supportsReturnType(MethodParameter returnType) { return this.adapterRegistry.getAdapter(returnType.getParameterType()) != null; }
/** * Resolve the top-level parameter type of the given {@code MethodParameter}. * @param methodParameter the method parameter to resolve * @since 4.1.9 * @see MethodParameter#setParameterType */ static void resolveMethodParameter(MethodParameter methodParameter) { Assert.notNull(methodParameter, "MethodParameter must not be null"); ResolvableType owner = forType(methodParameter.getContainingClass()).as(methodParameter.getDeclaringClass()); methodParameter.setParameterType( forType(null, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()).resolve()); }
/** * Resolve the specified generic type against the given TypeVariable map. * <p>Used by Spring Data. * @param genericType the generic type to resolve * @param map the TypeVariable Map to resolved against * @return the type if it resolves to a Class, or {@code Object.class} otherwise */ @SuppressWarnings("rawtypes") public static Class<?> resolveType(Type genericType, Map<TypeVariable, Type> map) { return ResolvableType.forType(genericType, new TypeVariableMapVariableResolver(map)).toClass(); }
/** * Return a {@link ResolvableType} for the specified {@link ParameterizedTypeReference}. * <p>Note: The resulting {@link ResolvableType} instance may not be {@link Serializable}. * @param typeReference the reference to obtain the source type from * @return a {@link ResolvableType} for the specified {@link ParameterizedTypeReference} * @since 4.3.12 * @see #forType(Type) */ public static ResolvableType forType(ParameterizedTypeReference<?> typeReference) { return forType(typeReference.getType(), null, null); }
@Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if (isEligibleForOverriding(name)) { Class<?> result = loadClassForOverriding(name); if (result != null) { if (resolve) { resolveClass(result); } return result; } } return super.loadClass(name, resolve); }
/** * Unwrap the given type, effectively returning the original non-serializable type. * @param type the type to unwrap * @return the original non-serializable type */ @SuppressWarnings("unchecked") public static <T extends Type> T unwrap(T type) { Type unwrapped = type; while (unwrapped instanceof SerializableTypeProxy) { unwrapped = ((SerializableTypeProxy) type).getTypeProvider().getType(); } return (unwrapped != null ? (T) unwrapped : type); }
/** * Shortcut for {@code getDescriptor().isMultiValue()}. */ public boolean isMultiValue() { return getDescriptor().isMultiValue(); }
/** * Shortcut for {@code getDescriptor().isNoValue()}. */ public boolean isNoValue() { return getDescriptor().isNoValue(); }
/** * Shortcut for {@code getDescriptor().getReactiveType()}. */ public Class<?> getReactiveType() { return getDescriptor().getReactiveType(); }
/** * Shortcut for {@code getDescriptor().supportsEmpty()}. */ public boolean supportsEmpty() { return getDescriptor().supportsEmpty(); }
/** * Increase this descriptor's nesting level. * @see MethodParameter#increaseNestingLevel() */ public void increaseNestingLevel() { this.nestingLevel++; this.resolvableType = null; if (this.methodParameter != null) { this.methodParameter.increaseNestingLevel(); } }
/** * Determine whether the specified class is eligible for overriding * by this class loader. * @param className the class name to check * @return whether the specified class is eligible * @see #isExcluded */ protected boolean isEligibleForOverriding(String className) { return !isExcluded(className); }
/** * Descriptor for a reactive type that can produce 0..1 values. * @param type the reactive type * @param emptySupplier a supplier of an empty-value instance of the reactive type */ public static ReactiveTypeDescriptor singleOptionalValue(Class<?> type, Supplier<?> emptySupplier) { return new ReactiveTypeDescriptor(type, emptySupplier, false, false); }
/** * Build a {@code ParameterizedTypeReference} wrapping the given type. * @param type a generic type (possibly obtained via reflection, * e.g. from {@link java.lang.reflect.Method#getGenericReturnType()}) * @return a corresponding reference which may be passed into * {@code ParameterizedTypeReference}-accepting methods * @since 4.3.12 */ public static <T> ParameterizedTypeReference<T> forType(Type type) { return new ParameterizedTypeReference<T>(type) { }; }
/** * Descriptor for a reactive type that must produce 1 value to complete. * @param type the reactive type */ public static ReactiveTypeDescriptor singleRequiredValue(Class<?> type) { return new ReactiveTypeDescriptor(type, null, false, false); }