Using the answer to which I am bound as a duplicate of this if you save:
import groovy.inspect.swingui.AstNodeToScriptVisitor def a = { assert 1 == 1 } def method( def a ) { new StringWriter().with { writer -> a.metaClass.classNode.getDeclaredMethods("doCall")[0].code.visit new AstNodeToScriptVisitor( writer ) println "{\n$writer}" } } method( a )
into the test.groovy file, then do:
groovy test.groovy
You get the conclusion:
{ assert 1 == 1 : null return null }
Be that as it may, I think ... Without using positional data in the code variable (which is the Groovy Class Statement ) to get the row / column numbers and parse the file as text to extract it ...
source share