-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 isVisibleFrom and isVisibleFromSubclass to Visibility #227
base: main
Are you sure you want to change the base?
Conversation
I didn't know where to put those 2 methods, so I put them on |
So, the problem is that these methods guarantee way more than they actually provide. For classes, you have to account for nesting and the visibility of enclosing types. For members, protected has to worry about inheritance. In #226 you pointed to the relevant portions of the JLS, but AFAICT didn't account for most of the bullets therein - or at least not in a way that makes this generally applicable to |
The visibility of the enclosing type is handled with For TL;DR: I believe the methods, as proposed here, cover 99% of use-cases. Maybe we could enhance the javadoc to be more explicit about the unsupported edge-cases? (also note that the second argument is a Let's review the bullets one by one if you don't mind:
That's the
This is the
Array types aren't represented as
This is the
Same as above.
This case isn't handled, but should never happen in practice in an annotation processor: you cannot have an So now for the
This is the rule that users of the API should follow to determine which one of the two methods they should call. All the bullets in §6.6.2 would help the user determine which method to call depending on their use-case, as access will depend on which code you're generating that would possibly reference the target element. For example, when you have an In many cases, you won't have an |
* Returns whether the given element is visible from another element in the given package, | ||
* assuming that other element is a subclass (or a member of a subclass) of the former (or | ||
* its enclosing type). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being a subclass doesn't guarantee protected
access. If the element being accessed is a constructor or an instance method, it is only accessible from within the same instance. I'm not sure how to capture that here. Maybe just give in and actually mention protected
.
Fixes #226