title: AspectJ, how to get line number of a method invocation
body: <p>I am trying to write an aspect to catch all methods execution and retrieve the line number where the methods have been invoked.
  For example, if I have:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class MyMainClass {
      public static void main(String[] args){
          MyArray m = new MyArray(5);
          m.setValue //...
          //...
      }
  }
  </code></pre>
  
  <p>I would like to write a pointcut and an advice able to get the line where the method setValue has been called (i.e. line number 4) and not the source code line, where the method has been implemented (accessible with <code>thisJoinPoint.getSourceLocation().getLine()</code>).</p>
  
  <p>Is there any way to do this? 
  Thanks!</p>
  
  <p>UPDATE: I just found out that this code:</p>
  
  <pre class="lang-java prettyprint-override"><code>StackTraceElement[] trace = Thread.currentThread().getStackTrace();
  System.out.println("[AspectJ]LineNumber: " + trace[trace.length-1].getLineNumber());
  </code></pre>
  
  <p>prints the last method invocation line number, the problem is that it is not useful when there is method invocation inside a method implementation (because, in that case I should decrease trace elements position, but I don't know how to understand when to do that).</p>