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

Groovy doesn't follow JavaBeans Specification on method name to property name decapitialization

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.6, 1.6-beta-1, 1.5.7, 1.6-beta-2
    • 1.6-rc-1, 1.6-rc-2
    • None
    • None
    • Patch

    Description

      Like the title says.

      For a Groovy property named 'PROPERTY' for example, rather than following JavaBeans Specification section 8.8 which says to preserve the initial capital, Groovy will always lowercase it.

      Sun Microsystems 57 10/12/97

      8.8 Capitalization of inferred names.

      When we use design patterns to infer a property or event name, we need to decide what rules
      to follow for capitalizing the inferred name. If we extract the name from the middle of a normal
      mixedCase style Java name then the name will, by default, begin with a capital letter.

      Java programmers are accustomed to having normal identifiers start with lowercase letters.
      Vigorous reviewer input has convinced us that we should follow this same conventional rule
      for property and event names.

      Thus when we extract a property or event name from the middle of an existing Java name, we
      normally convert the first character to lowercase. However to support the occasional use of all
      upper-casenames, we check if the first two characters of the name are both uppercase and if
      so leave it alone. So for example,

      "FooBah" becomes "fooBah"
      "Z" becomes "z"
      "URL" becomes "URL"

      We provide a method Introspector.decapitalize which implements this conversion rule.

      This isn't an all one way deal though. Groovy has another rule about looking at the initial letter in some contexts to decide whether the name is a class (uppercase) or a property/method name (lowercase).

      Also it would be difficult to preserve property names that begin with an initial lowercase and the rest if uppercase because the JavaBeans decapitalization rule will upcase that initial letter. Fixing that would require Groovy to generate a BeanInfo for the class in those cases (or all cases which would allow for dispensing with the expensive introspection/reflection stuff).

      Attachments

        1. the-real-propname-patch-again.txt
          11 kB
          James P. White

        Issue Links

          Activity

            People

              jimwhite James P. White
              jimwhite James P. White
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: