Class LocalizedMessage
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.LocalizedMessage
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<LocalizedMessage>
public final class LocalizedMessage extends java.lang.Object implements java.lang.Comparable<LocalizedMessage>, java.io.Serializable
Represents a message that can be localised. The translations come from message.properties files. The underlying implementation uses java.text.MessageFormat.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLocalizedMessage.Utf8ControlCustom ResourceBundle.Control implementation which allows explicitly read the properties files as UTF-8.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object[]argsArguments for MessageFormat.private java.lang.StringbundleName of the resource bundle to get messages from.private static java.util.Map<java.lang.String,java.util.ResourceBundle>BUNDLE_CACHEA cache that maps bundle names to ResourceBundles.private intcolumnNoThe column number.private java.lang.StringcustomMessageA custom message overriding the default message from the bundle.private static SeverityLevelDEFAULT_SEVERITYThe default severity level if one is not specified.private java.lang.StringkeyKey for the message format.private intlineNoThe line number.private java.lang.StringmoduleIdThe id of the module generating the message.private static longserialVersionUIDprivate SeverityLevelseverityLevelThe severity level.private static java.util.LocalesLocaleThe locale to localise messages to.private java.lang.Class<?>sourceClassClass of the source for this LocalizedMessage.
-
Constructor Summary
Constructors Constructor Description LocalizedMessage(int lineNo, int columnNo, java.lang.String bundle, java.lang.String key, java.lang.Object[] args, SeverityLevel severityLevel, java.lang.String moduleId, java.lang.Class<?> sourceClass, java.lang.String customMessage)Creates a newLocalizedMessageinstance.LocalizedMessage(int lineNo, int columnNo, java.lang.String bundle, java.lang.String key, java.lang.Object[] args, java.lang.String moduleId, java.lang.Class<?> sourceClass, java.lang.String customMessage)Creates a newLocalizedMessageinstance.LocalizedMessage(int lineNo, java.lang.String bundle, java.lang.String key, java.lang.Object[] args, SeverityLevel severityLevel, java.lang.String moduleId, java.lang.Class<?> sourceClass, java.lang.String customMessage)Creates a newLocalizedMessageinstance.LocalizedMessage(int lineNo, java.lang.String bundle, java.lang.String key, java.lang.Object[] args, java.lang.String moduleId, java.lang.Class<?> sourceClass, java.lang.String customMessage)Creates a newLocalizedMessageinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidclearCache()Clears the cache.intcompareTo(LocalizedMessage other)booleanequals(java.lang.Object object)private java.util.ResourceBundlegetBundle(java.lang.String bundleName)Find a ResourceBundle for a given bundle name.intgetColumnNo()Gets the column number.private java.lang.StringgetCustomMessage()Returns the formatted custom message if one is configured.java.lang.StringgetKey()Returns the message key to locate the translation, can also be used in IDE plugins to map error messages to corrective actions.intgetLineNo()Gets the line number.java.lang.StringgetMessage()Gets the translated message.java.lang.StringgetModuleId()Returns id of module.SeverityLevelgetSeverityLevel()Gets the severity level.java.lang.StringgetSourceName()Gets the name of the source for this LocalizedMessage.inthashCode()static voidsetLocale(java.util.Locale locale)Sets a locale to use for localization.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
BUNDLE_CACHE
private static final java.util.Map<java.lang.String,java.util.ResourceBundle> BUNDLE_CACHE
A cache that maps bundle names to ResourceBundles. Avoids repetitive calls to ResourceBundle.getBundle().
-
DEFAULT_SEVERITY
private static final SeverityLevel DEFAULT_SEVERITY
The default severity level if one is not specified.
-
sLocale
private static java.util.Locale sLocale
The locale to localise messages to.
-
lineNo
private final int lineNo
The line number.
-
columnNo
private final int columnNo
The column number.
-
severityLevel
private final SeverityLevel severityLevel
The severity level.
-
moduleId
private final java.lang.String moduleId
The id of the module generating the message.
-
key
private final java.lang.String key
Key for the message format.
-
args
private final java.lang.Object[] args
Arguments for MessageFormat.
-
bundle
private final java.lang.String bundle
Name of the resource bundle to get messages from.
-
sourceClass
private final java.lang.Class<?> sourceClass
Class of the source for this LocalizedMessage.
-
customMessage
private final java.lang.String customMessage
A custom message overriding the default message from the bundle.
-
-
Constructor Detail
-
LocalizedMessage
public LocalizedMessage(int lineNo, int columnNo, java.lang.String bundle, java.lang.String key, java.lang.Object[] args, SeverityLevel severityLevel, java.lang.String moduleId, java.lang.Class<?> sourceClass, java.lang.String customMessage)Creates a newLocalizedMessageinstance.- Parameters:
lineNo- line number associated with the messagecolumnNo- column number associated with the messagebundle- resource bundle namekey- the key to locate the translationargs- arguments for the translationseverityLevel- severity level for the messagemoduleId- the id of the module the message is associated withsourceClass- the Class that is the source of the messagecustomMessage- optional custom message overriding the default
-
LocalizedMessage
public LocalizedMessage(int lineNo, int columnNo, java.lang.String bundle, java.lang.String key, java.lang.Object[] args, java.lang.String moduleId, java.lang.Class<?> sourceClass, java.lang.String customMessage)Creates a newLocalizedMessageinstance.- Parameters:
lineNo- line number associated with the messagecolumnNo- column number associated with the messagebundle- resource bundle namekey- the key to locate the translationargs- arguments for the translationmoduleId- the id of the module the message is associated withsourceClass- the Class that is the source of the messagecustomMessage- optional custom message overriding the default
-
LocalizedMessage
public LocalizedMessage(int lineNo, java.lang.String bundle, java.lang.String key, java.lang.Object[] args, SeverityLevel severityLevel, java.lang.String moduleId, java.lang.Class<?> sourceClass, java.lang.String customMessage)Creates a newLocalizedMessageinstance.- Parameters:
lineNo- line number associated with the messagebundle- resource bundle namekey- the key to locate the translationargs- arguments for the translationseverityLevel- severity level for the messagemoduleId- the id of the module the message is associated withsourceClass- the source class for the messagecustomMessage- optional custom message overriding the default
-
LocalizedMessage
public LocalizedMessage(int lineNo, java.lang.String bundle, java.lang.String key, java.lang.Object[] args, java.lang.String moduleId, java.lang.Class<?> sourceClass, java.lang.String customMessage)Creates a newLocalizedMessageinstance. The column number defaults to 0.- Parameters:
lineNo- line number associated with the messagebundle- name of a resource bundle that contains error messageskey- the key to locate the translationargs- arguments for the translationmoduleId- the id of the module the message is associated withsourceClass- the name of the source for the messagecustomMessage- optional custom message overriding the default
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
clearCache
public static void clearCache()
Clears the cache.
-
getMessage
public java.lang.String getMessage()
Gets the translated message.- Returns:
- the translated message
-
getCustomMessage
private java.lang.String getCustomMessage()
Returns the formatted custom message if one is configured.- Returns:
- the formatted custom message or
nullif there is no custom message
-
getBundle
private java.util.ResourceBundle getBundle(java.lang.String bundleName)
Find a ResourceBundle for a given bundle name. Uses the classloader of the class emitting this message, to be sure to get the correct bundle.- Parameters:
bundleName- the bundle name- Returns:
- a ResourceBundle
-
getLineNo
public int getLineNo()
Gets the line number.- Returns:
- the line number
-
getColumnNo
public int getColumnNo()
Gets the column number.- Returns:
- the column number
-
getSeverityLevel
public SeverityLevel getSeverityLevel()
Gets the severity level.- Returns:
- the severity level
-
getModuleId
public java.lang.String getModuleId()
Returns id of module.- Returns:
- the module identifier.
-
getKey
public java.lang.String getKey()
Returns the message key to locate the translation, can also be used in IDE plugins to map error messages to corrective actions.- Returns:
- the message key
-
getSourceName
public java.lang.String getSourceName()
Gets the name of the source for this LocalizedMessage.- Returns:
- the name of the source for this LocalizedMessage
-
setLocale
public static void setLocale(java.util.Locale locale)
Sets a locale to use for localization.- Parameters:
locale- the locale to use for localization
-
compareTo
public int compareTo(LocalizedMessage other)
- Specified by:
compareToin interfacejava.lang.Comparable<LocalizedMessage>
-
-