config.dsld:
def configBlock = { -> enclosingCall(name('withConfig') & hasArgument('configuration')) & inClosure() & isThisType() }
contribute(configBlock()) {
method(name:'imports', type:void, params:[block:'@DelegatesTo(org.codehaus.groovy.control.customizers.builder.ImportCustomizerFactory.ImportHelper) Closure'])
method(name:'inline', type:void, params:[code:'@ClosureParams(value=SimpleType, options=["org.codehaus.groovy.control.SourceUnit","org.codehaus.groovy.classgen.GeneratorContext","org.codehaus.groovy.ast.ClassNode"]) Closure'], namedParams:[phase:String], optionalParams:[superClass:Class, interfaces:Class[]])
}
config.groovy
withConfig(configuration) {
imports {
star 'groovy.transform'
normal 'java.util.regex.Matcher'
normal 'java.util.regex.Pattern'
alias 'Regexp', 'java.util.regex.Pattern'
staticMember 'java.util.concurrent.TimeUnit', 'SECONDS'
staticMember 'MILLIS', 'java.util.concurrent.TimeUnit', 'MILLISECONDS'
}
inline(phase:'CONVERSION') { sourceUnit, generatorContext, classNode ->
}
}
The methods star, normal, etc. within the imports block should be known due to @DelegatesTo parameter annotation. The parameters sourceUnit, generatorContext and classNode should be inferred due to @ClosureParams parameter type annotation.
config.dsld:
config.groovy
withConfig(configuration) { imports { star 'groovy.transform' normal 'java.util.regex.Matcher' normal 'java.util.regex.Pattern' alias 'Regexp', 'java.util.regex.Pattern' staticMember 'java.util.concurrent.TimeUnit', 'SECONDS' staticMember 'MILLIS', 'java.util.concurrent.TimeUnit', 'MILLISECONDS' } inline(phase:'CONVERSION') { sourceUnit, generatorContext, classNode -> } }The methods
star,normal, etc. within the imports block should be known due to@DelegatesToparameter annotation. The parameterssourceUnit,generatorContextandclassNodeshould be inferred due to@ClosureParamsparameter type annotation.