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

Refactor internal methods to avoid duplicate JVM signature #621

Merged
merged 2 commits into from
Oct 31, 2023
Merged

Conversation

jbarr21
Copy link
Contributor

@jbarr21 jbarr21 commented Oct 31, 2023

ViewRouter extends from Router & both have a method: internal fun onSaveInstanceStateInternal(outState: Bundle).
In order to avoid exposing this method to non-RIB-class subclasses, the method was duplicated each Router class w/ internal visibility. But, starting in K2 this fails with duplicate JVM signature, so this PR removes the ViewRouter copy & makes the Router copy public but requiring a core annotation.

Copy link
Contributor

@psteiger psteiger left a comment

Choose a reason for hiding this comment

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

I propose a different approach:

  1. Completely kill ViewRouter.saveInstanceStateInternal -- it seems the only reason it existed was to force a friend-module visibility by duplicating the method name in a class in the module that will access it -- kinda hacky.
  2. Make Router.saveInstanceStateInternal public, but annotate it with @CoreFriendModuleApi.

RibActivity now can access Router.saveInstanceStateInternal because rib-android is a core-friend module (opt-in from Gradle)

Now, external Kotlin consumers can't just @OptIn(CoreFriendModuleApi::class) because it is an internal annotation. So it remains inaccessible to them.

External Java consumers can access it, but that's the same issue with just internal visibility anyway -- it's public but mangled.

See #618

@psteiger
Copy link
Contributor

Let me know what you think of the suggested approach -- I think it's being pushed by JetBrains own libraries to handle the "internal to friend modules" visibility issue and I'm pushing for the same here.

@jbarr21
Copy link
Contributor Author

jbarr21 commented Oct 31, 2023

I like it, thanks for sharing. Definitely feels better, too

@jbarr21 jbarr21 changed the title Rename internal method to avoid duplicate JVM signature Refactor internal methods to avoid duplicate JVM signature Oct 31, 2023
@jbarr21 jbarr21 merged commit 69903fd into main Oct 31, 2023
3 checks passed
@jbarr21 jbarr21 deleted the jb/k2-fix branch October 31, 2023 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants