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

@Newify works for pre-defined classes but not for classes defined in the same script

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.8.1
    • None
    • None

    Description

      The current implementation expects to be given a ClassExpression for each class to Newify (for the Rubyesque style). Classes defined within the same script won't yet be processed into a ClassExpression but can be found in the source unit. The goal is to make the following work:

      import groovy.transform.Immutable
      abstract class Tree {}
      @Immutable class Branch extends Tree { Tree left, right }
      @Immutable class Leaf extends Tree { int val }
      @Newify([Branch, Leaf])
      def t = Branch(Leaf(1), Branch(Branch(Leaf(2), Leaf(3)), Leaf(4)))
      assert t.toString() == 'Branch(Leaf(1), Branch(Branch(Leaf(2), Leaf(3)), Leaf(4)))'
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: