From 53b4bc812b2c4bc0d2cd90399c9155ab3260f703 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Thu, 10 Oct 2024 14:01:06 -0700 Subject: [PATCH 1/3] Switch to Palantir's JavaPoet --- gradle/libs.versions.toml | 4 +-- .../com/squareup/wire/java/JavaGenerator.java | 28 +++++++++---------- .../squareup/wire/java/JavaSchemaHandler.kt | 12 ++++---- .../squareup/wire/java/JavaGeneratorHelper.kt | 2 +- .../squareup/wire/java/JavaGeneratorTest.java | 4 +-- .../wire/java/JavaWithProfilesGenerator.kt | 2 +- .../squareup/wire/schema/AdapterConstant.kt | 2 +- .../com/squareup/wire/schema/Profile.kt | 4 +-- .../squareup/wire/schema/ProfileLoaderTest.kt | 2 +- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 00ae50dac3..f8122290e4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,7 +8,7 @@ dokka = "1.9.20" grpc = "1.68.0" gson = "2.11.0" guava = "32.0.1-jre" -javapoet = "1.13.0" +javapoet = "0.5.0" jimfs = "1.3.0" jmh = "1.37" jsr305 = "3.0.2" @@ -43,7 +43,7 @@ grpc-protobuf = { module = "io.grpc:grpc-protobuf", version.ref = "grpc" } grpc-stub = { module = "io.grpc:grpc-stub", version.ref = "grpc" } gson = { module = "com.google.code.gson:gson", version.ref = "gson" } guava = { module = "com.google.guava:guava", version.ref = "guava" } -javapoet = { module = "com.squareup:javapoet", version.ref = "javapoet" } +javapoet = { module = "com.palantir.javapoet:javapoet", version.ref = "javapoet" } jimfs = { module = "com.google.jimfs:jimfs", version.ref = "jimfs" } jmh-core = { module = "org.openjdk.jmh:jmh-core", version.ref = "jmh" } jmh-generator = { module = "org.openjdk.jmh:jmh-generator-annprocess", version.ref = "jmh" } diff --git a/wire-java-generator/src/main/java/com/squareup/wire/java/JavaGenerator.java b/wire-java-generator/src/main/java/com/squareup/wire/java/JavaGenerator.java index 1755d1f063..463680f453 100644 --- a/wire-java-generator/src/main/java/com/squareup/wire/java/JavaGenerator.java +++ b/wire-java-generator/src/main/java/com/squareup/wire/java/JavaGenerator.java @@ -39,18 +39,18 @@ import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Ordering; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ArrayTypeName; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.CodeBlock; -import com.squareup.javapoet.FieldSpec; -import com.squareup.javapoet.MethodSpec; -import com.squareup.javapoet.NameAllocator; -import com.squareup.javapoet.ParameterSpec; -import com.squareup.javapoet.ParameterizedTypeName; -import com.squareup.javapoet.TypeName; -import com.squareup.javapoet.TypeSpec; -import com.squareup.javapoet.WildcardTypeName; +import com.palantir.javapoet.AnnotationSpec; +import com.palantir.javapoet.ArrayTypeName; +import com.palantir.javapoet.ClassName; +import com.palantir.javapoet.CodeBlock; +import com.palantir.javapoet.FieldSpec; +import com.palantir.javapoet.MethodSpec; +import com.palantir.javapoet.NameAllocator; +import com.palantir.javapoet.ParameterSpec; +import com.palantir.javapoet.ParameterizedTypeName; +import com.palantir.javapoet.TypeName; +import com.palantir.javapoet.TypeSpec; +import com.palantir.javapoet.WildcardTypeName; import com.squareup.wire.EnumAdapter; import com.squareup.wire.FieldEncoding; import com.squareup.wire.Message; @@ -510,7 +510,7 @@ public TypeName typeName(ProtoType protoType) { if (typeName instanceof ClassName) { javaName = (ClassName) typeName; } else if (typeName instanceof ParameterizedTypeName) { - javaName = ((ParameterizedTypeName) typeName).rawType; + javaName = ((ParameterizedTypeName) typeName).rawType(); } else { throw new IllegalArgumentException("Unexpected typeName :" + typeName); } @@ -1641,7 +1641,7 @@ private String adapterString(ProtoType type) { private String reflectionName(TypeName typeName) { ClassName className; if (typeName instanceof ParameterizedTypeName) { - className = ((ParameterizedTypeName) typeName).rawType; + className = ((ParameterizedTypeName) typeName).rawType(); } else { className = (ClassName) typeName; } diff --git a/wire-java-generator/src/main/java/com/squareup/wire/java/JavaSchemaHandler.kt b/wire-java-generator/src/main/java/com/squareup/wire/java/JavaSchemaHandler.kt index 1d537c1a6a..5ed35c82a4 100644 --- a/wire-java-generator/src/main/java/com/squareup/wire/java/JavaSchemaHandler.kt +++ b/wire-java-generator/src/main/java/com/squareup/wire/java/JavaSchemaHandler.kt @@ -15,7 +15,7 @@ */ package com.squareup.wire.java -import com.squareup.javapoet.JavaFile +import com.palantir.javapoet.JavaFile import com.squareup.wire.schema.Extend import com.squareup.wire.schema.Field import com.squareup.wire.schema.Location @@ -86,8 +86,8 @@ class JavaSchemaHandler( } private fun write( - javaTypeName: com.squareup.javapoet.ClassName, - typeSpec: com.squareup.javapoet.TypeSpec, + javaTypeName: com.palantir.javapoet.ClassName, + typeSpec: com.palantir.javapoet.TypeSpec, source: Any, location: Location, context: Context, @@ -98,12 +98,12 @@ class JavaSchemaHandler( .addFileComment("\nSource: \$L in \$L", source, location.withPathOnly()) .build() val filePath = outDirectory / - javaFile.packageName.replace(".", "/") / + javaFile.packageName().replace(".", "/") / "${javaTypeName.simpleName()}.java" context.logger.artifactHandled( outDirectory, - "${javaFile.packageName}.${javaFile.typeSpec.name}", + "${javaFile.packageName()}.${javaFile.typeSpec().name()}", "Java", ) try { @@ -113,7 +113,7 @@ class JavaSchemaHandler( } } catch (e: IOException) { throw IOException( - "Error emitting ${javaFile.packageName}.${javaFile.typeSpec.name} to $outDirectory", + "Error emitting ${javaFile.packageName()}.${javaFile.typeSpec().name()} to $outDirectory", e, ) } diff --git a/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorHelper.kt b/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorHelper.kt index 9637f699e8..7e9e7625db 100644 --- a/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorHelper.kt +++ b/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorHelper.kt @@ -15,7 +15,7 @@ */ package com.squareup.wire.java -import com.squareup.javapoet.JavaFile +import com.palantir.javapoet.JavaFile import com.squareup.wire.schema.Location import com.squareup.wire.schema.Profile import com.squareup.wire.schema.Schema diff --git a/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorTest.java b/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorTest.java index 10f51b4f91..af64d36d28 100644 --- a/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorTest.java +++ b/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorTest.java @@ -19,8 +19,8 @@ import static com.squareup.wire.schema.SchemaHelpersJvmKt.addFromTest; import static org.junit.Assert.fail; -import com.squareup.javapoet.JavaFile; -import com.squareup.javapoet.TypeSpec; +import com.palantir.javapoet.JavaFile; +import com.palantir.javapoet.TypeSpec; import com.squareup.wire.SchemaBuilder; import com.squareup.wire.schema.MessageType; import com.squareup.wire.schema.PruningRules; diff --git a/wire-java-generator/src/test/java/com/squareup/wire/java/JavaWithProfilesGenerator.kt b/wire-java-generator/src/test/java/com/squareup/wire/java/JavaWithProfilesGenerator.kt index 3bfd85053b..e7ee70322b 100644 --- a/wire-java-generator/src/test/java/com/squareup/wire/java/JavaWithProfilesGenerator.kt +++ b/wire-java-generator/src/test/java/com/squareup/wire/java/JavaWithProfilesGenerator.kt @@ -15,7 +15,7 @@ */ package com.squareup.wire.java -import com.squareup.javapoet.JavaFile +import com.palantir.javapoet.JavaFile import com.squareup.wire.schema.Location import com.squareup.wire.schema.Profile import com.squareup.wire.schema.Schema diff --git a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/AdapterConstant.kt b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/AdapterConstant.kt index 9149b3413e..6e9da9a0a8 100644 --- a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/AdapterConstant.kt +++ b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/AdapterConstant.kt @@ -15,7 +15,7 @@ */ package com.squareup.wire.schema -import com.squareup.javapoet.ClassName +import com.palantir.javapoet.ClassName import com.squareup.kotlinpoet.ClassName as KClassName /** diff --git a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Profile.kt b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Profile.kt index 1e83ff2fd6..fff57bd10b 100644 --- a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Profile.kt +++ b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Profile.kt @@ -15,8 +15,8 @@ */ package com.squareup.wire.schema -import com.squareup.javapoet.ClassName -import com.squareup.javapoet.TypeName +import com.palantir.javapoet.ClassName +import com.palantir.javapoet.TypeName import com.squareup.kotlinpoet.ClassName as KClassName import com.squareup.kotlinpoet.TypeName as KTypeName import com.squareup.wire.schema.internal.ProfileFileElement diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProfileLoaderTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProfileLoaderTest.kt index 22c3abfbdf..17a9a8689d 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProfileLoaderTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProfileLoaderTest.kt @@ -19,7 +19,7 @@ import assertk.assertThat import assertk.assertions.hasMessage import assertk.assertions.isEqualTo import assertk.assertions.isNull -import com.squareup.javapoet.ClassName +import com.palantir.javapoet.ClassName import com.squareup.wire.testing.add import com.squareup.wire.testing.addZip import java.io.IOException From 324f123c66e5e63eba6dba9de1f1d6fb8ed05333 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Thu, 10 Oct 2024 14:47:36 -0700 Subject: [PATCH 2/3] apiDump --- wire-java-generator/api/wire-java-generator.api | 14 +++++++------- wire-schema/api/wire-schema.api | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/wire-java-generator/api/wire-java-generator.api b/wire-java-generator/api/wire-java-generator.api index 67f01f7f1c..161e1ae379 100644 --- a/wire-java-generator/api/wire-java-generator.api +++ b/wire-java-generator/api/wire-java-generator.api @@ -1,15 +1,15 @@ public final class com/squareup/wire/java/JavaGenerator { - public fun abstractAdapterName (Lcom/squareup/wire/schema/ProtoType;)Lcom/squareup/javapoet/ClassName; + public fun abstractAdapterName (Lcom/squareup/wire/schema/ProtoType;)Lcom/palantir/javapoet/ClassName; public static fun builtInType (Lcom/squareup/wire/schema/ProtoType;)Z - public fun generateAdapterForCustomType (Lcom/squareup/wire/schema/Type;)Lcom/squareup/javapoet/TypeSpec; - public fun generateOptionType (Lcom/squareup/wire/schema/Extend;Lcom/squareup/wire/schema/Field;)Lcom/squareup/javapoet/TypeSpec; - public fun generateType (Lcom/squareup/wire/schema/Type;)Lcom/squareup/javapoet/TypeSpec; - public fun generatedTypeName (Lcom/squareup/wire/schema/ProtoMember;)Lcom/squareup/javapoet/ClassName; - public fun generatedTypeName (Lcom/squareup/wire/schema/Type;)Lcom/squareup/javapoet/ClassName; + public fun generateAdapterForCustomType (Lcom/squareup/wire/schema/Type;)Lcom/palantir/javapoet/TypeSpec; + public fun generateOptionType (Lcom/squareup/wire/schema/Extend;Lcom/squareup/wire/schema/Field;)Lcom/palantir/javapoet/TypeSpec; + public fun generateType (Lcom/squareup/wire/schema/Type;)Lcom/palantir/javapoet/TypeSpec; + public fun generatedTypeName (Lcom/squareup/wire/schema/ProtoMember;)Lcom/palantir/javapoet/ClassName; + public fun generatedTypeName (Lcom/squareup/wire/schema/Type;)Lcom/palantir/javapoet/ClassName; public static fun get (Lcom/squareup/wire/schema/Schema;)Lcom/squareup/wire/java/JavaGenerator; public fun isEnum (Lcom/squareup/wire/schema/ProtoType;)Z public fun schema ()Lcom/squareup/wire/schema/Schema; - public fun typeName (Lcom/squareup/wire/schema/ProtoType;)Lcom/squareup/javapoet/TypeName; + public fun typeName (Lcom/squareup/wire/schema/ProtoType;)Lcom/palantir/javapoet/TypeName; public fun withAndroid (Z)Lcom/squareup/wire/java/JavaGenerator; public fun withAndroidAnnotations (Z)Lcom/squareup/wire/java/JavaGenerator; public fun withBuildersOnly (Z)Lcom/squareup/wire/java/JavaGenerator; diff --git a/wire-schema/api/wire-schema.api b/wire-schema/api/wire-schema.api index 0cb97d53df..be713ab578 100644 --- a/wire-schema/api/wire-schema.api +++ b/wire-schema/api/wire-schema.api @@ -18,15 +18,15 @@ public abstract interface class com/squareup/wire/WireLogger$Factory : java/io/S public final class com/squareup/wire/schema/AdapterConstant { public static final field Companion Lcom/squareup/wire/schema/AdapterConstant$Companion; - public final field javaClassName Lcom/squareup/javapoet/ClassName; + public final field javaClassName Lcom/palantir/javapoet/ClassName; public final field kotlinClassName Lcom/squareup/kotlinpoet/ClassName; public final field memberName Ljava/lang/String; - public fun (Lcom/squareup/javapoet/ClassName;Lcom/squareup/kotlinpoet/ClassName;Ljava/lang/String;)V - public final fun component1 ()Lcom/squareup/javapoet/ClassName; + public fun (Lcom/palantir/javapoet/ClassName;Lcom/squareup/kotlinpoet/ClassName;Ljava/lang/String;)V + public final fun component1 ()Lcom/palantir/javapoet/ClassName; public final fun component2 ()Lcom/squareup/kotlinpoet/ClassName; public final fun component3 ()Ljava/lang/String; - public final fun copy (Lcom/squareup/javapoet/ClassName;Lcom/squareup/kotlinpoet/ClassName;Ljava/lang/String;)Lcom/squareup/wire/schema/AdapterConstant; - public static synthetic fun copy$default (Lcom/squareup/wire/schema/AdapterConstant;Lcom/squareup/javapoet/ClassName;Lcom/squareup/kotlinpoet/ClassName;Ljava/lang/String;ILjava/lang/Object;)Lcom/squareup/wire/schema/AdapterConstant; + public final fun copy (Lcom/palantir/javapoet/ClassName;Lcom/squareup/kotlinpoet/ClassName;Ljava/lang/String;)Lcom/squareup/wire/schema/AdapterConstant; + public static synthetic fun copy$default (Lcom/squareup/wire/schema/AdapterConstant;Lcom/palantir/javapoet/ClassName;Lcom/squareup/kotlinpoet/ClassName;Ljava/lang/String;ILjava/lang/Object;)Lcom/squareup/wire/schema/AdapterConstant; public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I public fun toString ()Ljava/lang/String; @@ -562,7 +562,7 @@ public final class com/squareup/wire/schema/Profile { public fun (Ljava/util/List;)V public synthetic fun (Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun getAdapter (Lcom/squareup/wire/schema/ProtoType;)Lcom/squareup/wire/schema/AdapterConstant; - public final fun javaTarget (Lcom/squareup/wire/schema/ProtoType;)Lcom/squareup/javapoet/TypeName; + public final fun javaTarget (Lcom/squareup/wire/schema/ProtoType;)Lcom/palantir/javapoet/TypeName; public final fun kotlinTarget (Lcom/squareup/wire/schema/ProtoType;)Lcom/squareup/kotlinpoet/TypeName; } From 962225b7a1a47619e578fe0aa1eb21e3483fb7bc Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Thu, 10 Oct 2024 16:53:01 -0700 Subject: [PATCH 3/3] wire-codegen-sample --- .../java/com/squareup/wire/sample/ServiceGenerator.java | 8 ++++---- .../java/com/squareup/wire/sample/ServiceGeneratorTest.kt | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/wire-codegen-sample/src/main/java/com/squareup/wire/sample/ServiceGenerator.java b/samples/wire-codegen-sample/src/main/java/com/squareup/wire/sample/ServiceGenerator.java index 7b0fa5d144..4632a12e25 100644 --- a/samples/wire-codegen-sample/src/main/java/com/squareup/wire/sample/ServiceGenerator.java +++ b/samples/wire-codegen-sample/src/main/java/com/squareup/wire/sample/ServiceGenerator.java @@ -18,10 +18,10 @@ import static javax.lang.model.element.Modifier.ABSTRACT; import static javax.lang.model.element.Modifier.PUBLIC; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.MethodSpec; -import com.squareup.javapoet.TypeName; -import com.squareup.javapoet.TypeSpec; +import com.palantir.javapoet.ClassName; +import com.palantir.javapoet.MethodSpec; +import com.palantir.javapoet.TypeName; +import com.palantir.javapoet.TypeSpec; import com.squareup.wire.java.JavaGenerator; import com.squareup.wire.schema.ProtoType; import com.squareup.wire.schema.Rpc; diff --git a/samples/wire-codegen-sample/src/test/java/com/squareup/wire/sample/ServiceGeneratorTest.kt b/samples/wire-codegen-sample/src/test/java/com/squareup/wire/sample/ServiceGeneratorTest.kt index f8e43ceb80..42f5fd8c7d 100644 --- a/samples/wire-codegen-sample/src/test/java/com/squareup/wire/sample/ServiceGeneratorTest.kt +++ b/samples/wire-codegen-sample/src/test/java/com/squareup/wire/sample/ServiceGeneratorTest.kt @@ -15,8 +15,8 @@ */ package com.squareup.wire.sample -import com.squareup.javapoet.JavaFile -import com.squareup.javapoet.TypeSpec +import com.palantir.javapoet.JavaFile +import com.palantir.javapoet.TypeSpec import com.squareup.wire.java.JavaGenerator import com.squareup.wire.schema.Location import com.squareup.wire.schema.Schema