Add isVisibleFrom and isVisibleFromSubclass to Visibility#227
Add isVisibleFrom and isVisibleFromSubclass to Visibility#227tbroyer wants to merge 1 commit intogoogle:mainfrom
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 |
There was a problem hiding this comment.
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