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

Proposal: VisibleForAccessors #765

Closed
ZacSweers opened this issue Oct 8, 2017 · 5 comments
Closed

Proposal: VisibleForAccessors #765

ZacSweers opened this issue Oct 8, 2017 · 5 comments

Comments

@ZacSweers
Copy link

On android we have method limits, and one means of mitigating them is to avoid synthetic accessor methods. A downside of this would be that sometimes you're left making certain things package-local when you'd normally make them private. What would you think of an annotation like @VisibleForAccessors(otherwise = PRIVATE)? Similar to @VisibleForTesting, but to enforce these are treated the same way as otherwise (whose value could default to PRIVATE) during compilation,

@ZacSweers
Copy link
Author

An example: uber/AutoDispose#103

@NightlyNexus
Copy link
Contributor

There is an Android Lint rule for @RestrictTo, as you know, but this proposal may be handy for non-Android libraries.

My personal experience is that Java's private keyword is useless noise in libraries and all feature-package organized code.
@VisibleForAccessors(otherwise = PRIVATE) would also be a lot of noise for little clarity or other benefit, in my opinion.

However, an annotation like this would be handy to apply to packages in Java libraries that organize some implementation details in separate packages like internal, so they could restrict consumers from using code not intended to be part of the API.

@JakeWharton
Copy link
Contributor

Dupe of #537

@JakeWharton
Copy link
Contributor

Or related to, at least

@bangarharshit
Copy link
Contributor

bangarharshit commented Feb 18, 2018

Error-Prone already has a check for RestrictTo RestrictToEnforcer.

There is also a RestricedApiChecker which enforces whitelisting on some path.

It can be very verbose and is only true for methods.

A similar test can be added to this suit. I can send a PR if the error-prone team is ok about the check.

This issue can then be closed in favor of #537.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants