Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eric-milles opened this issue Oct 23, 2018 · 0 comments
Assignees
Milestone

Comments

@eric-milles
Copy link
Member

eric-milles commented Oct 23, 2018

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.

@eric-milles eric-milles added this to the v3.2.0 milestone Oct 23, 2018
@eric-milles eric-milles self-assigned this Oct 23, 2018
@eric-milles eric-milles changed the title DSLD: Add support for method and property type annotations DSLD: Add support for method parameter type annotations like @ClosureParams and @DelegatesTo Oct 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant