Search in sources :

Example 1 with DefaultClassNameVisitor

use of com.palantir.conjure.java.types.DefaultClassNameVisitor in project conjure-java by palantir.

the class JerseyServiceGenerator method generate.

@Override
public Stream<JavaFile> generate(ConjureDefinition conjureDefinition) {
    ClassName binaryReturnType = options.jerseyBinaryAsResponse() ? BINARY_RETURN_TYPE_RESPONSE : BINARY_RETURN_TYPE_OUTPUT;
    TypeName optionalBinaryReturnType = options.jerseyBinaryAsResponse() ? BINARY_RETURN_TYPE_RESPONSE : OPTIONAL_BINARY_RETURN_TYPE;
    Map<com.palantir.conjure.spec.TypeName, TypeDefinition> types = TypeFunctions.toTypesMap(conjureDefinition);
    ClassNameVisitor defaultVisitor = new DefaultClassNameVisitor(types.keySet(), options);
    TypeMapper returnTypeMapper = new TypeMapper(types, new SpecializeBinaryClassNameVisitor(defaultVisitor, types, binaryReturnType, optionalBinaryReturnType));
    TypeMapper argumentTypeMapper = new TypeMapper(types, new SpecializeBinaryClassNameVisitor(defaultVisitor, types, BINARY_ARGUMENT_TYPE));
    return conjureDefinition.getServices().stream().map(serviceDef -> generateService(serviceDef, returnTypeMapper, argumentTypeMapper));
}
Also used : TypeMapper(com.palantir.conjure.java.types.TypeMapper) DefaultClassNameVisitor(com.palantir.conjure.java.types.DefaultClassNameVisitor) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeName(com.squareup.javapoet.TypeName) ClassName(com.squareup.javapoet.ClassName) ClassNameVisitor(com.palantir.conjure.java.types.ClassNameVisitor) SpecializeBinaryClassNameVisitor(com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor) DefaultClassNameVisitor(com.palantir.conjure.java.types.DefaultClassNameVisitor) SpecializeBinaryClassNameVisitor(com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor) TypeDefinition(com.palantir.conjure.spec.TypeDefinition)

Example 2 with DefaultClassNameVisitor

use of com.palantir.conjure.java.types.DefaultClassNameVisitor in project conjure-java by palantir.

the class DialogueServiceGenerator method generate.

@Override
public Stream<JavaFile> generate(ConjureDefinition conjureDefinition) {
    Map<TypeName, TypeDefinition> types = TypeFunctions.toTypesMap(conjureDefinition);
    DialogueEndpointsGenerator endpoints = new DialogueEndpointsGenerator(options);
    TypeMapper parameterTypes = new TypeMapper(types, new SpecializeBinaryClassNameVisitor(new DefaultClassNameVisitor(types.keySet(), options), types, ClassName.get(BinaryRequestBody.class)));
    TypeMapper returnTypes = new TypeMapper(types, new SpecializeBinaryClassNameVisitor(new DefaultClassNameVisitor(types.keySet(), options), types, ClassName.get(InputStream.class)));
    Map<TypeName, TypeDefinition> typeDefinitionsByName = conjureDefinition.getTypes().stream().collect(Collectors.toMap(type -> type.accept(TypeDefinitionVisitor.TYPE_NAME), Function.identity()));
    DialogueInterfaceGenerator interfaceGenerator = new DialogueInterfaceGenerator(options, new ParameterTypeMapper(parameterTypes), new ReturnTypeMapper(returnTypes));
    TypeNameResolver typeNameResolver = typeName -> Preconditions.checkNotNull(typeDefinitionsByName.get(typeName), "Referenced unknown TypeName", SafeArg.of("typeName", typeName));
    StaticFactoryMethodGenerator asyncGenerator = new DefaultStaticFactoryMethodGenerator(options, typeNameResolver, new ParameterTypeMapper(parameterTypes), new ReturnTypeMapper(returnTypes), StaticFactoryMethodType.ASYNC);
    StaticFactoryMethodGenerator blockingGenerator = new DefaultStaticFactoryMethodGenerator(options, typeNameResolver, new ParameterTypeMapper(parameterTypes), new ReturnTypeMapper(returnTypes), StaticFactoryMethodType.BLOCKING);
    return conjureDefinition.getServices().stream().flatMap(serviceDef -> Stream.of(endpoints.endpointsClass(serviceDef), interfaceGenerator.generateBlocking(serviceDef, blockingGenerator), interfaceGenerator.generateAsync(serviceDef, asyncGenerator)));
}
Also used : TypeMapper(com.palantir.conjure.java.types.TypeMapper) TypeDefinition(com.palantir.conjure.spec.TypeDefinition) SpecializeBinaryClassNameVisitor(com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor) DefaultClassNameVisitor(com.palantir.conjure.java.types.DefaultClassNameVisitor) TypeFunctions(com.palantir.conjure.java.util.TypeFunctions) ClassName(com.squareup.javapoet.ClassName) TypeMapper(com.palantir.conjure.java.types.TypeMapper) TypeDefinitionVisitor(com.palantir.conjure.visitor.TypeDefinitionVisitor) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) BinaryRequestBody(com.palantir.dialogue.BinaryRequestBody) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Options(com.palantir.conjure.java.Options) JavaFile(com.squareup.javapoet.JavaFile) SafeArg(com.palantir.logsafe.SafeArg) Stream(java.util.stream.Stream) Generator(com.palantir.conjure.java.Generator) TypeName(com.palantir.conjure.spec.TypeName) Map(java.util.Map) Preconditions(com.palantir.logsafe.Preconditions) InputStream(java.io.InputStream) DefaultClassNameVisitor(com.palantir.conjure.java.types.DefaultClassNameVisitor) TypeName(com.palantir.conjure.spec.TypeName) SpecializeBinaryClassNameVisitor(com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor) TypeDefinition(com.palantir.conjure.spec.TypeDefinition)

