publicstaticvoid main(String... args) {
List<String> errors = new ArrayList<>(); // Ensure that all Message fields have a corresponding key/value // in the resource bundle and that mnemonics can be looked // up where applicable.
Module module = sun.tools.jconsole.Messages.class.getModule();
ResourceBundle rb = ResourceBundle.getBundle(RESOURCE_BUNDLE, module); for (Field field : Messages.class.getFields()) { if (isResourceKeyField(field)) {
String resourceKey = field.getName();
String message = readField(field); if (message.startsWith(MISSING_RESOURCE_KEY_PREFIX)) {
errors.add("Can't find message (and perhaps mnemonic) for "
+ Messages.class.getSimpleName() + "."
+ resourceKey + " in resource bundle.");
} else {
String resourceMessage = rb.getString(resourceKey); if (hasMnemonicIdentifier(resourceMessage)) { int mi = Resources.getMnemonicInt(message); if (mi == 0) {
errors.add("Could not look up mnemonic for message '"
+ message + "'.");
}
}
}
}
}
// Ensure that there is Message class field for every resource key. for (String key : Collections.list(rb.getKeys())) { try {
Messages.class.getField(key);
} catch (NoSuchFieldException nfe) {
errors.add("Can't find static field ("
+ Messages.class.getSimpleName() + "." + key
+ ") matching '" + key
+ "' in resource bundle. Unused message?");
}
}
if (errors.size() > 0) {
throwError(errors);
}
}
privatestatic String readField(Field field) { try { return (String) field.get(null);
} catch (IllegalArgumentException | IllegalAccessException e) { thrownew Error("Could not access field " + field.getName()
+ " when trying to read resource message.");
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.