Xtend code within an active annotation field

26 views
Skip to first unread message

torste...@elektrobit.com

unread,
May 5, 2017, 4:34:09 AM5/5/17
to Xtend Programming Language
Hi.

I want to realize a light-weight design-by-contract pattern using active annotations.
It should look like this:

@Contract(requires='elements.filter[!empty].size != 0')
def doSomething(List<String> elements) {
...
}
The content of the requires rule is a string, but in fact is valid xtend code.

As far as I understood with the active annotation concept one can hook into the xtend-to-java generator process.
So I want to generate a piece of code like assertTrue(elements.filter[!empty].size != 0) after entering the method.
How this is done in principle is clear to me.
But I need to transform the xtend expression (elements.filter[!empty].size != 0) into a java expression first, since at the end everything needs to be java code.
How can I achieve this?

Thanks,
Torsten

Sven Efftinge (sven@efftinge.de)

unread,
May 5, 2017, 4:41:03 AM5/5/17
to xtend...@googlegroups.com
Hi Torsten,

of course, you can use the string from an annotation value and generate it into a method, but there is no xtend to java conversion as part of the active annotations. It would be cool if we could allow expressions of any type in annotation values, because then you would also get the full tool support there. But that's a bigger task.

Sven


--
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.

Reply all
Reply to author
Forward
0 new messages