[forge-issues] [JBoss JIRA] (FORGE-1582) Support the creation of nested Java source types
Antonio Goncalves (JIRA)
issues at jboss.org
Thu Mar 27 09:02:13 EDT 2014
[ https://issues.jboss.org/browse/FORGE-1582?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12956985#comment-12956985 ]
Antonio Goncalves commented on FORGE-1582:
------------------------------------------
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) :
{code}
@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();
}
}
{code}
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 ?
{code}
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);
}
}
{code}
> Support the creation of nested Java source types
> ------------------------------------------------
>
> Key: FORGE-1582
> URL: https://issues.jboss.org/browse/FORGE-1582
> Project: Forge
> Issue Type: Feature Request
> Components: Parsers / File Manipulation
> Affects Versions: 2.x Future
> Reporter: Matt Benson
>
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the forge-issues
mailing list