Skip to content

Commit 31295ab

Browse files
Next examples
1 parent cf33c69 commit 31295ab

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

modello-core/src/main/java/org/codehaus/modello/plugin/AbstractModelloGenerator.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public abstract class AbstractModelloGenerator implements ModelloGenerator {
111111
PLURAL_EXCEPTIONS.put("movies", "movie");
112112

113113
// Special "ves" exceptions
114+
PLURAL_EXCEPTIONS.put("archives", "archive");
114115
PLURAL_EXCEPTIONS.put("relatives", "relative");
115116
}
116117

@@ -260,6 +261,15 @@ public static String singular(String name) {
260261

261262
String lower = name.toLowerCase();
262263

264+
if (!lower.equals(name)) {
265+
// we can have a case like otherArchives
266+
String[] split = splitByUpperCase(name);
267+
if (split != null && PLURAL_EXCEPTIONS.containsKey(split[1])) {
268+
String plural = PLURAL_EXCEPTIONS.get(split[1]);
269+
return split[0] + Character.toUpperCase(plural.charAt(0)) + plural.substring(1);
270+
}
271+
}
272+
263273
if (PLURAL_EXCEPTIONS.containsKey(lower)) {
264274
return PLURAL_EXCEPTIONS.get(lower);
265275
}
@@ -299,6 +309,15 @@ public static String singular(String name) {
299309
return name;
300310
}
301311

312+
private static String[] splitByUpperCase(String name) {
313+
for (int i = name.length() - 1; i >= 0; i--) {
314+
if (Character.isUpperCase(name.charAt(i))) {
315+
return new String[] {name.substring(0, i), name.substring(i).toLowerCase()};
316+
}
317+
}
318+
return null;
319+
}
320+
302321
public static String uncapitalise(String str) {
303322
if (StringUtils.isEmpty(str)) {
304323
return str;

modello-core/src/test/java/org/codehaus/modello/plugin/AbstractModelloGeneratorTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class AbstractModelloGeneratorTest {
6363
"foxes, fox",
6464

6565
// Some test cases with different rules
66+
"archives, archive",
67+
"otherArchives, otherArchive",
68+
"Archives, Archive",
6669
"wolves, wolf",
6770
"knives, knife",
6871
"leaves, leaf",

0 commit comments

Comments
 (0)