groovy
  1. groovy
  2. GROOVY-4876

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

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.8.1
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      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)))'
      

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Paul King
            Reporter:
            Paul King
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: