title: JAVA - how to print trace of methods/objects used from an external jar
body: <p>I'm currently testing api's that are given to us in a jar.
  I am attempting to get a 'coverage' or list of the jar-methods and objects that we have touched or that at least our source code references.</p>
  
  <p>What we have or will have available is a text format of "here is a list of API's" </p>
  
  <p>And we need to cross reference our own application to ensure we are covering the API's listed.</p>
  
  <p>...</p>
  
  <p>Here's a simplified example... Below I listed an example of the external code available from the jar, and the code we have using those APIs.</p>
  
  <p>-- EXTERNAL_USE_CLASS -- MOCKS the external JAR with public API's that we need to cover</p>
  
  <pre><code>package external_api;
  
  public class EXTERNAL_USE_CLASS {
      String myString;
      Integer myInteger;
      Boolean has_ran;
      public EXTERNAL_USE_CLASS() {
          myString = "initial_string";
          myInteger = 4;
          has_ran = false;
      }
      public String getMyString() {
          return myString;
      }
      public void setMyString(String myString) {
          this.myString = myString;
      }
      public Integer getMyInteger() {
          return myInteger;
      }
      public void setMyInteger(Integer myInteger) {
          this.myInteger = myInteger;
      }
      public Boolean getHas_ran() {
          return has_ran;
      }
      public void setHas_ran(Boolean has_ran) {
          this.has_ran = has_ran;
      }
  }
  </code></pre>
  
  <p>My project will import the above as a jar and add it to the build path.
  What my code will do, is something like this:</p>
  
  <p>UseExtJar -- mocks our test application using the external jars objects/mathods</p>
  
  <pre><code>import external_api.EXTERNAL_USE_CLASS;
  
  public class UseExtJar {
      static EXTERNAL_USE_CLASS u = new EXTERNAL_USE_CLASS();
  
      //below is callable via a CLI interface test APP.
      public static void test_basics() {
          Boolean hasRan = u.getHas_ran();
          Integer getInt = u.getMyInteger();
          String getString = u.getMyString();
          System.out.println("u.getHas_ran()"+hasRan);
          System.out.println("u.getMyInteger()"+getInt);
          System.out.println("u.getMyString()"+getString);
      }
  }
  </code></pre>
  
  <p>And what I am interested in exposing are all the API's touched from the external Jar.</p>
  
  <p>(which namely would  these lines)</p>
  
  <pre><code>    Boolean hasRan = u.getHas_ran();
      Integer getInt = u.getMyInteger();
      String getString = u.getMyString();
  </code></pre>
  
  <p>And If possible... I'd like to be able to print out some report to the effect of saying </p>
  
  <blockquote>
    <p>Your Object Method 'test_basics' has used the following api's:<br>
    --external_api.EXTERNAL_USE_CLASS.getHas_ran()<br>
    --external_api.EXTERNAL_USE_CLASS.getMyInteger()
    --external_api.EXTERNAL_USE_CLASS.getMyString()</p>
  </blockquote>
  
  <p>The above names I had to get by going to my test-class and right clicking in eclipse and saying 'copy qualified name'.</p>
  
  <p>Which is kind of a pain if we have to do this for 1,000's of APIs.... I just figured theres some way to logically print out a trace.</p>
  
  <p>It could be I just dont know the proper google search terms, and this is a common easy task.</p>
  
  <p>Much Appreciated for any help/pointers.  </p>