You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Paul King <pa...@asert.com.au> on 2017/06/12 10:44:28 UTC

JSR 308 support for Groovy

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:

https://issues.apache.org/jira/browse/GROOVY-8225
https://issues.apache.org/jira/browse/GROOVY-8226

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

======>8======
@Grab('com.pholser:junit-quickcheck-generators:0.7')
@Grab('com.pholser:junit-quickcheck-core:0.7')
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

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

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:

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

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

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.

Re: JSR 308 support for Groovy

Posted by Paul King <pa...@asert.com.au>.
Hi Daniel,

I think the majority of Groovy users have in their mind that Groovy is just
like Java, only better. :-) So, initially we should aim to be the same as
Java.

Depending on what we discover during experimenting/implementation, we might
alter that plan. We might stop short if there are things we think are
extremely unlikely to be used in Groovy or particularly hard to do. We
might also go further if we find an interesting extension but it would have
to make sense for Groovy and not cause potential incompatibilities with
Java. Any changes from Java would always be mailing list discussion
material anyway.

Cheers, Paul.


On Tue, Jun 13, 2017 at 11:28 PM, Daniel Sun <re...@hotmail.com>
wrote:

> Hi Paul,
>
>        I'm reading an article on JSR308, which is really useful.
> http://www.oracle.com/technetwork/articles/java/
> ma14-architect-annotations-2177655.html
>
>        In addition, I've already created a branch
> jsr308(https://github.com/danielsun1106/groovy-parser/tree/jsr308) to
> experiment the grammar.  Before working on it, I want to confirm whether
> Groovy will support JSR308 fully.
>
> P.S. The following code is quite strange for me ;-)
> Forecast @Readonly [] fiveDay = new Forecast @Readonly [5];
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> View this message in context: http://groovy.329449.n5.
> nabble.com/JSR-308-support-for-Groovy-tp5741586p5741627.html
> Sent from the Groovy Users mailing list archive at Nabble.com.
>

Re: JSR 308 support for Groovy

Posted by Daniel Sun <re...@hotmail.com>.
Hi Paul,

       I'm reading an article on JSR308, which is really useful.
http://www.oracle.com/technetwork/articles/java/ma14-architect-annotations-2177655.html

       In addition, I've already created a branch
jsr308(https://github.com/danielsun1106/groovy-parser/tree/jsr308) to
experiment the grammar.  Before working on it, I want to confirm whether
Groovy will support JSR308 fully.

P.S. The following code is quite strange for me ;-)
Forecast @Readonly [] fiveDay = new Forecast @Readonly [5];

Cheers,
Daniel.Sun



--
View this message in context: http://groovy.329449.n5.nabble.com/JSR-308-support-for-Groovy-tp5741586p5741627.html
Sent from the Groovy Users mailing list archive at Nabble.com.

Re: JSR 308 support for Groovy

Posted by Paul King <pa...@asert.com.au>.
Thanks Daniel,

I created this additional sub-task:

https://issues.apache.org/jira/browse/GROOVY-8228 JSR308 grammar changes

If any parts turn out to be controversial or need further discussion we can
create further issues.

Cheers, Paul.


On Tue, Jun 13, 2017 at 2:34 AM, Daniel Sun <re...@hotmail.com> wrote:

> Hi Paul,
>
> > The grammar isn't expecting an annotation on the parameterized type. It
> > fails for both the old and new parsers with slightly different error
> > messages.
>
>       I will set aside some time to complete the grammar and AST
> construction.
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> View this message in context: http://groovy.329449.n5.
> nabble.com/JSR-308-support-for-Groovy-tp5741586p5741591.html
> Sent from the Groovy Users mailing list archive at Nabble.com.
>

Re: JSR 308 support for Groovy

Posted by Daniel Sun <re...@hotmail.com>.
Hi Paul,

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

      I will set aside some time to complete the grammar and AST
construction.

Cheers,
Daniel.Sun



--
View this message in context: http://groovy.329449.n5.nabble.com/JSR-308-support-for-Groovy-tp5741586p5741591.html
Sent from the Groovy Users mailing list archive at Nabble.com.