Repository navigation
Replies: 1 comment 3 replies
|
you can also test the types of the parameters boolean isOverridden = method.getOwner().getAllRawInterfaces()
.stream()
.anyMatch(c -> c.tryGetMethod(
method.getName(),
getTypeNames(method.getParameters())
).isPresent()); |
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I'm trying to implement a rule which detects if a method can be made private. It checks, if a method is only called from the same class, and doesn't have a couple of annotations, which marks the method as called using reflection - like @VisibleForTesting,@post,@get, etc This works great, unless that method is public, because it overrides an interface or parent class method currently this fails, I've tried improve the detection, however, the best I could find, is to find a function in a parent class or interface, with matching name, and matching number of parameters. So if I have a
Both apply method would be accepted, as correct - even though, the second could be made into private (or deleted).
Unfortunately I couldn't find an easy way to handle function overriding with generic parameters. (I know, this is a hard problem even for the compiler), but maybe, someone already tried to do something, and could suggest the perfect solution?
Otherwise, I can contribute my solution, which only matches based on name and function arguments, if someone is interested
All reactions