use of com.palantir.conjure.java.undertow.processor.data.DefaultDecoderNames.ContainerType in project conjure-java by palantir.
the class ParamTypesResolver method getParamDecoder.
private CodeBlock getParamDecoder(VariableElement variableElement, AnnotationReflector annotationReflector) {
// If the default marker interface is not used (overwritten by user), we want to use the user-provided decoder.
TypeMirror typeMirror = annotationReflector.getAnnotationValue("decoder", TypeMirror.class);
if (!context.isSameTypes(typeMirror, DefaultParamDecoder.class)) {
return Instantiables.instantiate(typeMirror);
}
TypeMirror variableType = variableElement.asType();
// For param decoders, we don't support list and set container types.
Optional<TypeMirror> innerOptionalType = context.getGenericInnerType(Optional.class, variableType);
TypeMirror decoderType = innerOptionalType.orElse(variableType);
ContainerType decoderOutputType = getOutputType(Optional.empty(), Optional.empty(), innerOptionalType);
return DefaultDecoderNames.getDefaultDecoderFactory(decoderType, ContainerType.NONE, decoderOutputType).orElseGet(() -> {
context.reportError("No default decoder exists for parameter. " + "Types with a valueOf(String) method are supported, as are conjure types", variableElement, SafeArg.of("variableType", variableType), SafeArg.of("supportedTypes", DefaultDecoderNames.SUPPORTED_CLASSES));
return CodeBlock.of("// error");
});
}
use of com.palantir.conjure.java.undertow.processor.data.DefaultDecoderNames.ContainerType in project conjure-java by palantir.
the class ParamTypesResolver method getCollectionParamDecoder.
private CodeBlock getCollectionParamDecoder(VariableElement variableElement, AnnotationReflector annotationReflector) {
// If the default marker interface is not used (overwritten by user), we want to use the user-provided decoder.
TypeMirror typeMirror = annotationReflector.getAnnotationValue("decoder", TypeMirror.class);
if (!context.isSameTypes(typeMirror, DefaultParamDecoder.class)) {
return Instantiables.instantiate(typeMirror);
}
TypeMirror variableType = variableElement.asType();
Optional<TypeMirror> innerListType = context.getGenericInnerType(List.class, variableType);
Optional<TypeMirror> innerSetType = context.getGenericInnerType(Set.class, variableType);
Optional<TypeMirror> innerOptionalType = context.getGenericInnerType(Optional.class, variableType);
TypeMirror decoderType = innerListType.or(() -> innerSetType).or(() -> innerOptionalType).orElse(variableType);
ContainerType decoderOutputType = getOutputType(innerListType, innerSetType, innerOptionalType);
return DefaultDecoderNames.getDefaultDecoderFactory(decoderType, ContainerType.LIST, decoderOutputType).orElseGet(() -> {
context.reportError("No default decoder exists for parameter. " + "Types with a valueOf(String) method are supported, as are conjure types", variableElement, SafeArg.of("variableType", variableType), SafeArg.of("supportedTypes", DefaultDecoderNames.SUPPORTED_CLASSES));
return CodeBlock.of("// error");
});
}
use of com.palantir.conjure.java.undertow.processor.data.DefaultDecoderNames.ContainerType in project conjure-java by palantir.
the class DefaultDecoderNamesTest method getParamDecoderArguments.
private static List<Arguments> getParamDecoderArguments() {
List<Optional<String>> supportedClasses = Stream.concat(Stream.of(Optional.<String>empty()), DefaultDecoderNames.SUPPORTED_CLASSES.stream().map(Optional::of)).filter(maybeName -> maybeName.map(name -> !name.equals(OptionalDouble.class.getName()) && !name.equals(OptionalInt.class.getName())).orElse(true)).collect(Collectors.toList());
ImmutableList.Builder<Arguments> arguments = ImmutableList.builder();
// For 'ParamDecoder', we only support mapping to Optional as output container.
for (ContainerType outputContainer : ImmutableList.of(ContainerType.NONE, ContainerType.OPTIONAL)) {
arguments.addAll(getArgumentsForOutputContainer(ContainerType.NONE, outputContainer, supportedClasses));
}
// For 'CollectionParamDecoder', we support mapping to Optional, List, and Set as output container.
for (ContainerType outputContainer : ContainerType.values()) {
arguments.addAll(getArgumentsForOutputContainer(ContainerType.LIST, outputContainer, supportedClasses));
}
return arguments.build();
}
Aggregations