Skip to content

Commit

Permalink
Propagate @SuppressWarnings on @Instrument types (#1976)
Browse files Browse the repository at this point in the history
Propagate @SuppressWarnings on @Instrument types
  • Loading branch information
schlosna authored Jul 8, 2024
1 parent e80ad5b commit e09cc16
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1976.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: Propagate @SuppressWarnings on @Instrument types
links:
- https://github.com/palantir/tritium/pull/1976
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -188,11 +189,17 @@ public List<FieldSpec> additionalFields(AdditionalFieldsArguments arguments) {

@Override
public void customize(CustomizeArguments arguments, TypeSpec.Builder generatedType) {
if (isDeprecated(arguments.type().type())) {
TypeElement type = arguments.type().type();
if (isDeprecated(type)) {
generatedType.addAnnotation(Deprecated.class);
}

TypeName annotatedTypeName = TypeName.get(arguments.type().type().asType());
SuppressWarnings suppressWarnings = type.getAnnotation(SuppressWarnings.class);
if (suppressWarnings != null) {
generatedType.addAnnotation(AnnotationSpec.get(suppressWarnings));
}

TypeName annotatedTypeName = TypeName.get(type.asType());
List<AnnotatedTypeMethod> instrumentedMethods = instrumentedMethods(arguments.type());

if (!instrumentedMethods.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.tritium.examples;

import com.palantir.tritium.annotations.Instrument;

@Instrument
@SuppressWarnings("deprecation")
public interface DeprecatedType {

Foo foo();

@Deprecated
interface Foo {
String bar();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.palantir.tritium.examples.DelegateToRunnable;
import com.palantir.tritium.examples.DelegateToRunnableMethod;
import com.palantir.tritium.examples.DeprecatedMethod;
import com.palantir.tritium.examples.DeprecatedType;
import com.palantir.tritium.examples.Empty;
import com.palantir.tritium.examples.HasDefaultMethod;
import com.palantir.tritium.examples.HasToString;
Expand Down Expand Up @@ -114,6 +115,11 @@ public void testDeprecatedInterface() {
assertTestFileCompileAndMatches(TEST_CLASSES_BASE_DIR, com.palantir.tritium.examples.DeprecatedInterface.class);
}

@Test
public void testDeprecatedType() {
assertTestFileCompileAndMatches(TEST_CLASSES_BASE_DIR, DeprecatedType.class);
}

@Test
public void testEmptyInterface() {
assertTestFileCompileAndMatches(TEST_CLASSES_BASE_DIR, Empty.class);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e09cc16

Please sign in to comment.