Skip to content

Add the ability to access type annotations for Java #3114

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

Closed
wants to merge 3 commits into from

Conversation

jrhee17
Copy link
Contributor

@jrhee17 jrhee17 commented Mar 24, 2025

#2553 had added the ability to access field annotations in java.

In our use-case, we would like to annotate arbitrary types and re-use it without explicitly re-annotating each field.

e.g.

struct should_mask {
} (a = "b")

struct struct_1 {
  1: should_mask field;
}

struct struct_2 {
  1: should_mask field;
}

instead of

struct should_mask {
}

struct struct_1 {
  1: should_mask field (a = "b")
}

struct struct_2 {
  1: should_mask field (a = "b")
}

I would like to propose that FieldMetaData#getFieldAnnotations returns annotations on types as well to achieve this.

Misc1) If it feels safer to hide this change behind an option (i.e. type_annotations_as_metadata_), then I can also make this change

  • Did you create an Apache Jira ticket? (Request account here, not required for trivial changes)
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?

@jrhee17 jrhee17 changed the title Add type annotations for java Add the ability to access type annotations for Java Mar 24, 2025
@Jens-G Jens-G added the java Pull requests that update Java code label Mar 26, 2025
@Jens-G
Copy link
Member

Jens-G commented May 19, 2025

CI was cancelled, could you "force push" please?

some otherwise unrelevant change to force another build
@Jens-G
Copy link
Member

Jens-G commented Jun 7, 2025

Hi @jrhee17
could you fix that please?

* What went wrong:
Execution failed for task ':spotlessJavaCheck'.
> The following files had format violations:
      src/test/java/org/apache/thrift/TestAnnotationMetadata.java
          @@ -67,7 +67,9 @@
           ····}
           ····{
           ······Map<String,·String>·metadata·=
          -··············structMetaDataMap.get(OneOfEachBeansWithAnnotations._Fields.TYPEDEF_META).getFieldAnnotations();
          +··········structMetaDataMap
          +··············.get(OneOfEachBeansWithAnnotations._Fields.TYPEDEF_META)
          +··············.getFieldAnnotations();
           ······Map<String,·String>·expected·=·new·HashMap<>();
           ······expected.put("a",·"b");
           ······expected.put("c",·"d");
  Run './gradlew :spotlessApply' to fix these violations.

@Jens-G Jens-G self-requested a review June 7, 2025 21:20
Copy link
Member

@Jens-G Jens-G left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI spotlessJavaCheck failed

@jrhee17
Copy link
Contributor Author

jrhee17 commented Jun 9, 2025

Sorry about the late follow-up, updated

@Jens-G Jens-G closed this in f0f72d8 Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java Pull requests that update Java code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants