Take hidden API into account during getDeclaredMethod()

Generics make it possible for two methods to have the same name and list
of parameters but differ in their return type. Class.getDeclaredMethod()
does not allow callers to specify the type, so either of the matching
methods can be returned (ART will prefer the non-synthetic one).

However, Class::GetDeclaredMethodInternal() did not use to take hidden API
into account and could return a hidden method, despite a non-hidden one
being available. The reflective call would then reject the method and
throw NoSuchMethodException.

This patch modifies Class:GetDeclaredMethodInternal() to consider:
(a) hidden/non-hidden
(b) virtual/direct
(c) synthetic/non-synthetic
in that decreasing order of importance and pick the best matching
method. The hiddenness checks are performed with AccessMethod::kNone
so as to not trigger warnings. A hidden method may still be returned and
the caller should do the access check again with the appropriate
AccessMethod.

Bug: 122291025
Test: art/test.py -r -t 690-hiddenapi-same-name-methods
Change-Id: Iaee780c1e87f5587f51e24b517b2b37101c729e3
18 files changed