I\'m using Groovy 1.8.4, trying to get the name of the enclosing function...
def myFunction() { println functionName?? }
I\'ve tried
import org.codehaus.groovy.runtime.StackTraceUtils def getCurrentMethodName(){ def marker = new Throwable() return StackTraceUtils.sanitize(marker).stackTrace[1].methodName } def helloFun(){ println( getCurrentMethodName() ) } helloFun()
output:
helloFun