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

Enhance Closure annotation value (as Closure class) to Arrays

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.0.7, 4.0.0-alpha-2
    • None
    • None

    Description

      The background for this request is annotations in the picocli library. The annotations API of this library allows applications to specify a class or an array of classes to customize some behaviour. For example:

      // current picocli (4.5.2) requires explicit class(es), does not support Closures
      @Option(names = "-x",
              completionCandidates = MyCandidates.class, 
              converter = [StringConverter.class, MessageDigestConverter.class])
      Map<String, MessageDigest> someOption;
      

      There is work in progress in the picocli library to allow applications to specify closures for such classes in the annotations. For example, I would like applications to be able to do this:

      // next version of picocli (4.6.0) aims to support Closures in these annotation attributes
      @picocli.CommandLine.Option(names = "-x",
              completionCandidates = {["A", "B", "C"]},
              converter = [ {it}, { str -> java.security.MessageDigest.getInstance(str) } ])
      Map<String, java.security.MessageDigest> someOption
      

      With the current version of Groovy (3.0.6), this works for the single-value attributes like completionCandidates, but does not work for attributes that take an array of values, like converter.

      Please add support for arrays in the Closure to Class conversion for annotations.

      See also discussion on the groovy-dev mailing list.

      Attachments

        Activity

          People

            paulk Paul King
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 50m
                50m