users@jaxb.java.net

Re: Generating inline comments from plugins

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Thu, 10 Jan 2008 15:14:36 +0100

Hi.

> I'm trying to use this to generate code along this following lines:
>
> new MyType[] {
> new MyType(a,b,c), /* comment */
> new MyType(d,e,f), /* comment */
> new MyType(g,h,i), /* comment */
> }
>
> If I add the comment to the JArray using
>
> array.add(direct("/* comment */"));
>
> then of course it adds the comment as an expression, so I get this (note
> the trailing commas):
>
> new MyType[] {
> new MyType(a,b,c), /* comment */,
> new MyType(d,e,f), /* comment */,
> new MyType(g,h,i), /* comment */,
> }
>
> which doesn't compile.
>
> It seems I need to construct a JExpression which contains both the new
> MyType(..) and then the comment.
>
> Any ideas how to achieve that?

I'd simply implement JCommentedExpression which outputs a comment
before the expression text. Take a look how J* classes are
implemented, there's nothing difficult there.

Bye.
/lexi