This is a small AST transformation that allows you to get the source code of a Class at run-time.
@SaveSource
class AClass {
def getCode() {
SourceCode sourceCode = this.class.getAnnotation(SourceCode)
return sourceCode.value()
}
}
You can add a dependency to you build via jitpack.
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
compile 'com.github.MeneDev:groovy-get-source:96746d39f3'
}
This was created as an answer to the question Source code of current file in Groovy on Stackoverflow.