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

Add all interface's class-level annotations to its DefaultImpls class. #161

Merged

Conversation

fzhinkin
Copy link
Collaborator

Fixes #155

@fzhinkin fzhinkin force-pushed the 155-take-defaultimpls-annotations-from-original-interface branch from 27424fd to 493ba62 Compare December 14, 2023 16:34
@fzhinkin fzhinkin marked this pull request as ready for review December 14, 2023 17:03
@fzhinkin fzhinkin requested a review from ilya-g December 14, 2023 17:03
/**
* For synthetic $DefaultImpls classes copy annotations from the original interface
*/
val inheritedAnnotations = mutableListOf<AnnotationNode>().apply {
Copy link
Member

Choose a reason for hiding this comment

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

Could you please check if it is possible to consolidate annotation "inheritance" in a single place?

AFAIR we have a multitude of such logic, some examples are:

  1. PublishedApi and methods with default arguments
  2. Regular annotations (e.g. @PrivateApi) and methods with default arguments
  3. Nested objects/companions and @JvmStatic
  4. Companions and INSTANCE
  5. Fields and accessors

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems like now there are only 3 cases when we're "inheriting" ("propagating" would fit better, I guess) annotations for an entity from some other entities:

  • for fields, we're taking annotations from accessors (and with Add all Companion class' annotations to corresponding Companion field. #162 we'll propagate companion class' annotations to the corresponding field);
  • for methods, we're taking annotations from other property accessors and fields and also from a regular method declaration if the current one is "$default";
  • for classes, if a class is "$DefaultImpls", we're taking annotations from the "original" class.

Currently, the logic is local w.r.t. the entity's processing scope (i.e. we're collecting annotations for a field when processing a field, for a method when processing that method and so on) and I'm not sure if we could do significantly better.
There's always an option to rewrite all the processing logic to have a single object encompassing the whole context (instead of tossing parts of that context across various extension functions) and have (still) separate methods responsible for annotation extraction there, but I think it is out of this PR's scope.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for taking a look!

@qwwdfsad qwwdfsad self-requested a review January 18, 2024 16:42
@fzhinkin fzhinkin merged commit 1d7505b into master Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants