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

Provide an enhanced each() method for subclasses of java.lang.Enum

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.5, 1.5.1
    • 1.5.2
    • groovy-jdk
    • None
    • Patch

    Description

      Currently the each() method for subclasses of java.lang.Enum is the default each() method that returns the enum class itself in a single-element list. I believe it would be useful for the each() method to iterate through the values of the enum.

      The provided patch implements this functionality by providing enum-specific behavior in DefaultTypeTransformation.asCollection(). This makes each(), eachWithIndex(), for (... in ...), and perhaps other constructs use the enum values as the collection instead of the single element list containing the enum class itself.

      The provided test case tests only each() and the for/in behavior. It also introduces a new groovy.vm5.GroovyMethodsTest class for DGM tests that should only be run under Java 5 and later.

      Attachments

        Activity

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

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment