use of io.lettuce.core.dynamic.support.TypeInformation in project lettuce-core by lettuce-io.
the class OutputRegistry method getOutputComponentType.
/**
* Retrieve {@link OutputType} for a {@link CommandOutput} type.
*
* @param commandOutputClass
* @return
*/
static OutputType getOutputComponentType(Class<? extends CommandOutput> commandOutputClass) {
ClassTypeInformation<? extends CommandOutput> classTypeInformation = ClassTypeInformation.from(commandOutputClass);
TypeInformation<?> superTypeInformation = classTypeInformation.getSuperTypeInformation(CommandOutput.class);
if (superTypeInformation == null) {
return null;
}
List<TypeInformation<?>> typeArguments = superTypeInformation.getTypeArguments();
return new OutputType(commandOutputClass, typeArguments.get(2), false) {
@Override
public ResolvableType withCodec(RedisCodec<?, ?> codec) {
TypeInformation<?> typeInformation = ClassTypeInformation.from(codec.getClass());
ResolvableType resolvableType = ResolvableType.forType(commandOutputClass, new CodecVariableTypeResolver(typeInformation));
while (!resolvableType.getRawClass().equals(CommandOutput.class)) {
resolvableType = resolvableType.getSuperType();
}
return resolvableType.getGeneric(2);
}
};
}
use of io.lettuce.core.dynamic.support.TypeInformation in project lettuce-core by lettuce-io.
the class ParameterWrappersUnitTests method shouldReturnValueTypeForList.
@Test
void shouldReturnValueTypeForList() {
Method method = ReflectionUtils.findMethod(CommandMethods.class, "withList", List.class);
TypeInformation typeInformation = new Parameter(method, 0).getTypeInformation();
assertThat(ParameterWrappers.hasKeyType(typeInformation)).isFalse();
assertThat(ParameterWrappers.supports(typeInformation)).isTrue();
assertThat(ParameterWrappers.getValueType(typeInformation).getType()).isEqualTo(String.class);
}
use of io.lettuce.core.dynamic.support.TypeInformation in project lettuce-core by lettuce-io.
the class ParameterWrappersUnitTests method shouldReturnValueTypeForKeyValue.
@Test
void shouldReturnValueTypeForKeyValue() {
Method method = ReflectionUtils.findMethod(CommandMethods.class, "keyValue", KeyValue.class);
TypeInformation typeInformation = new Parameter(method, 0).getTypeInformation();
assertThat(ParameterWrappers.hasKeyType(typeInformation)).isTrue();
assertThat(ParameterWrappers.getKeyType(typeInformation).getType()).isEqualTo(Integer.class);
assertThat(ParameterWrappers.hasValueType(typeInformation)).isTrue();
assertThat(ParameterWrappers.getValueType(typeInformation).getType()).isEqualTo(String.class);
}
use of io.lettuce.core.dynamic.support.TypeInformation in project lettuce-core by lettuce-io.
the class OutputRegistry method getStreamingType.
/**
* Retrieve {@link OutputType} for a {@link StreamingOutput} type.
*
* @param commandOutputClass
* @return
*/
@SuppressWarnings("rawtypes")
static OutputType getStreamingType(Class<? extends CommandOutput> commandOutputClass) {
ClassTypeInformation<? extends CommandOutput> classTypeInformation = ClassTypeInformation.from(commandOutputClass);
TypeInformation<?> superTypeInformation = classTypeInformation.getSuperTypeInformation(StreamingOutput.class);
if (superTypeInformation == null) {
return null;
}
List<TypeInformation<?>> typeArguments = superTypeInformation.getTypeArguments();
return new OutputType(commandOutputClass, typeArguments.get(0), true) {
@Override
public ResolvableType withCodec(RedisCodec<?, ?> codec) {
TypeInformation<?> typeInformation = ClassTypeInformation.from(codec.getClass());
ResolvableType resolvableType = ResolvableType.forType(commandOutputClass, new CodecVariableTypeResolver(typeInformation));
while (resolvableType != ResolvableType.NONE) {
ResolvableType[] interfaces = resolvableType.getInterfaces();
for (ResolvableType resolvableInterface : interfaces) {
if (resolvableInterface.getRawClass().equals(StreamingOutput.class)) {
return resolvableInterface.getGeneric(0);
}
}
resolvableType = resolvableType.getSuperType();
}
throw new IllegalStateException();
}
};
}
use of io.lettuce.core.dynamic.support.TypeInformation in project lettuce-core by lettuce-io.
the class ParameterWrappersUnitTests method shouldReturnValueTypeForMap.
@Test
void shouldReturnValueTypeForMap() {
Method method = ReflectionUtils.findMethod(CommandMethods.class, "withMap", Map.class);
TypeInformation typeInformation = new Parameter(method, 0).getTypeInformation();
assertThat(ParameterWrappers.hasKeyType(typeInformation)).isTrue();
assertThat(ParameterWrappers.getKeyType(typeInformation).getType()).isEqualTo(Integer.class);
assertThat(ParameterWrappers.hasValueType(typeInformation)).isTrue();
assertThat(ParameterWrappers.getValueType(typeInformation).getType()).isEqualTo(String.class);
}
Aggregations