Cleanup (warnings; formatting)

This commit is contained in:
Roman Shevchenko
2018-12-07 15:12:14 +01:00
parent d633ea4419
commit 9e43d8b507
2 changed files with 45 additions and 50 deletions
@@ -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
@@ -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();
}
}
}