groovy

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

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.5, 1.5.1
  • Fix Version/s: 1.5.2
  • Component/s: groovy-jdk
  • Labels:
    None
  • Testcase included:
    yes
  • Patch Submitted:
    Yes
  • Number of attachments :
    1

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.

Activity

Hide
Paul King added a comment -

Patch looks good to me.

Show
Paul King added a comment - Patch looks good to me.
Hide
Paul King added a comment -

Added

Show
Paul King added a comment - Added
Hide
Paul King added a comment -

close off release 1.5.4

Show
Paul King added a comment - close off release 1.5.4

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: