Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding line number in generated Java source

Is there any way to override the line numbers in Java (e.g., by using some kind of preprocessor directive)?

I am "compiling" a high-level language, down to Java byte code using Janino. I need compiler errors to report the line from the original file, not the generated Java code.

C# has the #line directive, and I've successfully exploited it to map line numbers from a source file to the compiled result. I need the same for Java.

Thanks!

like image 681
Ryan Emerle Avatar asked Feb 10 '09 03:02

Ryan Emerle


1 Answers

I've never seen it used for other than JSP, but JSR-45 was designed to be used for this purpose for any source language. The process involves creating a second file in a special format ("SMAP") that maps line numbers in the original source to line numbers in the generated Java source code.

like image 184
erickson Avatar answered Oct 13 '22 13:10

erickson