Problem with ActiveAnnotation and used annotation javax.validation.constraints.Size

16 views
Skip to first unread message

Alexander Fischer

unread,
Mar 14, 2017, 1:00:57 PM3/14/17
to Xtend Programming Language

We have implemented some own active annotations with Xtend2.11 (but the problem also occurs with Xtend2.10).
If the Xtend-code uses the annotation javax.validation.constraints.Size with two attributes (min=0, max=10), the Xtend-system crashes with an exception:
java.lang.RuntimeException: Cannot root twice
at org.eclipse.xtext.xbase.typesystem.internal.DefaultBatchTypeResolver$1.add(DefaultBatchTypeResolver.java:73)
at org.eclipse.xtext.xbase.typesystem.internal.DefaultBatchTypeResolver$1.add(DefaultBatchTypeResolver.java:1)
at org.eclipse.xtext.xbase.typesystem.internal.LogicalContainerAwareReentrantTypeResolver$1.add(LogicalContainerAwareReentrantTypeResolver.java:325)

If I only use one attribute (only min= or max=), all is working.
I think, the problem lies in the class org.eclipse.xtext.xbase.typesystem.internal.LogicalContainerAwareReentrantTypeResolver in method recordAnnotationExpressions(List<JvmAnnotationReference> annotations):

	protected void recordAnnotationExpressions(List<JvmAnnotationReference> annotations) {
		for(JvmAnnotationReference annotation: annotations) {
			EObject sourceElement = getSourceElement(annotation);
			if (sourceElement != annotation) {
				rootedInstances.add(sourceElement);
			} else {
				for(JvmAnnotationValue value: annotation.getExplicitValues()) {
					if (value instanceof JvmCustomAnnotationValue) {
						JvmCustomAnnotationValue custom = (JvmCustomAnnotationValue) value;
						for(Object object: custom.getValues()) {
							if (object instanceof XExpression) {
								rootedInstances.add(sourceElement);
							}
						}
					} else if (value instanceof JvmAnnotationAnnotationValue) {
						recordAnnotationExpressions(((JvmAnnotationAnnotationValue) value).getValues());
					}
				}
			}
		}
	}

For every attribute of the annotation the method goes through the loop and wants to add the same annotation ("sourceElement") to the rootedInstances. This fails for the second call.
How can I solve this problem, if I want to use an annotation with multiple parameters/attributes?

Kindly regards,
Alexander

Sven Efftinge (sven@efftinge.de)

unread,
Mar 14, 2017, 1:34:56 PM3/14/17
to xtend...@googlegroups.com
I saw you already files a ticket at github. Thanks.

--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sven Efftinge (sven@efftinge.de)

unread,
Mar 14, 2017, 1:35:16 PM3/14/17
to xtend...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages