Java Code Examples for org.springframework.core.ResolvableType#getGenerics()
The following examples show how to use
org.springframework.core.ResolvableType#getGenerics() .
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: RpcComponent.java From Brutusin-RPC with Apache License 2.0 | 6 votes |
/** * * @param rt * @return */ protected static Type getType(final ResolvableType rt) { if (!rt.hasGenerics()) { return rt.resolve(); } else { return new ParameterizedType() { public Type[] getActualTypeArguments() { Type[] ret = new Type[rt.getGenerics().length]; for (int i = 0; i < ret.length; i++) { ret[i] = getType(rt.getGenerics()[i]); } return ret; } public Type getRawType() { return rt.resolve(); } public Type getOwnerType() { return null; } }; } }
Example 2
Source File: FunctionTypeUtils.java From spring-cloud-function with Apache License 2.0 | 6 votes |
public static Type compose(Type originType, Type composedType) { ResolvableType resolvableOriginType = ResolvableType.forType(originType); ResolvableType resolvableComposedType = ResolvableType.forType(composedType); if (FunctionTypeUtils.isSupplier(originType)) { if (FunctionTypeUtils.isFunction(composedType)) { ResolvableType resolvableLastArgument = resolvableComposedType.getGenerics()[1]; resolvableLastArgument = FunctionTypeUtils.isPublisher(resolvableOriginType.getGeneric(0).getType()) ? ResolvableType.forClassWithGenerics(resolvableOriginType.getGeneric(0).getRawClass(), resolvableLastArgument) : resolvableLastArgument; originType = ResolvableType.forClassWithGenerics(Supplier.class, resolvableLastArgument).getType(); } } else { ResolvableType outType = FunctionTypeUtils.isConsumer(composedType) ? ResolvableType.forClass(Void.class) : (ObjectUtils.isEmpty(resolvableComposedType.getGenerics()) ? ResolvableType.forClass(Object.class) : resolvableComposedType.getGenerics()[1]); originType = ResolvableType.forClassWithGenerics(Function.class, ObjectUtils.isEmpty(resolvableOriginType.getGenerics()) ? resolvableOriginType : resolvableOriginType.getGenerics()[0], outType).getType(); } return originType; }
Example 3
Source File: GenericConversionService.java From spring-analysis-note with MIT License | 5 votes |
@Nullable private ResolvableType[] getRequiredTypeInfo(Class<?> converterClass, Class<?> genericIfc) { ResolvableType resolvableType = ResolvableType.forClass(converterClass).as(genericIfc); ResolvableType[] generics = resolvableType.getGenerics(); if (generics.length < 2) { return null; } Class<?> sourceType = generics[0].resolve(); Class<?> targetType = generics[1].resolve(); if (sourceType == null || targetType == null) { return null; } return generics; }
Example 4
Source File: GenericConversionService.java From java-technology-stack with MIT License | 5 votes |
@Nullable private ResolvableType[] getRequiredTypeInfo(Class<?> converterClass, Class<?> genericIfc) { ResolvableType resolvableType = ResolvableType.forClass(converterClass).as(genericIfc); ResolvableType[] generics = resolvableType.getGenerics(); if (generics.length < 2) { return null; } Class<?> sourceType = generics[0].resolve(); Class<?> targetType = generics[1].resolve(); if (sourceType == null || targetType == null) { return null; } return generics; }
Example 5
Source File: SolaceJmsAutoConfigurationTestBase.java From solace-jms-spring-boot with Apache License 2.0 | 5 votes |
static Set<Object[]> getTestParameters(Set<ResolvableType> testClasses) { Set<Object[]> parameters = new HashSet<>(); for (ResolvableType resolvableRawClass : testClasses) { Class<?> rawClass = resolvableRawClass.resolve(); StringBuilder testName = new StringBuilder(rawClass.getSimpleName()); for (ResolvableType resolvableGeneric : resolvableRawClass.getGenerics()) { Class<?> genericClass = resolvableGeneric.getRawClass(); if (genericClass != null) testName = testName.append('—').append(genericClass.getSimpleName()); } parameters.add(new Object[]{testName.toString(), rawClass}); } return parameters; }
Example 6
Source File: GenericConversionService.java From lams with GNU General Public License v2.0 | 5 votes |
private ResolvableType[] getRequiredTypeInfo(Class<?> converterClass, Class<?> genericIfc) { ResolvableType resolvableType = ResolvableType.forClass(converterClass).as(genericIfc); ResolvableType[] generics = resolvableType.getGenerics(); if (generics.length < 2) { return null; } Class<?> sourceType = generics[0].resolve(); Class<?> targetType = generics[1].resolve(); if (sourceType == null || targetType == null) { return null; } return generics; }
Example 7
Source File: SolaceJavaAutoConfigurationTestBase.java From solace-java-spring-boot with Apache License 2.0 | 5 votes |
static Set<Object[]> getTestParameters(Set<ResolvableType> testClasses) { Set<Object[]> parameters = new HashSet<>(); for (ResolvableType resolvableRawClass : testClasses) { Class<?> rawClass = resolvableRawClass.resolve(); StringBuilder testName = new StringBuilder(rawClass.getSimpleName()); for (ResolvableType resolvableGeneric : resolvableRawClass.getGenerics()) { Class<?> genericClass = resolvableGeneric.getRawClass(); if (genericClass != null) testName = testName.append('—').append(genericClass.getSimpleName()); } parameters.add(new Object[]{testName.toString(), rawClass}); } return parameters; }
Example 8
Source File: GenericConversionService.java From spring4-understanding with Apache License 2.0 | 5 votes |
private ResolvableType[] getRequiredTypeInfo(Object converter, Class<?> genericIfc) { ResolvableType resolvableType = ResolvableType.forClass(converter.getClass()).as(genericIfc); ResolvableType[] generics = resolvableType.getGenerics(); if (generics.length < 2) { return null; } Class<?> sourceType = generics[0].resolve(); Class<?> targetType = generics[1].resolve(); if (sourceType == null || targetType == null) { return null; } return generics; }
Example 9
Source File: LambdaSafe.java From initializr with Apache License 2.0 | 5 votes |
@Override public boolean match(Class<C> callbackType, C callbackInstance, A argument, Object[] additionalArguments) { ResolvableType type = ResolvableType.forClass(callbackType, callbackInstance.getClass()); if (type.getGenerics().length == 1 && type.resolveGeneric() != null) { return type.resolveGeneric().isInstance(argument); } return true; }
Example 10
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; }