Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7956

Provide an AST transformation which improves named parameter support

Agile BoardAttach filesAttach ScreenshotVotersStop watchingWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.5.0-beta-3
    • GEP
    • None

    Description

      In order to aid static compilation for builders we have @DelegatesTo which allows statically compiled code to know what the delegate of a closure is.

      This proposal is to allow @DelegatesTo on Map types such that IDEs and the static compiler can resolve the target type the named arguments are to be used on.

      For example:

      class Farm {
           void animal(@DelegatesTo(Animal) Map arguments, @DelegatesTo(AnimalBuilder) Closure callable) {
                   def animal = new Animal(arguments)
                   // handle closure
          }
      } 
      
      class Animal { String name }
      

      The following code would then fail to compile :

      def farm = new Farm()
      // compilation failure, no name property on Animal
      farm.animal(nam: "Dog")  { 
      }
      

      It would then be down to IDEs to also provide support for code completion etc.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            paulk Paul King
            graemerocher1 Graeme Rocher
            Votes:
            5 Vote for this issue
            Watchers:
            9 Stop watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment