Skip to content

Commit

Permalink
Suppress deprecation warnings in generated undertow services (#245)
Browse files Browse the repository at this point in the history
## Before this PR
Undertow service handlers for deprecated endpoints fail to compile when using `-Xlint:deprecation`. This wasn't a problem for Jersey services because the deprecated methods were not called in the generated code.

## After this PR
Undertow service handlers suppress deprecation warnings when calling deprecated endpoints.
  • Loading branch information
pkoenig10 authored and bulldozer-bot[bot] committed Feb 21, 2019
1 parent 5762117 commit 4cfdb0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.palantir.conjure.visitor.TypeVisitor;
import com.palantir.tokens.auth.AuthHeader;
import com.palantir.tokens.auth.BearerToken;
import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.FieldSpec;
Expand Down Expand Up @@ -205,20 +206,26 @@ private TypeSpec generateEndpointHandler(EndpointDefinition endpointDefinition,
List<TypeDefinition> typeDefinitions,
TypeMapper typeMapper,
TypeMapper returnTypeMapper) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("handleRequest")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.addParameter(HttpServerExchange.class, EXCHANGE_VAR_NAME)
.addException(IOException.class)
.addCode(endpointInvocation(endpointDefinition, typeDefinitions, typeMapper, returnTypeMapper));

endpointDefinition.getDeprecated().ifPresent(deprecatedDocsValue -> methodBuilder.addAnnotation(
AnnotationSpec.builder(SuppressWarnings.class)
.addMember("value", "$S", "deprecation")
.build()));

return TypeSpec.classBuilder(endpointToHandlerClassName(endpointDefinition.getEndpointName()))
.addModifiers(Modifier.PRIVATE)
.addSuperinterface(HttpHandler.class)
.addFields(endpointDefinition.getArgs().stream()
.filter(def -> def.getParamType().accept(ParameterTypeVisitor.IS_BODY))
.map(def -> createTypeField(typeMapper, def))
.collect(Collectors.toList()))
.addMethod(MethodSpec.methodBuilder("handleRequest")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.addParameter(HttpServerExchange.class, EXCHANGE_VAR_NAME)
.addException(IOException.class)
.addCode(endpointInvocation(endpointDefinition, typeDefinitions, typeMapper, returnTypeMapper))
.build())
.addMethod(methodBuilder.build())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ public final class TestServiceEndpoints implements Service {

private class GetBranchesDeprecatedHandler implements HttpHandler {
@Override
@SuppressWarnings("deprecation")
public void handleRequest(HttpServerExchange exchange) throws IOException {
AuthHeader authHeader = Auth.header(exchange);
Map<String, String> pathParams =
Expand Down

0 comments on commit 4cfdb0b

Please sign in to comment.