You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by "Daniel.Sun" <re...@hotmail.com> on 2016/11/04 15:09:30 UTC
try-with-resources statement for Groovy 3
Hi all,
The new parser supports *try-with-resources statement* now. The
related code is on the tryWithResources branch of groovy-parser
project(https://github.com/danielsun1106/groovy-parser/tree/tryWithResources).
In order to keep the same semantic with Java's try-with-resources, the
implementation conforms to *JLS "14.20.3.
try-with-resources"*(https://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html).
Example codes can be found at
https://github.com/danielsun1106/groovy-parser/blob/tryWithResources/src/test/resources/core/TryWithResources_01x.groovy
Any thoughts?
Cheers,
Daniel.Sun
--
View this message in context: http://groovy.329449.n5.nabble.com/try-with-resources-statement-for-Groovy-3-tp5736479.html
Sent from the Groovy Dev mailing list archive at Nabble.com.
Re: try-with-resources statement for Groovy 3
Posted by "Daniel.Sun" <re...@hotmail.com>.
Hi all,
If nobody unlikes the feature, I'll merge it into the master of
groovy-parser later :)
Cheers,
Daniel.Sun
--
View this message in context: http://groovy.329449.n5.nabble.com/try-with-resources-statement-for-Groovy-3-tp5736479p5736495.html
Sent from the Groovy Dev mailing list archive at Nabble.com.
Re: try-with-resources statement for Groovy 3
Posted by "Daniel.Sun" <re...@hotmail.com>.
Hi Jochen,
The nest version of test case is added, the new parser can support too
:)
https://github.com/danielsun1106/groovy-parser/blob/tryWithResources/src/test/resources/core/TryWithResources_01x.groovy#L188
Cheers,
Daniel.Sun
--
View this message in context: http://groovy.329449.n5.nabble.com/try-with-resources-statement-for-Groovy-3-tp5736479p5736493.html
Sent from the Groovy Dev mailing list archive at Nabble.com.
Re: try-with-resources statement for Groovy 3
Posted by "Daniel.Sun" <re...@hotmail.com>.
Hi Jochen,
The basic try-with-resources will be wrapped by a block, so the test
cases can be put in a file, the r1 variables will not impact each
other(Reference 14.20.3.1. Basic try-with-resources
(https://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html)).
And the nest version of test cases will be added later. Have I caught
your meaning?
BTW, the try-with-resources test cases are all runnable. You can see
they are marked 'x'(e.g. TryWithResources_01*x*.groovy), which means
executable.
Cheers,
Daniel.Sun
--
View this message in context: http://groovy.329449.n5.nabble.com/try-with-resources-statement-for-Groovy-3-tp5736479p5736489.html
Sent from the Groovy Dev mailing list archive at Nabble.com.
Re: try-with-resources statement for Groovy 3
Posted by "Daniel.Sun" <re...@hotmail.com>.
Hi Cédric,
try-with-resources works fine with static compilation(test case 15):
https://github.com/danielsun1106/groovy-parser/blob/tryWithResources/src/test/resources/core/TryWithResources_01x.groovy#L212
Cheers,
Daniel.Sun
--
View this message in context: http://groovy.329449.n5.nabble.com/try-with-resources-statement-for-Groovy-3-tp5736479p5736492.html
Sent from the Groovy Dev mailing list archive at Nabble.com.
Re: try-with-resources statement for Groovy 3
Posted by "Daniel.Sun" <re...@hotmail.com>.
Hi Cédric,
Thanks for your reminding. I'll keep it in mind.
Cheers,
Daniel.Sun
--
View this message in context: http://groovy.329449.n5.nabble.com/try-with-resources-statement-for-Groovy-3-tp5736479p5736490.html
Sent from the Groovy Dev mailing list archive at Nabble.com.
Re: try-with-resources statement for Groovy 3
Posted by Cédric Champeau <ce...@gmail.com>.
Cool stuff. When you add such features, it is very important to double
check they also work with static compilation.
Keep up the good work!
2016-11-04 17:54 GMT+01:00 Daniel.Sun <re...@hotmail.com>:
> Hi Jochen,
>
> Thanks for your advice. I'll refactor the test cases later.
>
> The implementation is done, you can find it at
> https://github.com/danielsun1106/groovy-parser/blob/tryWithResources/src/
> main/java/org/apache/groovy/parser/antlr4/TryWithResourcesASTTransformat
> ion.java
>
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> View this message in context: http://groovy.329449.n5.
> nabble.com/try-with-resources-statement-for-Groovy-3-
> tp5736479p5736485.html
> Sent from the Groovy Dev mailing list archive at Nabble.com.
>
Re: try-with-resources statement for Groovy 3
Posted by "Daniel.Sun" <re...@hotmail.com>.
Hi Jochen,
Thanks for your advice. I'll refactor the test cases later.
The implementation is done, you can find it at
https://github.com/danielsun1106/groovy-parser/blob/tryWithResources/src/main/java/org/apache/groovy/parser/antlr4/TryWithResourcesASTTransformation.java
Cheers,
Daniel.Sun
--
View this message in context: http://groovy.329449.n5.nabble.com/try-with-resources-statement-for-Groovy-3-tp5736479p5736485.html
Sent from the Groovy Dev mailing list archive at Nabble.com.
Re: try-with-resources statement for Groovy 3
Posted by Jochen Theodorou <bl...@gmx.org>.
On 04.11.2016 16:09, Daniel.Sun wrote:
> Hi all,
>
> The new parser supports *try-with-resources statement* now. The
> related code is on the tryWithResources branch of groovy-parser
> project(https://github.com/danielsun1106/groovy-parser/tree/tryWithResources).
> In order to keep the same semantic with Java's try-with-resources, the
> implementation conforms to *JLS "14.20.3.
> try-with-resources"*(https://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html).
>
> Example codes can be found at
> https://github.com/danielsun1106/groovy-parser/blob/tryWithResources/src/test/resources/core/TryWithResources_01x.groovy
>
> Any thoughts?
you should rewrite that as proper test cases plus one in which you check
r1 inside the try-block. Nested versions of trys with ressoures are also
of interest.
And I assume the implementatio is totally missing, yes?
bye Jochen