jaxb-ri icon indicating copy to clipboard operation
jaxb-ri copied to clipboard

JJavaName.getPluralForm(String) is too simplistic.

Open patrodyne opened this issue 3 years ago • 1 comments

The method String getPluralForm(String word) in class com.sun.codemodel.JJavaName uses case insensitive patterns to map singular words to their plural form. Because of this, the plural of Child (uppercase) becomes children (lowercase). Applications that use codemodel (i.e. XJC) to generate code are impacted and produce code like getchildren() instead of getChildren().

Further, the pluralization algorithm in JJavaName is a simplistic approach to a complex problem. It has many deficiencies, for example #402. The approach in JJavaName should be refactored to delegate the pluralization to a library like Evo-Inflector. The sole purpose of Evo Inflector is to be a pluralization library. I have no affiliation with that project but I have attached, evo-inflector-main.tar.gz, a small tar-ball containing a stand-alone application to demonstrate the Evo-Inflector library (jar). The library is maintained, with releases to Maven Central, and has a simple API, a small footprint and no runtime dependencies and uses the Apache 2.0 license.

Here is how the Evo-Inflector API fixes the examples in Issue #402, as well as the subject of this issue:

Singular Plural
Vif Vifs
Mouse Mice
Pan Pans
Plum Plums
Child Children

patrodyne avatar Nov 26 '22 23:11 patrodyne

@Tomas-Kraus, @lukasj, I understand that you don't want to change the pluralization rules because of backward compatibility. But what if you added an option to enable pluralization in simple binding mode and turned it on by default? If that's not possible, maybe there could be an option to disable it or customize it with a plugin.

That way, existing projects wouldn't be affected after upgrading the package, but the feature could still be turned off if it doesn't work correctly.

bllngr avatar Sep 06 '24 06:09 bllngr