{"id":1930,"date":"2019-04-02T08:24:03","date_gmt":"2019-04-02T12:24:03","guid":{"rendered":"http:\/\/codinggorilla.com\/?p=1930"},"modified":"2019-04-03T13:25:38","modified_gmt":"2019-04-03T17:25:38","slug":"series-on-program-transformation-systems-spoon-2004","status":"publish","type":"post","link":"http:\/\/165.227.223.229\/index.php\/2019\/04\/02\/series-on-program-transformation-systems-spoon-2004\/","title":{"rendered":"Series on program transformation systems: Spoon  (2005)"},"content":{"rendered":"\n<p> This is the next entry in the series on program transformation systems. This article describes <a href=\"http:\/\/spoon.gforge.inria.fr\/index.html\">Spoon<\/a>, a system for Java source code. It has been in development since 2005 and is actively being developed to this day.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>One part of Spoon is an API to modify the abstract syntax tree of a Java program. For example, the API has methods to add or delete classes, methods, methods, and statements. <a href=\"http:\/\/spoon.gforge.inria.fr\/processor.html\">An example shown on Spoon&#8217;s website<\/a> checks for empty <em>catch<\/em> blocks using an API for visiting tree nodes. As noted,  &#8220;[t]he concept of a <g class=\"gr_ gr_7 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace\" id=\"7\" data-gr-id=\"7\">CtScanner<\/g> is a &#8220;visitor pattern&#8221;, which can be applied to <g class=\"gr_ gr_8 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins replaceWithoutSep\" id=\"8\" data-gr-id=\"8\">processing<\/g> of Abstract [S]yntax [T]ree.&#8221;<\/p>\n\n\n\n<p>The second part of Spoon uses Java Annotations. <a href=\"http:\/\/spoon.gforge.inria.fr\/processor_annotations.html\">An example they give<\/a> shows how to insert a check into the code for a null parameter check. They note that &#8220;[t]he implementation of such an annotation would not be straightforward using Java&#8217;s processing API since it would not allow us to just insert the NULL check in the body of the annotated method.&#8221; It isn&#8217;t clear to me what API they are referring to, or why Spoon&#8217;s API for modifying an AST could not be used to insert a null check.<\/p>\n\n\n\n<h2>Observations and notes<\/h2>\n\n\n\n<ul><li>Spoon is a compiler system that parses Java source code, computes ASTs, provides for program transformation on that AST using an AST visitor API. But, as noted with C-Breeze, there is no pattern matching\/rewrite language for ASTs. So, it is very low level.<\/li><\/ul>\n\n\n\n<h2>References<\/h2>\n\n\n\n<p>Pawlak, R., Monperrus, M., Petitprez, N., Noguera, C. and Seinturier, L., 2016. Spoon: A library for implementing analyses and transformations of java source code. <em>Software: Practice and Experience<\/em>,&nbsp;<em>46<\/em>(9), pp.1155-1179. <\/p>\n\n\n\n<h2>Additional Reading<\/h2>\n\n\n\n<p><a href=\"http:\/\/spoon.gforge.inria.fr\/\">http:\/\/spoon.gforge.inria.fr\/<\/a> <br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the next entry in the series on program transformation systems. This article describes Spoon, a system for Java source code. It has been in development since 2005 and is actively being developed to this day.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/1930"}],"collection":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/comments?post=1930"}],"version-history":[{"count":0,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/1930\/revisions"}],"wp:attachment":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/media?parent=1930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/categories?post=1930"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/tags?post=1930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}