Templates geneating aligned comments

14 views
Skip to first unread message

fab...@gmail.com

unread,
Jul 5, 2015, 3:06:07 PM7/5/15
to xtend...@googlegroups.com
Hi,

I want to use Xtend templates to generate C-Code with comments. I want to generate a initializer for a structure like this:

const testStruct bla =
{
   1,          /* id */
   bool       /* type */
}

And the comments should be aligned without knowing the size of the initialization field.

Currently my template looks like this:
'''
const const testStruct bla =
{
   «getId()»,           /*id */
   «getType()»        /*id */
}
'''

I would appreciate a good idea. I love Xtend and its capabilities with the templates, but I need a solution to produce nice, readable code.

Sven Efftinge

unread,
Jul 5, 2015, 3:23:34 PM7/5/15
to xtend...@googlegroups.com
You could use guavas Strings#padEnd like this;

import static extension com.google.common.base.Strings.*
> '''
> const const testStruct bla =
> {
> «(getId()+’,’).padEnd(42,‘ ‘)»/* id */
> «getType().padEnd(42,‘ ‘)»/* type */
> }
> '''



Reply all
Reply to author
Forward
0 new messages