From b4e8d5b8254f27cc067c6748c022fd94327cce7b Mon Sep 17 00:00:00 2001 From: Chaoren Lin Date: Tue, 20 Dec 2022 12:03:23 -0800 Subject: [PATCH] Add Guice extensions to cirvlist. Also update `Api#parse()` to accept class names with `-` in them. PiperOrigin-RevId: 496717232 --- .../errorprone/bugpatterns/checkreturnvalue/Api.java | 3 +++ .../bugpatterns/checkreturnvalue/ApiTest.java | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/Api.java b/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/Api.java index f211d3e57c1..d72eab342f9 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/Api.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/Api.java @@ -150,6 +150,9 @@ String owningType() { case '.': // OK, separator break; + case '-': + // OK, used in Kotlin JvmName to prevent Java users. + break; default: checkArgument( isJavaIdentifierPart(next), diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/checkreturnvalue/ApiTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/checkreturnvalue/ApiTest.java index cba54e4b0ec..510683533f4 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/checkreturnvalue/ApiTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/checkreturnvalue/ApiTest.java @@ -148,4 +148,16 @@ public void parseApi_methodWithVarargs_b231250004() { assertThat(api.isConstructor()).isTrue(); assertThat(api.toString()).isEqualTo(string); } + + @Test + public void parseApi_kotlinClassWithJvmName() { + String string = "com.google.inject.-GuiceExtensions#bind(com.google.inject.AbstractModule)"; + Api api = Api.parse(string); + + assertThat(api.className()).isEqualTo("com.google.inject.-GuiceExtensions"); + assertThat(api.methodName()).isEqualTo("bind"); + assertThat(api.parameterTypes()).containsExactly("com.google.inject.AbstractModule"); + assertThat(api.isConstructor()).isFalse(); + assertThat(api.toString()).isEqualTo(string); + } }