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

@Sortable annotation is not able to use accessible parent properties

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.12
    • 2.5.2
    • groovy-runtime
    • None
    • Linux 4.16.7 x86_64
      Java(TM) SE Runtime Environment (build 1.8.0_172-b11)

    Description

      The @Sortable annotation does not appear to support sorting by parent properties, e.g.

      Error:(22, 5) Groovyc: Error during @Sortable processing: tried to include unknown property 'name'
      

      Example:

      import groovy.transform.Sortable
      import groovy.transform.ToString
      
      class SortableSpec {
      
        static void main(String[] args) {
          new SortableSpec().run()
        }
      
        void run() {
          Random random = Random.newInstance()
      
          (0..9).collect {
            new Thing(name: "${random.nextDouble()}")
          }.sort().each { println it }
        }
      
        static class Base {
          String name
        }
      
        // @Sortable(includes = 'name') <- fails compilation
        @Sortable
        @ToString(includeSuperProperties = true)
        final static class Thing extends Base {}
      
      }
      

      Attachments

        1. SortableSpec.groovy
          0.6 kB
          Gus Power

        Issue Links

          Activity

            People

              paulk Paul King
              guspower Gus Power
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: