Skip to content

DSLD: Add support for method parameter type annotations like @ClosureParams and @DelegatesTo #749

@eric-milles

Description

@eric-milles

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions