groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <>
Subject JSR 308 support for Groovy
Date Mon, 12 Jun 2017 10:44:28 GMT
I have started examining what is required for JSR 308 support in Groovy. It
is one of those things which might make sense to ensure we support in the
new grammar from the get go.

Current issues:

With just a few tweaks (GROOVY-8226) we get some stuff for free since
we had some bits geared up already. We can now start using some of the
Java libraries which leverage the JSR, e.g.:

import com.pholser.junit.quickcheck.generator.InRange
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck
import org.junit.runner.RunWith
import com.pholser.junit.quickcheck.Property

class IntegerRanges {
    void shouldHold(@InRange(min = "0", max = "9") Integer item) {
        item >= 0 && item <= 9

Which uses a property-based testing framework to call our assertion 100
times. It works in fact even with the old grammar once the plumbing changes
are done.

What we can't do at the moment is something like this:

void shouldAlsoHold(List<@InRange(min = "0", max = "9") Integer> items) {
        assert items.every{ it >= 0 && it <= 9 }

The grammar isn't expecting an annotation on the parameterized type. It
fails for both the old and new parsers with slightly different error

I'll be taking a look at what else is required to make this work but if
anyone has particular requirements or comments, or some part they would
like to work on, please let me know.

Cheers, Paul.

View raw message