use of com.palantir.conjure.java.undertow.processor.generate.ConjureUndertowEndpointsGenerator in project conjure-java by palantir.
the class ConjureUndertowAnnotationProcessor method generateUndertowServiceEndpoints.
private JavaFile generateUndertowServiceEndpoints(Element annotatedInterface, Collection<? extends Element> annotatedMethods) {
validationStep(ctx -> {
for (Element element : annotatedMethods) {
if (!element.getKind().equals(ElementKind.METHOD)) {
ctx.reportError("Only methods can be annotated with @Handle", element);
} else if (element.getModifiers().contains(Modifier.PRIVATE) || element.getModifiers().contains(Modifier.PROTECTED)) {
ctx.reportError("Methods annotated with '@Handle' must be accessible to classes in the same " + "package, neither 'private' nor 'protected' modifiers are allowed.", element);
} else if (element.getModifiers().contains(Modifier.STATIC)) {
ctx.reportError("The '@Handle' annotation does not support static methods.", element);
}
}
});
List<EndpointDefinition> endpoints = processingStep(ctx -> {
EndpointDefinitions endpointDefinitions = new EndpointDefinitions(ctx, elements, types);
List<Optional<EndpointDefinition>> maybeEndpoints = annotatedMethods.stream().map(MoreElements::asExecutable).map(endpointDefinitions::tryParseEndpointDefinition).collect(Collectors.toList());
Preconditions.checkArgument(maybeEndpoints.stream().filter(Predicates.not(Optional::isPresent)).collect(Collectors.toList()).isEmpty(), "Failed validation");
return maybeEndpoints.stream().map(Optional::get).collect(Collectors.toList());
});
ClassName serviceInterface = ClassName.get(MoreElements.getPackage(annotatedInterface).getQualifiedName().toString(), annotatedInterface.getSimpleName().toString());
ServiceDefinition serviceDefinition = ImmutableServiceDefinition.builder().serviceInterface(serviceInterface).addAllEndpoints(endpoints).build();
TypeSpec generatedClass = new ConjureUndertowEndpointsGenerator(serviceDefinition).generate();
TypeSpec withOriginatingElement = generatedClass.toBuilder().addOriginatingElement(annotatedInterface).build();
return JavaFile.builder(serviceInterface.packageName(), withOriginatingElement).build();
}
Aggregations