diff --git a/platform/util/src/com/intellij/openapi/util/text/Pluralizer.java b/platform/util/src/com/intellij/openapi/util/text/Pluralizer.java
index 5474e2d78b8e..d1629614bbc9 100644
--- a/platform/util/src/com/intellij/openapi/util/text/Pluralizer.java
+++ b/platform/util/src/com/intellij/openapi/util/text/Pluralizer.java
@@ -63,7 +63,7 @@ class Pluralizer {
* Pass in a word token to produce a function that can replicate the case on
* another word.
*/
- private static String restoreCase(String word, String result) {
+ static String restoreCase(String word, String result) {
if (word == null || result == null || word == result) return result;
char[] chars = result.toCharArray();
boolean prevUp = false;
@@ -173,20 +173,20 @@ class Pluralizer {
*/
JBIterable.of(new String[][]{
// Pronouns.
- {"I", "we"},
- {"me", "us"},
- {"he", "they"},
- {"she", "they"},
- {"them", "them"},
- {"myself", "ourselves"},
- {"yourself", "yourselves"},
- {"itself", "themselves"},
- {"herself", "themselves"},
- {"himself", "themselves"},
- {"themself", "themselves"},
- {"is", "are"},
- {"was", "were"},
- {"has", "have"},
+ //{"I", "we"},
+ //{"me", "us"},
+ //{"he", "they"},
+ //{"she", "they"},
+ //{"them", "them"},
+ //{"myself", "ourselves"},
+ //{"yourself", "yourselves"},
+ //{"itself", "themselves"},
+ //{"herself", "themselves"},
+ //{"himself", "themselves"},
+ //{"themself", "themselves"},
+ //{"is", "are"},
+ //{"was", "were"},
+ //{"has", "have"},
{"this", "these"},
{"that", "those"},
// Words ending in with a consonant and `o`.
diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
index 4e9b313020fb..1fa20da94898 100644
--- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
+++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
@@ -832,7 +832,9 @@ public class StringUtil extends StringUtilRt {
@NotNull
@Contract(pure = true)
public static String pluralize(@NotNull String word) {
- return Pluralizer.PLURALIZER.plural(word);
+ String plural = Pluralizer.PLURALIZER.plural(word);
+ return equalsIgnoreCase(plural, word) && !endsWithIgnoreCase(plural, "es") ?
+ Pluralizer.restoreCase(word, word + "s") : plural;
}
@NotNull
@@ -1645,13 +1647,17 @@ public class StringUtil extends StringUtilRt {
* Returns unpluralized variant using English based heuristics like properties -> property, names -> name, children -> child.
* Returns null if failed to match appropriate heuristic.
*
- * @param name english word in plural form
+ * @param word english word in plural form
* @return name in singular form or null if failed to find one.
*/
@Nullable
@Contract(pure = true)
public static String unpluralize(@NotNull String word) {
- return Pluralizer.PLURALIZER.singular(word);
+ String singular = Pluralizer.PLURALIZER.singular(word);
+ if (equalsIgnoreCase(singular, word)) {
+ singular = nullize(trimEnd(singular, "s", true));
+ }
+ return equalsIgnoreCase(singular, word) ? null : singular;
}
@Contract(pure = true)
diff --git a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java
index e1594bc26518..f41583eeda94 100644
--- a/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java
+++ b/platform/util/testSrc/com/intellij/util/text/StringUtilTest.java
@@ -98,7 +98,9 @@ public class StringUtilTest {
@Test
public void testUnPluralize() {
- assertEquals("s", StringUtil.unpluralize("s"));
+ assertEquals("plurals", StringUtil.unpluralize("pluralss"));
+ assertEquals("I", StringUtil.unpluralize("Is"));
+ assertEquals(null, StringUtil.unpluralize("s"));
assertEquals("z", StringUtil.unpluralize("zs"));
assertEquals("Index", StringUtil.unpluralize("Indices"));
assertEquals("fix", StringUtil.unpluralize("fixes"));