[forge-issues] [JBoss JIRA] (FORGE-1671) Add nested annotation to a constraint annotation
Antonio Goncalves (JIRA)
issues at jboss.org
Tue Apr 1 16:27:12 EDT 2014
[ https://issues.jboss.org/browse/FORGE-1671?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12958237#comment-12958237 ]
Antonio Goncalves commented on FORGE-1671:
------------------------------------------
Another attempt... but looks like it's impossible to do with Roaster at the moment :
{code}
public class BeanValidationAnnotation {
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}
> Add nested annotation to a constraint annotation
> ------------------------------------------------
>
> Key: FORGE-1671
> URL: https://issues.jboss.org/browse/FORGE-1671
> Project: Forge
> Issue Type: Sub-task
> Components: Java EE
> Affects Versions: 2.2.0.Final
> Reporter: Antonio Goncalves
> Fix For: 2.x Future
>
>
> At the moment a constraint annotation does not contain a {{List}} of constraints. So, at the moment, the command {{constraint-new-annotation}} generates the following code :
> {code}
> @Documented
> @Constraint(validatedBy = {})
> @Target( { METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
> @Retention(RUNTIME)
> @ReportAsSingleViolation
> public @interface URL {
> String message() default "Invalid value";
> Class<?>[] groups() default { };
> Class<? extends Payload>[] payload() default { };
> {code}
> It should add a nested annotation {{List}} of type array of constraint
> {code}
> @Documented
> @Constraint(validatedBy = {})
> @Target( { METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
> @Retention(RUNTIME)
> @ReportAsSingleViolation
> public @interface URL {
> String message() default "Invalid value";
> Class<?>[] groups() default { };
> Class<? extends Payload>[] payload() default { };
> @Target( { METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
> @Retention(RUNTIME)
> @Documented
> public @interface List {
> URL[] value();
> }
> }
> {code}
> See class : {{NewAnnotationCommand}}
--
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