From c022bff350b73125b892002cdc535a10c70aad1c Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Fri, 6 Dec 2024 11:14:30 -0500 Subject: [PATCH] Tritium uses the Palantir fork of javapoet (#2085) Tritium uses the Palantir fork of javapoet --- changelog/@unreleased/pr-2085.v2.yml | 5 +++ tritium-processor/build.gradle | 4 +- .../com/palantir/tritium/processor/Names.java | 16 ++++---- .../processor/TritiumAnnotationProcessor.java | 2 +- .../TritiumAnnotationProcessorStrategy.java | 37 ++++++++++--------- .../palantir/tritium/processor/TypeNames.java | 19 +++++----- versions.lock | 12 +++--- versions.props | 4 +- 8 files changed, 53 insertions(+), 46 deletions(-) create mode 100644 changelog/@unreleased/pr-2085.v2.yml diff --git a/changelog/@unreleased/pr-2085.v2.yml b/changelog/@unreleased/pr-2085.v2.yml new file mode 100644 index 000000000..5f45cd153 --- /dev/null +++ b/changelog/@unreleased/pr-2085.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Tritium uses the Palantir fork of javapoet + links: + - https://github.com/palantir/tritium/pull/2085 diff --git a/tritium-processor/build.gradle b/tritium-processor/build.gradle index 1a567c722..e090b4fdd 100644 --- a/tritium-processor/build.gradle +++ b/tritium-processor/build.gradle @@ -7,8 +7,8 @@ dependencies { api project(':tritium-registry') implementation 'com.google.guava:guava' - implementation 'com.palantir.delegate.processors:delegate-processors' - implementation 'com.squareup:javapoet' + implementation 'com.palantir.delegate.processors:delegate-processor' + implementation 'com.palantir.javapoet:javapoet' testImplementation 'com.google.testing.compile:compile-testing' testImplementation 'org.assertj:assertj-core' diff --git a/tritium-processor/src/main/java/com/palantir/tritium/processor/Names.java b/tritium-processor/src/main/java/com/palantir/tritium/processor/Names.java index 203f50e94..fa679c80d 100644 --- a/tritium-processor/src/main/java/com/palantir/tritium/processor/Names.java +++ b/tritium-processor/src/main/java/com/palantir/tritium/processor/Names.java @@ -19,12 +19,12 @@ import com.google.common.base.CaseFormat; import com.google.common.hash.Hasher; import com.google.common.hash.Hashing; -import com.squareup.javapoet.ArrayTypeName; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.ParameterizedTypeName; -import com.squareup.javapoet.TypeName; -import com.squareup.javapoet.TypeVariableName; -import com.squareup.javapoet.WildcardTypeName; +import com.palantir.javapoet.ArrayTypeName; +import com.palantir.javapoet.ClassName; +import com.palantir.javapoet.ParameterizedTypeName; +import com.palantir.javapoet.TypeName; +import com.palantir.javapoet.TypeVariableName; +import com.palantir.javapoet.WildcardTypeName; import java.nio.charset.StandardCharsets; import java.util.stream.Stream; import javax.lang.model.element.ExecutableElement; @@ -61,14 +61,14 @@ private static String simpleName(TypeName input) { } if (input instanceof ParameterizedTypeName) { ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) input; - return simpleName(parameterizedTypeName.rawType); + return simpleName(parameterizedTypeName.rawType()); } if (input instanceof WildcardTypeName || input instanceof TypeVariableName) { return Object.class.getSimpleName(); } if (input instanceof ArrayTypeName) { ArrayTypeName arrayTypeName = (ArrayTypeName) input; - return simpleName(arrayTypeName.componentType) + "[]"; + return simpleName(arrayTypeName.componentType()) + "[]"; } throw new IllegalArgumentException("Unknown type-name: " + input); } diff --git a/tritium-processor/src/main/java/com/palantir/tritium/processor/TritiumAnnotationProcessor.java b/tritium-processor/src/main/java/com/palantir/tritium/processor/TritiumAnnotationProcessor.java index 34ece0dcd..28cc90fda 100644 --- a/tritium-processor/src/main/java/com/palantir/tritium/processor/TritiumAnnotationProcessor.java +++ b/tritium-processor/src/main/java/com/palantir/tritium/processor/TritiumAnnotationProcessor.java @@ -16,7 +16,7 @@ package com.palantir.tritium.processor; -import com.palantir.delegate.processors.DelegateProcessor; +import com.palantir.delegate.processor.DelegateProcessor; public final class TritiumAnnotationProcessor extends DelegateProcessor { diff --git a/tritium-processor/src/main/java/com/palantir/tritium/processor/TritiumAnnotationProcessorStrategy.java b/tritium-processor/src/main/java/com/palantir/tritium/processor/TritiumAnnotationProcessorStrategy.java index daa1161ef..564c6620d 100644 --- a/tritium-processor/src/main/java/com/palantir/tritium/processor/TritiumAnnotationProcessorStrategy.java +++ b/tritium-processor/src/main/java/com/palantir/tritium/processor/TritiumAnnotationProcessorStrategy.java @@ -16,10 +16,20 @@ package com.palantir.tritium.processor; -import com.palantir.delegate.processors.AnnotatedType; -import com.palantir.delegate.processors.AnnotatedTypeMethod; -import com.palantir.delegate.processors.DelegateProcessorStrategy; -import com.palantir.delegate.processors.LocalVariable; +import com.palantir.delegate.processor.AnnotatedType; +import com.palantir.delegate.processor.AnnotatedTypeMethod; +import com.palantir.delegate.processor.DelegateProcessorStrategy; +import com.palantir.delegate.processor.LocalVariable; +import com.palantir.javapoet.AnnotationSpec; +import com.palantir.javapoet.ClassName; +import com.palantir.javapoet.CodeBlock; +import com.palantir.javapoet.FieldSpec; +import com.palantir.javapoet.MethodSpec; +import com.palantir.javapoet.ParameterSpec; +import com.palantir.javapoet.ParameterizedTypeName; +import com.palantir.javapoet.TypeName; +import com.palantir.javapoet.TypeSpec; +import com.palantir.javapoet.TypeVariableName; import com.palantir.tritium.annotations.Instrument; import com.palantir.tritium.annotations.internal.InstrumentationBuilder; import com.palantir.tritium.api.event.InstrumentationFilter; @@ -27,22 +37,12 @@ import com.palantir.tritium.event.InvocationContext; import com.palantir.tritium.event.InvocationEventHandler; import com.palantir.tritium.metrics.registry.TaggedMetricRegistry; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.CodeBlock; -import com.squareup.javapoet.FieldSpec; -import com.squareup.javapoet.MethodSpec; -import com.squareup.javapoet.ParameterSpec; -import com.squareup.javapoet.ParameterizedTypeName; -import com.squareup.javapoet.TypeName; -import com.squareup.javapoet.TypeSpec; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; @@ -225,8 +225,9 @@ public void customize(CustomizeArguments arguments, TypeSpec.Builder generatedTy generatedType.addStaticBlock(staticBlock.build()); } + List typeVariables = generatedType.build().typeVariables(); generatedType.addMethod(MethodSpec.methodBuilder("builder") - .addTypeVariables(generatedType.typeVariables) + .addTypeVariables(typeVariables) .addModifiers(Modifier.PUBLIC, Modifier.STATIC) .returns(ParameterizedTypeName.get( ClassName.get(InstrumentationBuilder.class), arguments.delegateTypeName(), annotatedTypeName)) @@ -241,7 +242,7 @@ public void customize(CustomizeArguments arguments, TypeSpec.Builder generatedTy arguments.generatedTypeName()) .build()); generatedType.addMethod(MethodSpec.methodBuilder("trace") - .addTypeVariables(generatedType.typeVariables) + .addTypeVariables(typeVariables) .addModifiers(Modifier.PUBLIC, Modifier.STATIC) .returns(annotatedTypeName) .addParameter(ParameterSpec.builder(arguments.delegateTypeName(), "delegate") @@ -253,7 +254,7 @@ public void customize(CustomizeArguments arguments, TypeSpec.Builder generatedTy arguments.generatedTypeName()) .build()); generatedType.addMethod(MethodSpec.methodBuilder("instrument") - .addTypeVariables(generatedType.typeVariables) + .addTypeVariables(typeVariables) .addModifiers(Modifier.PUBLIC, Modifier.STATIC) .returns(annotatedTypeName) .addParameter(ParameterSpec.builder(arguments.delegateTypeName(), "delegate") @@ -267,7 +268,7 @@ public void customize(CustomizeArguments arguments, TypeSpec.Builder generatedTy private static List instrumentedMethods(AnnotatedType type) { return type.methods().stream() .filter(method -> isInstrumented(type, method)) - .collect(Collectors.toUnmodifiableList()); + .toList(); } private static boolean isInstrumented(DelegateMethodArguments arguments) { diff --git a/tritium-processor/src/main/java/com/palantir/tritium/processor/TypeNames.java b/tritium-processor/src/main/java/com/palantir/tritium/processor/TypeNames.java index 694a39eff..540a8bceb 100644 --- a/tritium-processor/src/main/java/com/palantir/tritium/processor/TypeNames.java +++ b/tritium-processor/src/main/java/com/palantir/tritium/processor/TypeNames.java @@ -16,11 +16,12 @@ package com.palantir.tritium.processor; -import com.squareup.javapoet.ArrayTypeName; -import com.squareup.javapoet.ParameterizedTypeName; -import com.squareup.javapoet.TypeName; -import com.squareup.javapoet.TypeVariableName; -import com.squareup.javapoet.WildcardTypeName; +import com.palantir.javapoet.ArrayTypeName; +import com.palantir.javapoet.ClassName; +import com.palantir.javapoet.ParameterizedTypeName; +import com.palantir.javapoet.TypeName; +import com.palantir.javapoet.TypeVariableName; +import com.palantir.javapoet.WildcardTypeName; import java.util.List; final class TypeNames { @@ -28,14 +29,14 @@ final class TypeNames { static TypeName erased(TypeName input) { if (input instanceof ParameterizedTypeName) { ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) input; - return parameterizedTypeName.rawType; + return parameterizedTypeName.rawType(); } if (input instanceof WildcardTypeName || input instanceof TypeVariableName) { - return TypeName.OBJECT; + return ClassName.OBJECT; } if (input instanceof ArrayTypeName) { ArrayTypeName arrayTypeName = (ArrayTypeName) input; - return ArrayTypeName.of(erased(arrayTypeName.componentType)); + return ArrayTypeName.of(erased(arrayTypeName.componentType())); } return input; } @@ -43,7 +44,7 @@ static TypeName erased(TypeName input) { static List typeParameters(TypeName typeName) { if (typeName instanceof ParameterizedTypeName) { ParameterizedTypeName parameterized = (ParameterizedTypeName) typeName; - return parameterized.typeArguments; + return parameterized.typeArguments(); } return List.of(); } diff --git a/versions.lock b/versions.lock index adcd9e497..b944a336e 100644 --- a/versions.lock +++ b/versions.lock @@ -1,16 +1,16 @@ # Run ./gradlew writeVersionsLocks to regenerate this file com.github.ben-manes.caffeine:caffeine:3.1.8 (1 constraints: 0e050536) -com.google.auto:auto-common:1.2.2 (2 constraints: 5a289c27) +com.google.auto:auto-common:1.2.2 (2 constraints: e727c4fc) com.google.auto.service:auto-service-annotations:1.1.1 (1 constraints: 0505f435) com.google.code.findbugs:jsr305:3.0.2 (4 constraints: 5c3586ed) com.google.errorprone:error_prone_annotations:2.28.0 (8 constraints: fb70485c) com.google.guava:failureaccess:1.0.2 (1 constraints: 150ae2b4) -com.google.guava:guava:33.3.1-jre (6 constraints: 745bc47d) +com.google.guava:guava:33.3.1-jre (6 constraints: 025bd61a) com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918) com.google.j2objc:j2objc-annotations:3.0.0 (1 constraints: 150aeab4) -com.palantir.delegate.processors:delegate-processors:1.2.0 (1 constraints: 0505f635) -com.palantir.goethe:goethe:0.13.0 (1 constraints: 731666f3) -com.palantir.javapoet:javapoet:0.1.0 (1 constraints: c10b63eb) +com.palantir.delegate.processors:delegate-processor:2.0.0 (1 constraints: 0405f535) +com.palantir.goethe:goethe:0.14.0 (1 constraints: 011643da) +com.palantir.javapoet:javapoet:0.5.0 (3 constraints: 9726a5be) com.palantir.jvm.diagnostics:jvm-diagnostics:0.5.0 (1 constraints: 0705fa35) com.palantir.nylon:nylon-threads:0.4.0 (1 constraints: 0605f735) com.palantir.safe-logging:logger:3.7.0 (3 constraints: f51f7222) @@ -20,7 +20,7 @@ com.palantir.safe-logging:preconditions:3.7.0 (4 constraints: 2334c4ac) com.palantir.safe-logging:safe-logging:3.7.0 (7 constraints: a9622139) com.palantir.tracing:tracing:6.20.0 (1 constraints: 3a054b3b) com.palantir.tracing:tracing-api:6.20.0 (2 constraints: 0912eb17) -com.squareup:javapoet:1.13.0 (3 constraints: 9e27444d) +com.squareup:javapoet:1.13.0 (1 constraints: f50b65f7) io.dropwizard.metrics:metrics-core:4.2.29 (2 constraints: 37143f89) io.dropwizard.metrics:metrics-jvm:4.2.29 (1 constraints: 43054a3b) net.bytebuddy:byte-buddy:1.15.10 (4 constraints: c82b2985) diff --git a/versions.props b/versions.props index 2d8e66828..6b918b177 100644 --- a/versions.props +++ b/versions.props @@ -6,12 +6,12 @@ com.google.auto.service:* = 1.1.1 com.google.code.findbugs:* = 3.0.2 com.google.guava:guava = 33.3.1-jre com.google.testing.compile:* = 0.21.0 -com.palantir.delegate.processors:* = 1.2.0 +com.palantir.delegate.processors:* = 2.0.0 com.palantir.jvm.diagnostics:* = 0.5.0 com.palantir.nylon:* = 0.4.0 com.palantir.safe-logging:* = 3.7.0 com.palantir.tracing:* = 6.20.0 -com.squareup:javapoet = 1.13.0 +com.palantir.javapoet:javapoet = 0.5.0 com.squareup.okhttp3:* = 4.12.0 # Keep major.minor metrics version in sync with Apache Spark io.dropwizard.metrics:* = 4.2.29