Suppress deprecated warnings on Kotlin deprecated methods

780 Views Asked by At

I'm working on a project that uses grpc/grpc-kotlin to generate a Kotlin-idiomatic interface for interacting with gRPC Services and noticed the generated code has some warnings related to use of deprecated methods.

> Task :lib:compileKotlin
w: /Users/pedro/.../java/lib/src/main/kotlin/.../v1/GetUserByIdResponseKt.kt: (30, 24): 'getName(): String!' is deprecated. Deprecated in Java

There are some deprecated RPCs on the service definition that are being translated to Java methods annotated with @Deprecated. On top of that, Kotlin methods that invoke their Java counterparts are also generated and these are annotated with @kotlin.Deprecated.

message GetUserByIdResponse {
  string name = 1 [deprecated = true];
  ...
}
  /**
   * <code>string name = 1 [deprecated = true];</code>
   * @deprecated
   * @return The name.
   */
  @java.lang.Override
  @java.lang.Deprecated public java.lang.String getName() {
    java.lang.Object ref = name_;
    if (ref instanceof java.lang.String) {
      return (java.lang.String) ref;
    } else {
      com.google.protobuf.ByteString bs = 
          (com.google.protobuf.ByteString) ref;
      java.lang.String s = bs.toStringUtf8();
      name_ = s;
      return s;
    }
  }
    /**
     * <code>string name = 1 [deprecated = true];</code>
     */
    @kotlin.Deprecated(message = "Field name is deprecated") public var name: kotlin.String
      @JvmName("getName")
      get() = _builder.getName()
      @JvmName("setName")
      set(value) {
        _builder.setName(value)
      }

Is there a way to tell the Kotlin compiler to don't warn about deprecated method calls on deprecated methods? I know it's possible to accomplish that with @kotlin.Suppress("DEPRECATION"), but that would require me to patch the generated code or grpc-kotlin itself. It seems this kind of suppression should be something supported by some Kotlin compiler flag but I couldn't find any.

0

There are 0 best solutions below