[forge-dev] [Roaster] Don't know how to add an annotation inside another one

Lincoln Baxter, III lincolnbaxter at gmail.com
Sun Apr 13 11:15:19 EDT 2014


javaSource.addNestedType() should be what you are looking for.


On Sun, Apr 13, 2014 at 11:14 AM, Lincoln Baxter, III <
lincolnbaxter at gmail.com> wrote:

> Hey Antonio. George fixed this in the most recent Roaster SNAPSHOT. Could
> you give it a try? Hopefully we got it!
>
>
> On Thu, Mar 27, 2014 at 9:03 AM, Antonio Goncalves <
> antonio.mailing at gmail.com> wrote:
>
>> @Lincoln I think I did try passing a String but it didn't work. Let me
>> have an extra look at it
>>
>> @Matt I've added a comment to the JIRA
>>
>> Antonio
>>
>>
>> 2014-03-25 18:59 GMT+01:00 Matt Benson <gudnabrsam at gmail.com>:
>>
>> This is an open issue: https://issues.jboss.org/browse/FORGE-1582
>>>
>>> Matt
>>>
>>> On Tue, Mar 25, 2014 at 12:43 PM, Lincoln Baxter, III
>>> <lincolnbaxter at gmail.com> wrote:
>>> > Hey Antonio,
>>> >
>>> > I don't really know how to do this off the top of my head. My guess is
>>> that
>>> > you'll need to do what you've done for the prior elements and provide
>>> the
>>> > definition using a String. Will this work until we can add this
>>> > functionality to the API?
>>> >
>>> > ~Lincoln
>>> >
>>> >
>>> > On Sun, Mar 23, 2014 at 10:37 AM, Antonio Goncalves
>>> > <antonio.mailing at gmail.com> wrote:
>>> >>
>>> >> It's not like I have the choice. This is the way you model a
>>> constraint
>>> >> with Bean Validation :
>>> >>
>>> http://beanvalidation.org/1.1/spec/#constraintsdefinitionimplementation-multipleconstraints
>>> >>
>>> >>
>>> >> 2014-03-22 9:11 GMT+01:00 Luca Masini
>>> >> <luca.masini.mailing.list at gmail.com>:
>>> >>
>>> >>> Why don't you model it like "NamedQueries/NamedQuery" ?
>>> >>>
>>> >>>
>>> >>> 2014-03-22 7:25 GMT+01:00 Antonio Goncalves <
>>> antonio.mailing at gmail.com>:
>>> >>>>
>>> >>>> Hi,
>>> >>>>
>>> >>>> This is a Roaster question. I've been trying to create a Bean
>>> Validation
>>> >>>> constraint properly... in vain. What I want to achieve is the
>>> following
>>> >>>> (notice the @List annotation) :
>>> >>>>
>>> >>>> @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
>>> >>>> @Retention(RUNTIME)
>>> >>>> @Documented
>>> >>>> @Constraint(validatedBy = {})
>>> >>>> public @interface Email {
>>> >>>>
>>> >>>>   String message() default "wrong email address";
>>> >>>>
>>> >>>>   Class<?>[] groups() default {};
>>> >>>>
>>> >>>>   Class<? extends Payload>[] payload() default {};
>>> >>>>
>>> >>>>   @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
>>> >>>>   @Retention(RUNTIME)
>>> >>>>   @interface List {
>>> >>>>     Email[] value();
>>> >>>>   }
>>> >>>> }
>>> >>>>
>>> >>>>
>>> >>>> This is the code I've written. Both annotation are generated
>>> >>>> separately... but I don't know how to add listAnnotation inside
>>> >>>> emailAnnotation. Any idea ?
>>> >>>>
>>> >>>> Thanks
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>> public class Main {
>>> >>>>     public static void main(String[] args) {
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>         // This is the inner annotation List
>>> >>>>         final JavaAnnotationSource listAnnotation =
>>> >>>> Roaster.create(JavaAnnotationSource.class);
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>         listAnnotation.setName("List");
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>> listAnnotation.addAnnotation(Retention.class).setEnumValue(RUNTIME);
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> listAnnotation.addAnnotation(Target.class).setEnumValue(METHOD,
>>> >>>> FIELD, PARAMETER, TYPE);
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>         listAnnotation.addAnnotationElement("Email[] value()");
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>         System.out.println(listAnnotation);
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>         // This is the annotation @Email
>>> >>>>         final JavaAnnotationSource emailAnnotation =
>>> >>>> Roaster.create(JavaAnnotationSource.class);
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> emailAnnotation.setPackage("org.agoncal.proj.constraints").setName("Email");
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>         emailAnnotation.addImport(Payload.class);
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>         emailAnnotation.addAnnotation(Documented.class);
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> emailAnnotation.addAnnotation(Retention.class).setEnumValue(RUNTIME);
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> emailAnnotation.addAnnotation(Target.class).setEnumValue(METHOD,
>>> >>>> FIELD, PARAMETER, TYPE);
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> emailAnnotation.addAnnotation(Constraint.class).setLiteralValue("validatedBy",
>>> >>>> "{}");
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>         emailAnnotation.addAnnotationElement("String message()
>>> default
>>> >>>> \"wrong email address\"");
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>         emailAnnotation.addAnnotationElement("Class<?>[] groups()
>>> >>>> default {}");
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>         emailAnnotation.addAnnotationElement("Class<? extends
>>> Payload>[]
>>> >>>> payload() default {}");
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>         // I was expecting to have a method like that so I could add
>>> >>>> annotation inside another one
>>> >>>>         // emailAnnotation.addAnnotationElement(emailAnnotation);
>>> >>>>
>>> >>>>         System.out.println(emailAnnotation);
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>     }
>>> >>>>
>>> >>>> }
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>> --
>>> >>>> Antonio Goncalves
>>> >>>> Software architect and Java Champion
>>> >>>>
>>> >>>> Web site | Twitter | LinkedIn | Paris JUG | Devoxx France
>>> >>>>
>>> >>>> _______________________________________________
>>> >>>> forge-dev mailing list
>>> >>>> forge-dev at lists.jboss.org
>>> >>>> https://lists.jboss.org/mailman/listinfo/forge-dev
>>> >>>
>>> >>>
>>> >>>
>>> >>>
>>> >>> --
>>> >>> ****************************************
>>> >>> http://www.lucamasini.net
>>> >>> http://twitter.com/lmasini
>>> >>> http://www.linkedin.com/pub/luca-masini/7/10/2b9
>>> >>> ****************************************
>>> >>>
>>> >>> _______________________________________________
>>> >>> forge-dev mailing list
>>> >>> forge-dev at lists.jboss.org
>>> >>> https://lists.jboss.org/mailman/listinfo/forge-dev
>>> >>
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> Antonio Goncalves
>>> >> Software architect and Java Champion
>>> >>
>>> >> Web site | Twitter | LinkedIn | Paris JUG | Devoxx France
>>> >>
>>> >> _______________________________________________
>>> >> forge-dev mailing list
>>> >> forge-dev at lists.jboss.org
>>> >> https://lists.jboss.org/mailman/listinfo/forge-dev
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > Lincoln Baxter, III
>>> > http://ocpsoft.org
>>> > "Simpler is better."
>>> >
>>> > _______________________________________________
>>> > forge-dev mailing list
>>> > forge-dev at lists.jboss.org
>>> > https://lists.jboss.org/mailman/listinfo/forge-dev
>>> _______________________________________________
>>> forge-dev mailing list
>>> forge-dev at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/forge-dev
>>>
>>
>>
>>
>> --
>> Antonio Goncalves
>> Software architect and Java Champion
>>
>> Web site <http://www.antoniogoncalves.org/> | Twitter<http://twitter.com/agoncal>
>>  | LinkedIn <http://www.linkedin.com/in/agoncal> | Paris JUG<http://www.parisjug.org/>
>>  | Devoxx France <http://www.devoxx.fr/>
>>
>> _______________________________________________
>> forge-dev mailing list
>> forge-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/forge-dev
>>
>
>
>
> --
> Lincoln Baxter, III
> http://ocpsoft.org
> "Simpler is better."
>



-- 
Lincoln Baxter, III
http://ocpsoft.org
"Simpler is better."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/forge-dev/attachments/20140413/5d7322e5/attachment-0001.html 


More information about the forge-dev mailing list