Example 3 with DefaultClassNameVisitor

use of com.palantir.conjure.java.types.DefaultClassNameVisitor in project conjure-java by palantir.

the class Retrofit2ServiceGenerator method generate.

@Override
public Stream<JavaFile> generate(ConjureDefinition conjureDefinition) {
    Map<com.palantir.conjure.spec.TypeName, TypeDefinition> types = TypeFunctions.toTypesMap(conjureDefinition);
    ClassNameVisitor defaultVisitor = new DefaultClassNameVisitor(types.keySet(), options);
    TypeMapper returnTypeMapper = new TypeMapper(types, new SpecializeBinaryClassNameVisitor(defaultVisitor, types, BINARY_RETURN_TYPE, OPTIONAL_BINARY_RETURN_TYPE));
    TypeMapper argumentTypeMapper = new TypeMapper(types, new SpecializeBinaryClassNameVisitor(defaultVisitor, types, BINARY_ARGUMENT_TYPE));
    return conjureDefinition.getServices().stream().map(serviceDef -> generateService(serviceDef, returnTypeMapper, argumentTypeMapper));
}
Also used : TypeMapper(com.palantir.conjure.java.types.TypeMapper) DefaultClassNameVisitor(com.palantir.conjure.java.types.DefaultClassNameVisitor) TypeName(com.squareup.javapoet.TypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) ClassNameVisitor(com.palantir.conjure.java.types.ClassNameVisitor) SpecializeBinaryClassNameVisitor(com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor) DefaultClassNameVisitor(com.palantir.conjure.java.types.DefaultClassNameVisitor) SpecializeBinaryClassNameVisitor(com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor) TypeDefinition(com.palantir.conjure.spec.TypeDefinition)

Example 4 with DefaultClassNameVisitor

use of com.palantir.conjure.java.types.DefaultClassNameVisitor in project conjure-java by palantir.

the class UndertowServiceGenerator method generate.

@Override
public Stream<JavaFile> generate(ConjureDefinition conjureDefinition) {
    Map<TypeName, TypeDefinition> types = TypeFunctions.toTypesMap(conjureDefinition);
    ClassNameVisitor defaultVisitor = new DefaultClassNameVisitor(types.keySet(), options);
    TypeMapper typeMapper = new TypeMapper(types, new SpecializeBinaryClassNameVisitor(defaultVisitor, types, ClassName.get(InputStream.class)));
    TypeMapper returnTypeMapper = new TypeMapper(types, new SpecializeBinaryClassNameVisitor(defaultVisitor, types, ClassName.get(BinaryResponseBody.class)));
    UndertowServiceInterfaceGenerator interfaceGenerator = new UndertowServiceInterfaceGenerator(options);
    UndertowServiceHandlerGenerator handlerGenerator = new UndertowServiceHandlerGenerator(options);
    return conjureDefinition.getServices().stream().flatMap(serviceDef -> Stream.of(interfaceGenerator.generateServiceInterface(serviceDef, typeMapper, returnTypeMapper), handlerGenerator.generateServiceHandler(serviceDef, types, typeMapper, returnTypeMapper)));
}
Also used : TypeMapper(com.palantir.conjure.java.types.TypeMapper) DefaultClassNameVisitor(com.palantir.conjure.java.types.DefaultClassNameVisitor) TypeName(com.palantir.conjure.spec.TypeName) SpecializeBinaryClassNameVisitor(com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor) DefaultClassNameVisitor(com.palantir.conjure.java.types.DefaultClassNameVisitor) ClassNameVisitor(com.palantir.conjure.java.types.ClassNameVisitor) SpecializeBinaryClassNameVisitor(com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor) TypeDefinition(com.palantir.conjure.spec.TypeDefinition)

Aggregations

DefaultClassNameVisitor (com.palantir.conjure.java.types.DefaultClassNameVisitor)4 SpecializeBinaryClassNameVisitor (com.palantir.conjure.java.types.SpecializeBinaryClassNameVisitor)4 TypeMapper (com.palantir.conjure.java.types.TypeMapper)4 TypeDefinition (com.palantir.conjure.spec.TypeDefinition)4 ClassNameVisitor (com.palantir.conjure.java.types.ClassNameVisitor)3 TypeName (com.palantir.conjure.spec.TypeName)2 ClassName (com.squareup.javapoet.ClassName)2 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)2 TypeName (com.squareup.javapoet.TypeName)2 Generator (com.palantir.conjure.java.Generator)1 Options (com.palantir.conjure.java.Options)1 TypeFunctions (com.palantir.conjure.java.util.TypeFunctions)1 ConjureDefinition (com.palantir.conjure.spec.ConjureDefinition)1 TypeDefinitionVisitor (com.palantir.conjure.visitor.TypeDefinitionVisitor)1 BinaryRequestBody (com.palantir.dialogue.BinaryRequestBody)1 Preconditions (com.palantir.logsafe.Preconditions)1 SafeArg (com.palantir.logsafe.SafeArg)1 JavaFile (com.squareup.javapoet.JavaFile)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1