From 9e43d8b507ede44bb2bff110315f66e6c50cd2dd Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 7 Dec 2018 15:11:51 +0100 Subject: [PATCH] Cleanup (warnings; formatting) --- .../application/impl/ApplicationImpl.java | 5 +- .../util-rt/src/com/intellij/BundleBase.java | 90 +++++++++---------- 2 files changed, 45 insertions(+), 50 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index b47bcda7e7c9..43e6e9e4c94b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -131,8 +131,9 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App getPicoContainer().registerComponentInstance(Application.class, this); getPicoContainer().registerComponentInstance(TransactionGuard.class.getName(), myTransactionGuard); - //noinspection AssignmentToStaticFieldFromInstanceMethod - IconLoader.setStrictGlobally(BundleBase.assertKeyIsFound = isUnitTestMode || isInternal); + boolean strictMode = isUnitTestMode || isInternal; + BundleBase.assertOnMissedKeys(strictMode); + IconLoader.setStrictGlobally(strictMode); AWTExceptionHandler.register(); // do not crash AWT on exceptions diff --git a/platform/util-rt/src/com/intellij/BundleBase.java b/platform/util-rt/src/com/intellij/BundleBase.java index be81b10123fd..d2ba8d0fe3cd 100644 --- a/platform/util-rt/src/com/intellij/BundleBase.java +++ b/platform/util-rt/src/com/intellij/BundleBase.java @@ -18,7 +18,16 @@ public abstract class BundleBase { public static final char MNEMONIC = 0x1B; public static final String MNEMONIC_STRING = Character.toString(MNEMONIC); - public static boolean assertKeyIsFound = false; + private static boolean assertOnMissedKeys = false; + + public static void assertOnMissedKeys(boolean doAssert) { + assertOnMissedKeys = doAssert; + } + + @NotNull + public static String message(@NotNull ResourceBundle bundle, @NotNull String key, @NotNull Object... params) { + return messageOrDefault(bundle, key, null, params); + } public static String messageOrDefault(@Nullable ResourceBundle bundle, @NotNull String key, @@ -36,7 +45,7 @@ public abstract class BundleBase { } else { value = "!" + key + "!"; - if (assertKeyIsFound) { + if (assertOnMissedKeys) { assert false : "'" + key + "' is not found in " + bundle; } } @@ -56,59 +65,44 @@ public abstract class BundleBase { @NotNull public static String format(@NotNull String value, @NotNull Object... params) { - if (params.length > 0 && value.indexOf('{') >= 0) { - return MessageFormat.format(value, params); - } - - return value; + return params.length > 0 && value.indexOf('{') >= 0 ? MessageFormat.format(value, params) : value; } - @NotNull - public static String message(@NotNull ResourceBundle bundle, @NotNull String key, @NotNull Object... params) { - return messageOrDefault(bundle, key, null, params); - } - - public static String replaceMnemonicAmpersand(@Nullable final String value) { - if (value == null) { - return null; + public static String replaceMnemonicAmpersand(@Nullable String value) { + if (value == null || value.indexOf('&') < 0) { + return value; } - if (value.indexOf('&') >= 0) { - boolean useMacMnemonic = value.contains("&&"); - StringBuilder realValue = new StringBuilder(); - int i = 0; - while (i < value.length()) { - char c = value.charAt(i); - if (c == '\\') { - if (i < value.length() - 1 && value.charAt(i + 1) == '&') { - realValue.append('&'); - i++; - } - else { - realValue.append(c); - } - } - else if (c == '&') { - if (i < value.length() - 1 && value.charAt(i + 1) == '&') { - if (SystemInfoRt.isMac) { - realValue.append(MNEMONIC); - } - i++; - } - else { - if (!SystemInfoRt.isMac || !useMacMnemonic) { - realValue.append(MNEMONIC); - } - } + StringBuilder builder = new StringBuilder(); + boolean macMnemonic = value.contains("&&"); + int i = 0; + while (i < value.length()) { + char c = value.charAt(i); + if (c == '\\') { + if (i < value.length() - 1 && value.charAt(i + 1) == '&') { + builder.append('&'); + i++; } else { - realValue.append(c); + builder.append(c); } - i++; } - - return realValue.toString(); + else if (c == '&') { + if (i < value.length() - 1 && value.charAt(i + 1) == '&') { + if (SystemInfoRt.isMac) { + builder.append(MNEMONIC); + } + i++; + } + else if (!SystemInfoRt.isMac || !macMnemonic) { + builder.append(MNEMONIC); + } + } + else { + builder.append(c); + } + i++; } - return value; + return builder.toString(); } -} +} \ No newline at end of file