castor
  1. castor
  2. CASTOR-2827

Improve generation of java5 enums for simpleType enumerations

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.3
    • Fix Version/s: 1.3.1
    • Component/s: XML code generator
    • Labels:
      None
    • Patch Submitted:
      Yes
    • Number of attachments :
      1

      Description

      Generation of java5 enums for simpleType enumeration has been added in Castor v1.2 (see CASTOR-2117 issue). castor-maven-plugin v1.5 depends on castor-codegen v1.2 and generates java5 enums well, but I'd like to suggest following few improvements:

      1. all java 5 enums implement Serializable (and Comparable too; see java.lang.Enum javadoc), so there is no need to generate "implements java.io.Serializable"
      2. similarly, there is no need to generate '@SuppressWarnings("serial")' since there is no need to specify serialVersionUID anyway, all enums have a fixed serialVersionUID = 0L, and even if one specifies different value it is being ignored
      3. since all simpleType enumerations have a value, and Castor generates a value property for them and uses/sets that value in Enum constructor for every Enum constant, generated fromValue method could be optimized so that currently used for-loop over the Enum values is replaced with a Map of (value, Enum constant) pairs filled using a static initializer, all for increased efficiency.

      Attached patch implements all 3 suggested improvements. To support removal of "implements Serializable", a removeInterface method has been added to org.exolab.javasource.JStructure Castor source code model class. All the rest of the changes have been made solely to the org.exolab.castor.builder.factory.EnumerationFactory class and it's createJava5Enum method.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Werner Guttmann
            Reporter:
            Stevo Slavic
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 20 minutes
              20m
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 20 minutes
              20m