users@jaxb.java.net

Re: CodeModel and nested annotations

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Wed, 11 Jun 2008 10:54:21 +0200

Hi.

> Morning folks,
>
> I'm trying to figure out how to set up nested annotations using the XJC
> CodeModel.
>
> For example, I want to generate this sort of thing:
>
> @X({
> @Y(a="b"),
> @Y(c="d")
> })
> public class C {}
>
> Once I've added the @X (using JAnnotatable.annotate), the returned
> JAnnotationUse object doesn't seem to offer a way of adding the @Y array, it
> only offers methods to add scalar parameters.
>
> What am I missing?

Try something like:

final JAnnotationArrayMember ys = myAnnotationUse.paramArray("value");
ys.annotate(Y.class).param("a", "b");
ys.annotate(Y.class).param("c", "d");

Also see annox.dev.java.net and the annotate plugin in jaxb2-commons.

Bye.
/lexi