Created
September 30, 2014 19:41
-
-
Save spmallette/b0fdb3ed8166a4d3c3a2 to your computer and use it in GitHub Desktop.
Groovy Script From Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getClosureBody(final Closure closure) { | |
def node = closure.getMetaClass().getClassNode().getDeclaredMethods("doCall")[0].getCode(); | |
def writer = new StringWriter() | |
node.visit(new AstNodeToGremlinScriptVisitor(writer)) | |
return writer.toString() | |
} | |
class AstNodeToGremlinScriptVisitor extends AstNodeToScriptVisitor { | |
def AstNodeToGremlinScriptVisitor(Writer writer, boolean showScriptFreeForm = true, boolean showScriptClass = true) { | |
super(writer, showScriptFreeForm, showScriptClass) | |
} | |
@Override | |
void visitReturnStatement(ReturnStatement statement) { | |
// printLineBreak() | |
// print 'return ' | |
statement.getExpression().visit(this) | |
printLineBreak() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment