Skip to content

Commit

Permalink
fix eclipse warnings
Browse files Browse the repository at this point in the history
Remove @SuppressWarnings("deprecation") on deprecated methods. The
annotation is for suppressing calls of deprecated methods, not
implementation of deprecated methods.

Only generated _plainSerDe when it is used.

Fixes #1635
  • Loading branch information
rzpt committed Nov 16, 2022
1 parent b6d02c7 commit 8e54a5a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
import com.palantir.logsafe.SafeArg;
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 @@ -233,13 +232,6 @@ private TypeSpec generateEndpointHandler(
.addCode(endpointInvocation(
endpointDefinition, typeDefinitions, typeMapper, returnTypeMapper, safetyEvaluator));

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

MethodSpec.Builder ctorBuilder = MethodSpec.constructorBuilder()
.addParameter(UndertowRuntime.class, RUNTIME_VAR_NAME)
.addParameter(serviceClass, DELEGATE_VAR_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import com.palantir.dialogue.TypeMarker;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.exceptions.SafeIllegalStateException;
import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.FieldSpec;
Expand All @@ -75,6 +74,7 @@ public final class DefaultStaticFactoryMethodGenerator implements StaticFactoryM
private final ParameterTypeMapper parameterTypes;
private final ReturnTypeMapper returnTypes;
private final StaticFactoryMethodType methodType;
private final ThreadLocal<Boolean> shouldGeneratePlainSerDe = ThreadLocal.withInitial(() -> false);

public DefaultStaticFactoryMethodGenerator(
Options options,
Expand All @@ -91,14 +91,10 @@ public DefaultStaticFactoryMethodGenerator(

@Override
public MethodSpec generate(ServiceDefinition def) {
shouldGeneratePlainSerDe.set(false);
ClassName className = getClassName(def);
TypeSpec.Builder impl = TypeSpec.anonymousClassBuilder("").addSuperinterface(className);

impl.addField(FieldSpec.builder(PlainSerDe.class, PLAIN_SER_DE)
.addModifiers(Modifier.PRIVATE, Modifier.FINAL)
.initializer(CodeBlock.of("$L.plainSerDe()", StaticFactoryMethodGenerator.RUNTIME))
.build());

def.getEndpoints().forEach(endpoint -> {
endpoint.getArgs().stream()
.filter(arg -> arg.getParamType().accept(ParameterTypeVisitor.IS_BODY))
Expand All @@ -113,6 +109,13 @@ public MethodSpec generate(ServiceDefinition def) {

impl.addMethod(DefaultStaticFactoryMethodGenerator.toStringMethod(className));

if (shouldGeneratePlainSerDe.get()) {
impl.addField(FieldSpec.builder(PlainSerDe.class, PLAIN_SER_DE)
.addModifiers(Modifier.PRIVATE, Modifier.FINAL)
.initializer(CodeBlock.of("$L.plainSerDe()", StaticFactoryMethodGenerator.RUNTIME))
.build());
}

String javadoc = methodType.switchBy(
"Creates a synchronous/blocking client for a $L service.",
"Creates an " + "asynchronous/non-blocking client for a $L service.");
Expand All @@ -124,6 +127,7 @@ public MethodSpec generate(ServiceDefinition def) {
.addParameter(ConjureRuntime.class, StaticFactoryMethodGenerator.RUNTIME)
.addCode(CodeBlock.builder().add("return $L;", impl.build()).build())
.build();

return method;
}

Expand Down Expand Up @@ -200,20 +204,12 @@ private MethodSpec clientImpl(EndpointDefinition def) {
.addParameters(params)
.addAnnotation(Override.class);

if (def.getDeprecated().isPresent()) {
methodBuilder.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class)
.addMember("value", "$S", "deprecation")
.build());
}

TypeName returnType =
methodType.switchBy(returnTypes.baseType(def.getReturns()), returnTypes.async(def.getReturns()));
methodBuilder.returns(returnType);

CodeBlock.Builder requestParams = CodeBlock.builder();
def.getAuth()
.map(DefaultStaticFactoryMethodGenerator::generateAuthHeader)
.ifPresent(requestParams::add);
def.getAuth().map(this::generateAuthHeader).ifPresent(requestParams::add);

def.getArgs().stream()
.map(param -> generateParam(def.getEndpointName().get(), param))
Expand Down Expand Up @@ -311,6 +307,7 @@ private CodeBlock generatePlainSerializer(String method, String key, CodeBlock a
return type.accept(new Type.Visitor<CodeBlock>() {
@Override
public CodeBlock visitPrimitive(PrimitiveType primitiveType) {
shouldGeneratePlainSerDe.set(true);
return CodeBlock.of(
"$L.$L($S, $L.serialize$L($L));",
"_request",
Expand Down Expand Up @@ -388,7 +385,7 @@ private CodeBlock visitCollection(Type itemType) {
});
}

private static CodeBlock generateAuthHeader(AuthType auth) {
private CodeBlock generateAuthHeader(AuthType auth) {
return auth.accept(new AuthType.Visitor<CodeBlock>() {
@Override
public CodeBlock visitHeader(HeaderAuthType value) {
Expand All @@ -401,6 +398,7 @@ public CodeBlock visitHeader(HeaderAuthType value) {

@Override
public CodeBlock visitCookie(CookieAuthType value) {
shouldGeneratePlainSerDe.set(true);
return CodeBlock.of(
"$L.putHeaderParams($S, \"$L=\" + $L.serializeBearerToken($L));",
REQUEST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,11 +910,6 @@ private static MethodSpec createWrapperAcceptMethod(
} else {
methodBuilder.addStatement("return $N.$N($N)", visitor, visitMethodName, valueName);
}
if (isDeprecated) {
methodBuilder.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class)
.addMember("value", "$S", "deprecation")
.build());
}
return methodBuilder.build();
}

Expand Down

0 comments on commit 8e54a5a

Please sign in to comment.