Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Apache Groovy
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Abstract syntax tree transformation=== According to Groovy's own documentation, "When the Groovy compiler compiles Groovy scripts and classes, at some point in the process, the source code will end up being represented in memory in the form of a Concrete Syntax Tree, then transformed into an Abstract Syntax Tree. The purpose of AST Transformations is to let developers hook into the compilation process to be able to modify the AST before it is turned into bytecode that will be run by the JVM. AST Transformations provides Groovy with improved compile-time metaprogramming capabilities allowing powerful flexibility at the language level, without a runtime performance penalty."<ref>{{cite web |url=http://groovy.codehaus.org/Compile-time+Metaprogramming+-+AST+Transformations |title=Compile-time Metaprogramming - AST Transformations |access-date=2012-10-07 |archive-url=https://web.archive.org/web/20121014094900/http://groovy.codehaus.org/Compile-time+Metaprogramming+-+AST+Transformations |archive-date=2012-10-14 |url-status=dead }}</ref> Examples of ASTs in Groovy are: * Category and [[Mixin]] transformation * Immutable AST Macro * Newify transformation * Singleton transformation among others. The testing framework [[Spock (testing framework)|Spock]] uses AST transformations to allow the programmer to write tests in a syntax not supported by Groovy, but the relevant code is then manipulated in the AST to valid code.<ref>{{cite journal |last1=King |first1=Paul |title=A History of the Groovy Programming Language |journal=Proc. ACM Program. Lang. |date=2020 |volume=4 |pages=53 |doi=10.1145/3386326|doi-access=free }}</ref> An example of such a test is: <syntaxhighlight lang="groovy"> def "maximum of #a and #b is #c" () { expect: Math.max (a, b) == c where: a | b || c 3 | 5 || 5 7 | 0 || 7 0 | 0 || 0 } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)