You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Rich Wagner <ri...@hotmail.com> on 2010/01/01 22:50:03 UTC

Easiest way to map output line numbers to resource (e.g. template) line numbers?

(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: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


RE: Easiest way to map output line numbers to resource (e.g. template) line numbers?

Posted by Rich Wagner <ri...@hotmail.com>.
I'm using Velocity to generate Java code.  If the generated code has a compilation error, and if the problem is in the template (as opposed to in the Context), it's convenient to flag the problem's location in the template itself.  The mapping is required to do that.

-- Rich


> Date: Mon, 4 Jan 2010 03:43:07 -0800
> From: wyla@sci.fi
> To: user@velocity.apache.org
> Subject: Re: Easiest way to map output line numbers to resource (e.g. template) line numbers?
> 
> 
> Why do you want to do that?
> 
> 
> Rich Wagner-3 wrote:
>> 
>> 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?
>> ...
>> 
> 
> -- 
> View this message in context: http://old.nabble.com/Easiest-way-to-map-output-line-numbers-to-resource-%28e.g.-template%29-line-numbers--tp26988546p27011853.html
> Sent from the Velocity - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
> 
 		 	   		  
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/171222986/direct/01/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Easiest way to map output line numbers to resource (e.g. template) line numbers?

Posted by Jarkko Viinamäki-2 <wy...@sci.fi>.
Why do you want to do that?


Rich Wagner-3 wrote:
> 
> 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?
> ...
> 

-- 
View this message in context: http://old.nabble.com/Easiest-way-to-map-output-line-numbers-to-resource-%28e.g.-template%29-line-numbers--tp26988546p27011853.html
Sent from the Velocity - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Easiest way to map output line numbers to resource (e.g. template) line numbers?

Posted by Nathan Bubna <nb...@gmail.com>.
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 <ri...@hotmail.com> 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: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org