Refer to current filename and line.  
Author Message
Aaron Fude





PostPosted: 2008-6-11 10:36:00 Top

java-programmer, Refer to current filename and line. Hi,

I remember this was possible in C with macros. Is it possible in Java
to refer to the current file name and line number as in

System.out.println( something.that.returns.current.file.name() + "
printed this line.");

Many thanks in advance!

Aaron
 
Mark Space





PostPosted: 2008-6-11 10:47:00 Top

java-programmer >> Refer to current filename and line. Aaron Fude wrote:
> Hi,
>
> I remember this was possible in C with macros. Is it possible in Java
> to refer to the current file name and line number as in
>
> System.out.println( something.that.returns.current.file.name() + "
> printed this line.");
>
> Many thanks in advance!
>
> Aaron

This is all I could find:

<http://forum.java.sun.com/thread.jspa?threadID=5126327&messageID=9448610>
 
Neil Coffey





PostPosted: 2008-6-11 13:19:00 Top

java-programmer >> Refer to current filename and line. Mark Space wrote:

>> I remember this was possible in C with macros. Is it possible in Java
>> to refer to the current file name and line number as in

> This is all I could find:
>
> <http://forum.java.sun.com/thread.jspa?threadID=5126327&messageID=9448610>

As of Java 5, you can also go via the ThreadMXBean.getThreadInfo().
I've not tested, but I wonder if there could be a sliiight performance
gain because you can specify that you only need the top stack trace
element(s). (The code would be uglier, of course.)

You can also call Thread.currentThread().getStackTrace(), but internally
this appears to just create a Throwable and query it, so it depends
which code you like looking at...!

Neil
 
 
Roedy Green





PostPosted: 2008-6-11 14:26:00 Top

java-programmer >> Refer to current filename and line. On Tue, 10 Jun 2008 19:35:55 -0700 (PDT), Aaron Fude
<email***@***.com> wrote, quoted or indirectly quoted someone who
said :

>System.out.println( something.that.returns.current.file.name() + "
>printed this line.");

See http://mindprod.com/jgloss/trace.html

do a new Exception() then use the methods for exam inning the stack
track fields.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com