Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p>Here are some tips on how to debug what is happening on the transition from groovy source code into the generated bytecode.</p><table class="confluenceTable"><tbody><tr><th class="confluenceTh"><p>artifact</p></th><th class="confluenceTh"><p>transformation</p></th><th class="confluenceTh"><p>artifact</p></th></tr><tr><td class="confluenceTd"><p>source (<a class="confluence-link unresolved" data-filename="hello.groovy" data-linked-resource-default-alias="hello.groovy" href="#">hello.groovy</a>)</p></td><td class="confluenceTd"><p>GroovyLexer</p></td><td class="confluenceTd"><p>antlr tokens</p></td></tr><tr><td class="confluenceTd"><p>antlr tokens</p></td><td class="confluenceTd"><p>GroovyRecognizer</p></td><td class="confluenceTd"><p>antlr ast</p></td></tr><tr><td class="confluenceTd"><p>antlr ast</p></td><td class="confluenceTd"><p>AntlrParserPlugin</p></td><td class="confluenceTd"><p>groovy ast</p></td></tr><tr><td class="confluenceTd"><p>groovy ast</p></td><td class="confluenceTd"><p>AsmClassGenerator</p></td><td class="confluenceTd"><p>bytecode (<a class="confluence-link unresolved" data-filename="hello.class" data-linked-resource-default-alias="hello.class" href="#">hello.class</a>)</p></td></tr></tbody></table><p><em>Note1</em> <a href="http://fisheye.codehaus.org/browse/groovy/trunk/groovy/groovy-core/src/main/org/codehaus/groovy/antlr/groovy.g#r17581">groovy.g</a> is used to generate <a href="http://groovy.codehaus.org/jsr/spec/GroovyLexer.html">GroovyLexer</a> and <a href="http://groovy.codehaus.org/jsr/spec/GroovyRecognizer.html">GroovyRecognizer</a></p><p><em>Note2</em> <a href="http://groovy.codehaus.org/jsr/spec/GroovyRecognizer.html">GroovyRecognizer</a> is sometimes easier to understand in its <a href="http://groovy.codehaus.org/jsr/spec/grammar/">syntax diagram</a> form</p><p><em>Note3</em> <a href="https://fisheye.codehaus.org/browse/groovy/trunk/groovy/groovy-core/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java?hb=true">AntlrParserPlugin</a> source available.</p><h1>Example</h1><p>For these examples let's assume the file <a class="confluence-link unresolved" data-filename="hello.groovy" data-linked-resource-default-alias="hello.groovy" href="#">hello.groovy</a> contains</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>class Hello { static void main(args) { println "hello world" } } </pre></td></tr></table><h1>GroovyLexer (viewing Antlr Tokens)</h1><p>To view the antlr tokens that the source code has been broken into you need to do the following in groovy-core subdirectory</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>java -cp target/install/embeddable/groovy-all-1.6-beta-2.jar org.codehaus.groovy.antlr.LexerFrame </pre></td></tr></table><p><img class="confluence-embedded-image" src="/download/attachments/231082404/tokenstreamviewer.png?version=1&modificationDate=1371723091876" data-image-src="/download/attachments/231082404/tokenstreamviewer.png?version=1&modificationDate=1371723091876" data-linked-resource-id="231377399" data-linked-resource-type="attachment" data-linked-resource-default-alias="tokenstreamviewer.png" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231082404" title="null > tokenstreamviewer.png"></p><h1>GroovyRecognizer (viewing Antlr AST)</h1><p>To view the antlr AST that the recognized tokens have built</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>java -cp target/install/embeddable/groovy-all-1.6-beta-2.jar org.codehaus.groovy.antlr.Main -showtree Hello.groovy </pre></td></tr></table><p><img class="confluence-embedded-image" src="/download/attachments/231082404/antlrast.png?version=1&modificationDate=1371723091876" data-image-src="/download/attachments/231082404/antlrast.png?version=1&modificationDate=1371723091876" data-linked-resource-id="231377398" data-linked-resource-type="attachment" data-linked-resource-default-alias="antlrast.png" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231082404" title="null > antlrast.png"></p><h1>AntlrParserPlugin (viewing Groovy AST)</h1><p>To view the Groovy AST that is one step closer to the generated bytecode you can generate <a class="confluence-link unresolved" data-filename="hello.groovy.xml" data-linked-resource-default-alias="hello.groovy.xml" href="#">hello.groovy.xml</a> using these unix commands.</p><p>This can be generated by changing the <strong>groovy.ast</strong> system property. By doing this we can diff the generated Groovy AST artifacts for debugging and migration purposes.</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>$ export JAVA_OPTS="-Dgroovy.ast=xml" $ groovyc Hello.groovy Written AST to Hello.groovy.xml </pre></td></tr></table><p><img class="confluence-embedded-image" src="/download/attachments/231082404/groovyast.png?version=1&modificationDate=1371723091875" data-image-src="/download/attachments/231082404/groovyast.png?version=1&modificationDate=1371723091875" data-linked-resource-id="231377397" data-linked-resource-type="attachment" data-linked-resource-default-alias="groovyast.png" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231082404" title="null > groovyast.png"></p><h1>Viewing Bytecode</h1><p>One interesting bytecode viewer is <a href="http://www.ej-technologies.com/products/jclasslib/overview.html">jclasslib</a> which renders <a class="confluence-link unresolved" data-filename="hello.class" data-linked-resource-default-alias="hello.class" href="#">hello.class</a> in this manner...</p><p><img class="confluence-embedded-image" src="/download/attachments/231082404/jclasslib.png?version=1&modificationDate=1371723091860" data-image-src="/download/attachments/231082404/jclasslib.png?version=1&modificationDate=1371723091860" data-linked-resource-id="231377394" data-linked-resource-type="attachment" data-linked-resource-default-alias="jclasslib.png" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231082404" title="null > jclasslib.png"></p><h1>Decompiling bytecode back to Java</h1><p>If, however, you are bamboozled by bytecode... The easiest to grok mechanism for reading the compiled code is to use a tool like <a href="http://www.kpdus.com/jad.html">JAD</a> to decompile the <a class="confluence-link unresolved" data-filename="hello.class" data-linked-resource-default-alias="hello.class" href="#">hello.class</a> into a readable <a class="confluence-link unresolved" data-filename="hello.java" data-linked-resource-default-alias="hello.java" href="#">hello.java</a></p><p><img class="confluence-embedded-image" src="/download/attachments/231082404/jad.png?version=1&modificationDate=1371723091860" data-image-src="/download/attachments/231082404/jad.png?version=1&modificationDate=1371723091860" data-linked-resource-id="231377393" data-linked-resource-type="attachment" data-linked-resource-default-alias="jad.png" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231082404" title="null > jad.png"></p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced