I'm not aware of any easier way, nor do i recall anyone else tackling
this.  Though you can search the archives at:
http://velocity.markmail.org

On Fri, Jan 1, 2010 at 1:50 PM, Rich Wagner <[email protected]> wrote:
>
> (Sorry if this is a FAQ: I just joined the mailing list and didn't find an 
> answer to my question after "google"-ing.  BTW, is there a way to search the 
> Velocity mailing list archives?)
>
> I need to generate a mapping from output line numbers back to the 
> corresponding resource filenames and line numbers.  What's the easiest way to 
> do that?
>
> I have one method in mind, but am hoping there's an easier way.  My method 
> involves overloading the standard resource loaders' "getResourceStream" 
> methods so that each resulting "InputStream" prepends a path and line number 
> to each resource line.  So for instance, given a template of:
>
>     public enum ${EnumName} {
>         /* #foreach ( $name in $names ) */
>         ${name},
>         /* #end */
>         ;
>     }
>
> my overloaded "FileResourceLoader" would produce an InputStream that 
> contained:
>
>     Template.vtl:1:public enum ${EnumName} {
>
>     Template.vtl:2:    /* #foreach ( $name in $names ) */
>
>     Template.vtl:3:    ${name},
>
>     Template.vtl:4:    /* #end */
>
>     Template.vtl:5:    ;
>
>     Template.vtl:6:}
>
> Template expansion would then produce something like the following; output is 
> in the box, and output line numbers are to the left of the box:
>
>        RGB.java
>       +-------------------------------------------+
>     1 | Template.vtl:1:public enum ${EnumName} {  |
>
>
>     2 | Template.vtl:2:    /*  */                 |
>
>
>     3 | Template.vtl:3:    Red,                   |
>
>
>
>
>     4 | Template.vtl:4:    /*  */                 |
>
>
>
>
>     5 | Template.vtl:3:    Green,                 |
>
>
>
>
>     6 | Template.vtl:4:    /*  */                 |
>
>
>
>
>     7 | Template.vtl:3:    Blue,                  |
>
>
>
>
>     8 | Template.vtl:4:    /*  */                 |
>
>
>
>
>     9 | Template.vtl:5:    ;                      |
>
>
>     10| Template.vtl:6:}                          |
>
>       +-------------------------------------------+
>
>
> In this way, it can be inferred that (e.g.) line 7 in "RGB.java" was 
> generated from line 3 of "Template.vtl".
>
> Post-processing would then strip off the prepended file/line information from 
> the output, while at the same time saving line mapping information to a 
> separate file.  (Post-processing also provides a chance to remove the 
> extraneous empty comment lines, e.g. "RGB.java" lines 2, 4, 6 and 8...  :-)
>
> (Note that doing this at the Resource Loader level means it'd handle 
> #include-ed and #parse-ed resources.)
>
> All well and good, but is there an easier way to get what I want?
>
> Thanks in advance,
> Rich
>
>
> _________________________________________________________________
> Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
> http://clk.atdmt.com/GBL/go/177141664/direct/01/
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to