Skip to content

Commit

Permalink
Tritium uses the Palantir fork of javapoet (#2085)
Browse files Browse the repository at this point in the history
Tritium uses the Palantir fork of javapoet
  • Loading branch information
carterkozak authored Dec 6, 2024
1 parent e242819 commit c022bff
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 46 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-2085.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Tritium uses the Palantir fork of javapoet
links:
- https://github.com/palantir/tritium/pull/2085
4 changes: 2 additions & 2 deletions tritium-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@

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;
import com.palantir.tritium.event.Handlers;
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;
Expand Down Expand Up @@ -225,8 +225,9 @@ public void customize(CustomizeArguments arguments, TypeSpec.Builder generatedTy
generatedType.addStaticBlock(staticBlock.build());
}

List<TypeVariableName> 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))
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -267,7 +268,7 @@ public void customize(CustomizeArguments arguments, TypeSpec.Builder generatedTy
private static List<AnnotatedTypeMethod> instrumentedMethods(AnnotatedType type) {
return type.methods().stream()
.filter(method -> isInstrumented(type, method))
.collect(Collectors.toUnmodifiableList());
.toList();
}

private static boolean isInstrumented(DelegateMethodArguments arguments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,35 @@

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 {

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;
}

static List<TypeName> typeParameters(TypeName typeName) {
if (typeName instanceof ParameterizedTypeName) {
ParameterizedTypeName parameterized = (ParameterizedTypeName) typeName;
return parameterized.typeArguments;
return parameterized.typeArguments();
}
return List.of();
}
Expand Down
12 changes: 6 additions & 6 deletions versions.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c022bff

Please sign in to comment.