title: __LINE__ equivalent in Java?
body: <p>I'm searching a way to include <code>__LINE__</code> as a compile-time constant in outputted messages. </p>
  
  <p>Various solutions seem to exist, but with a big runtime penalty as suggested in <a href="https://stackoverflow.com/questions/453028" title="__LINE__ equivalent in Javascript"><code>__LINE__</code> in JS</a> and <a href="https://stackoverflow.com/questions/696218" title="Do __LINE__ __FILE__ equivalents exist in C#?"><code>__LINE__</code> in C#</a>. They are usually always based upon a runtime object <code>StackFrame</code> as log4j.</p>
  
  <p>Using the log4j possibility of enabling/disabling on a needed basis isn't an option either since usually when an error happens, it's too late to enable the line numbers, and inlined code doesn't seem to have any line numbers any more.
  . Would it be possible to either : </p>
  
  <ol>
  <li>Pre-process the java source files before compilation, ideally with something integrated with Eclipse<sup>1</sup>, so the it can be tested on the developpement platform also.</li>
  <li>Be able to <em>pre-process</em> the class at loading time. The overhead would then be negligible by being amortized.</li>
  </ol>
  
  <p><sub>1. Actually I do use an ugly hack: calling a custom preprocessor just after checkout on the build server via ANT tricks</sub></p>