Java Code Examples for org.springframework.core.ResolvableType#getSuperType()
The following examples show how to use
org.springframework.core.ResolvableType#getSuperType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReturnTypeParser.java From springdoc-openapi with Apache License 2.0 | 6 votes |
/** * Resolve variable resolvable type. * * @param typeVariable the type variable * @param contextType the context type * @return the resolvable type */ static ResolvableType resolveVariable(TypeVariable<?> typeVariable, ResolvableType contextType) { ResolvableType resolvedType; if (contextType.hasGenerics()) { resolvedType = ResolvableType.forType(typeVariable, contextType); if (resolvedType.resolve() != null) { return resolvedType; } } ResolvableType superType = contextType.getSuperType(); if (superType != ResolvableType.NONE) { resolvedType = resolveVariable(typeVariable, superType); if (resolvedType.resolve() != null) { return resolvedType; } } for (ResolvableType ifc : contextType.getInterfaces()) { resolvedType = resolveVariable(typeVariable, ifc); if (resolvedType.resolve() != null) { return resolvedType; } } return ResolvableType.NONE; }
Example 2
Source File: AbstractJackson2HttpMessageConverter.java From lams with GNU General Public License v2.0 | 6 votes |
private ResolvableType resolveVariable(TypeVariable<?> typeVariable, ResolvableType contextType) { ResolvableType resolvedType; if (contextType.hasGenerics()) { resolvedType = ResolvableType.forType(typeVariable, contextType); if (resolvedType.resolve() != null) { return resolvedType; } } ResolvableType superType = contextType.getSuperType(); if (superType != ResolvableType.NONE) { resolvedType = resolveVariable(typeVariable, superType); if (resolvedType.resolve() != null) { return resolvedType; } } for (ResolvableType ifc : contextType.getInterfaces()) { resolvedType = resolveVariable(typeVariable, ifc); if (resolvedType.resolve() != null) { return resolvedType; } } return ResolvableType.NONE; }
Example 3
Source File: FastJsonHttpMessageConverter.java From uavstack with Apache License 2.0 | 6 votes |
private static ResolvableType resolveVariable(TypeVariable<?> typeVariable, ResolvableType contextType) { ResolvableType resolvedType; if (contextType.hasGenerics()) { resolvedType = ResolvableType.forType(typeVariable, contextType); if (resolvedType.resolve() != null) { return resolvedType; } } ResolvableType superType = contextType.getSuperType(); if (superType != ResolvableType.NONE) { resolvedType = resolveVariable(typeVariable, superType); if (resolvedType.resolve() != null) { return resolvedType; } } for (ResolvableType ifc : contextType.getInterfaces()) { resolvedType = resolveVariable(typeVariable, ifc); if (resolvedType.resolve() != null) { return resolvedType; } } return ResolvableType.NONE; }
Example 4
Source File: GenericsUtils.java From spring-cloud-stream with Apache License 2.0 | 4 votes |
/** * For a specific class that implements or extends a parameterized type, return the * parameter of that interface at a given position. For example, for this class: * * <pre> {@code * class MessageChannelBinder implements Binder<MessageChannel, ?, ?> * } </pre> * * <pre> {@code * getParameterType(MessageChannelBinder.class, Binder.class, 0); * } </pre> * * will return {@code Binder} * @param evaluatedClass the evaluated class * @param interfaceClass the parametrized interface * @param position the position * @return the parameter type if any * @throws IllegalStateException if the evaluated class does not implement the * interface or */ public static Class<?> getParameterType(Class<?> evaluatedClass, Class<?> interfaceClass, int position) { Class<?> bindableType = null; Assert.isTrue(interfaceClass.isInterface(), "'interfaceClass' must be an interface"); if (!interfaceClass.isAssignableFrom(evaluatedClass)) { throw new IllegalStateException( evaluatedClass + " does not implement " + interfaceClass); } ResolvableType currentType = ResolvableType.forType(evaluatedClass); while (!Object.class.equals(currentType.getRawClass()) && bindableType == null) { ResolvableType[] interfaces = currentType.getInterfaces(); ResolvableType resolvableType = null; for (ResolvableType interfaceType : interfaces) { if (interfaceClass.equals(interfaceType.getRawClass())) { resolvableType = interfaceType; break; } } if (resolvableType == null) { currentType = currentType.getSuperType(); } else { ResolvableType[] generics = resolvableType.getGenerics(); ResolvableType generic = generics[position]; Class<?> resolvedParameter = generic.resolve(); if (resolvedParameter != null) { bindableType = resolvedParameter; } else { bindableType = Object.class; } } } if (bindableType == null) { throw new IllegalStateException( "Cannot find parameter of " + evaluatedClass.getName() + " for " + interfaceClass + " at position " + position); } return bindableType; }
Example 5
Source File: ResolvableTypeDemo.java From geekbang-lessons with Apache License 2.0 | 3 votes |
public static void main(String[] args) { // 工厂创建 // StringList <- ArrayList <- AbstractList <- List <- Collection ResolvableType resolvableType = ResolvableType.forClass(StringList.class); resolvableType.getSuperType(); // ArrayList resolvableType.getSuperType().getSuperType(); // AbstractList System.out.println(resolvableType.asCollection().resolve()); // 获取 Raw Type System.out.println(resolvableType.asCollection().resolveGeneric(0)); // 获取泛型参数类型 }