From 090f468b74359cd8e2a41b00d5eeebec6ce87693 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Fri, 30 Nov 2018 19:48:42 +0100 Subject: [PATCH] format ordinal numbers after ten correctly (IDEA-202990) --- .../src/messages/QuickFixBundle.properties | 6 +++--- .../ChangeMethodSignatureFromUsageFix.java | 6 +++--- .../openapi/util/text/StringUtil.java | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/java/java-analysis-impl/src/messages/QuickFixBundle.properties b/java/java-analysis-impl/src/messages/QuickFixBundle.properties index b978116a2e35..7e71e64d703f 100644 --- a/java/java-analysis-impl/src/messages/QuickFixBundle.properties +++ b/java/java-analysis-impl/src/messages/QuickFixBundle.properties @@ -57,9 +57,9 @@ change.method.signature.from.usage.family=Change method signature from usage # {0} - original method signature including name, {1} - method name, {2} - proposed new parameters list change.method.signature.from.usage.text=Change signature of ''{0}'' to ''{1}({2})'' -add.parameter.from.usage.text=Add ''{0}'' as {1, choice, 1#1st|2#2nd|3#3rd|4#{1,number}th} parameter to method ''{2}'' -remove.parameter.from.usage.text=Remove {0, choice, 1#1st|2#2nd|3#3rd|4#{0,number}th} parameter from method ''{1}'' -change.parameter.from.usage.text=Change {0, choice, 1#1st|2#2nd|3#3rd|4#{0,number}th} parameter of method ''{1}'' from ''{2}'' to ''{3}'' +add.parameter.from.usage.text=Add ''{0}'' as {1} parameter to method ''{2}'' +remove.parameter.from.usage.text=Remove {0} parameter from method ''{1}'' +change.parameter.from.usage.text=Change {0} parameter of method ''{1}'' from ''{2}'' to ''{3}'' searching.for.usages.progress.title=Searching For Usages... create.class.from.new.family=Create Class from New create.class.from.new.text=Create class ''{0}'' diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java index f1cb0555876c..f0d7335c1475 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java @@ -107,15 +107,15 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction/*, Hig if (newParams.size() == 1) { final ParameterInfoImpl p = newParams.iterator().next(); return QuickFixBundle - .message("add.parameter.from.usage.text", p.getTypeText(), (ArrayUtil.find(myNewParametersInfo, p) + 1), targetMethodName); + .message("add.parameter.from.usage.text", p.getTypeText(), StringUtil.formatOrdinal(ArrayUtil.find(myNewParametersInfo, p) + 1), targetMethodName); } if (removedParams.size() == 1) { final ParameterInfoImpl p = removedParams.iterator().next(); - return QuickFixBundle.message("remove.parameter.from.usage.text", (p.getOldIndex() + 1), targetMethodName); + return QuickFixBundle.message("remove.parameter.from.usage.text", StringUtil.formatOrdinal(p.getOldIndex() + 1), targetMethodName); } if (changedParams.size() == 1) { final ParameterInfoImpl p = changedParams.iterator().next(); - return QuickFixBundle.message("change.parameter.from.usage.text", (p.getOldIndex() + 1), targetMethodName, + return QuickFixBundle.message("change.parameter.from.usage.text", StringUtil.formatOrdinal(p.getOldIndex() + 1), targetMethodName, myTargetMethod.getParameterList().getParameters()[p.getOldIndex()].getType().getPresentableText(), p.getTypeText()); } 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 45c78c6827ae..03ce289f9ee5 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -1634,6 +1634,25 @@ public class StringUtil extends StringUtilRt { return sb.toString(); } + public static String formatOrdinal(int i) { + int mod = i % 100; + if (mod == 11 || mod == 12 || mod == 13) { + return i + "th"; + } + + mod = mod % 10; + if (mod == 1) { + return i + "st"; + } + else if (mod == 2) { + return i + "nd"; + } + else if (mod == 3) { + return i + "rd"; + } + return i + "th"; + } + /** * Returns unpluralized variant using English based heuristics like properties -> property, names -> name, children -> child. * Returns {@code null} if failed to match appropriate heuristic.