Last active
October 20, 2016 13:23
-
-
Save christoph-daehne/f3fc7a4122ac29749475 to your computer and use it in GitHub Desktop.
Highlighted Groovy DSL example: Hello World
This file contains hidden or 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
class HelloWorldService { | |
void printHelloWorld() { | |
println("Hello World") | |
} | |
} | |
class HelloWorldScript { | |
// by annotating the parameter we gain syntax highlighting and auto-completion | |
static void execute(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = HelloWorldService) Closure script) { | |
script.resolveStrategy = Closure.DELEGATE_FIRST | |
script.delegate = new HelloWorldService() | |
script() | |
} | |
} | |
HelloWorldScript.execute { | |
printHelloWorld() | |
for(def i = 0; i < 10; i++) { | |
printHelloWorld() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment