Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Palantir's JavaPoet #3142

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions wire-java-generator/api/wire-java-generator.api
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions wire-schema/api/wire-schema.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (Lcom/squareup/javapoet/ClassName;Lcom/squareup/kotlinpoet/ClassName;Ljava/lang/String;)V
public final fun component1 ()Lcom/squareup/javapoet/ClassName;
public fun <init> (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;
Expand Down Expand Up @@ -562,7 +562,7 @@ public final class com/squareup/wire/schema/Profile {
public fun <init> (Ljava/util/List;)V
public synthetic fun <init> (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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down