Message-ID: <1347665103.2773.1429406504553.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_2772_303158141.1429406504552" ------=_Part_2772_303158141.1429406504552 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Groovy AST transformations must be performed in one of the nine = defined compiler pha= ses.=20
Global transformations may be applied in any phase, but local transforma= tions may only be applied in the semantic analysis phase or later. Briefly,= the compiler phases are:=20
Generally speaking, there is more type information available later in th= e phases. If your transformation is concerned with reading the AST, then a = later phase where information is more plentiful might be a good choice. If = your transformation is concerned with writing AST, then an earlier phase wh= ere the tree is more sparse might be more convenient.=20
As a particular example, Groovy aggressively and statically types the st=
atic properties of a class, as demonstrated here:
So if you want to create an AST transform that creates a static property= , you have to hook in before this check is performed: in practice, this mea= ns the Conversion phase (Semantic Analysis is where you get busted). = In using a phase that early, though, most types won't be resolved, and so i= nsofar as type resolution is significant (e.g. in checking for annotations = of a particular class), it will have to be hand-rolled.=20
To learn more about what AST is produced in each phase, you can use the = AST viewer in Groovy console to explore the output in different phases.