title: Getting a list of accessible methods for a given class via reflection
body: <p>Is there a way to get a list of methods that would be accessible (not necessarily public) by a given class? The code in question will be in a completely different class.</p>
  
  <p>Example:</p>
  
  <pre><code>public class A {
    public void methodA1();
    protected void methodA2();
    void methodA3();
    private void methodA4();
  }
  
  public class B extends A {
    public void methodB1();
    protected void methodB2();
    private void methodB3();
  }
  </code></pre>
  
  <p>For class <code>B</code> I'd like to get:</p>
  
  <ul>
  <li>all of its own methods</li>
  <li><code>methodA1</code> and <code>methodA2</code> from class <code>A</code></li>
  <li><code>methodA3</code> if and only if class <code>B</code> is in the same package as <code>A</code></li>
  </ul>
  
  <p><code>methodA4</code> should never be included in results because it's inaccessible to class <code>B</code>. To clarify once again, code that needs to find and return the above methods will be in a completely different class / package.</p>
  
  <p>Now, <code>Class.getMethods()</code> only returns public methods and thus won't do what I want; <code>Class.getDeclaredMethods()</code> only returns methods for current class. While I can certainly use the latter and walk the class hierarchy up checking the visibility rules manually, I'd rather not if there's a better solution. Am I missing something glaringly obvious here? </p>