Class Violation
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.Violation
-
- All Implemented Interfaces:
Serializable
,Comparable<Violation>
public final class Violation extends Object implements Comparable<Violation>, Serializable
Represents a violation 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 class
Violation.Utf8Control
Custom ResourceBundle.Control implementation which allows explicitly read the properties files as UTF-8.
-
Field Summary
Fields Modifier and Type Field Description private Object[]
args
Arguments for MessageFormat.private String
bundle
Name of the resource bundle to get violations from.private static Map<String,ResourceBundle>
BUNDLE_CACHE
A cache that maps bundle names to ResourceBundles.private int
columnCharIndex
The column char index.private int
columnNo
The column number.private String
customMessage
A custom violation overriding the default violation from the bundle.private static SeverityLevel
DEFAULT_SEVERITY
The default severity level if one is not specified.private String
key
Key for the violation format.private int
lineNo
The line number.private String
moduleId
The id of the module generating the violation.private static long
serialVersionUID
A unique serial version identifier.private SeverityLevel
severityLevel
The severity level.private static Locale
sLocale
The locale to localise violations to.private Class<?>
sourceClass
Class of the source for this Violation.private int
tokenType
The token type constant.
-
Constructor Summary
Constructors Constructor Description Violation(int lineNo, int columnNo, int columnCharIndex, int tokenType, String bundle, String key, Object[] args, SeverityLevel severityLevel, String moduleId, Class<?> sourceClass, String customMessage)
Creates a newViolation
instance.Violation(int lineNo, int columnNo, int tokenType, String bundle, String key, Object[] args, SeverityLevel severityLevel, String moduleId, Class<?> sourceClass, String customMessage)
Creates a newViolation
instance.Violation(int lineNo, int columnNo, String bundle, String key, Object[] args, SeverityLevel severityLevel, String moduleId, Class<?> sourceClass, String customMessage)
Creates a newViolation
instance.Violation(int lineNo, int columnNo, String bundle, String key, Object[] args, String moduleId, Class<?> sourceClass, String customMessage)
Creates a newViolation
instance.Violation(int lineNo, String bundle, String key, Object[] args, SeverityLevel severityLevel, String moduleId, Class<?> sourceClass, String customMessage)
Creates a newViolation
instance.Violation(int lineNo, String bundle, String key, Object[] args, String moduleId, Class<?> sourceClass, String customMessage)
Creates a newViolation
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
clearCache()
Clears the cache.int
compareTo(Violation other)
boolean
equals(Object object)
Indicates whether some other object is "equal to" this one.private ResourceBundle
getBundle(String bundleName)
Find a ResourceBundle for a given bundle name.int
getColumnCharIndex()
Gets the column char index.int
getColumnNo()
Gets the column number.private String
getCustomViolation()
Returns the formatted custom violation if one is configured.String
getKey()
Returns the violation key to locate the translation, can also be used in IDE plugins to map audit event violations to corrective actions.int
getLineNo()
Gets the line number.String
getModuleId()
Returns id of module.SeverityLevel
getSeverityLevel()
Gets the severity level.String
getSourceName()
Gets the name of the source for this Violation.int
getTokenType()
Gets the token type.String
getViolation()
Gets the translated violation.int
hashCode()
static void
setLocale(Locale locale)
Sets a locale to use for localization.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
A unique serial version identifier.- See Also:
- Constant Field Values
-
BUNDLE_CACHE
private static final Map<String,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.
-
lineNo
private final int lineNo
The line number.
-
columnNo
private final int columnNo
The column number.
-
columnCharIndex
private final int columnCharIndex
The column char index.
-
tokenType
private final int tokenType
The token type constant. SeeTokenTypes
.
-
severityLevel
private final SeverityLevel severityLevel
The severity level.
-
sourceClass
private final Class<?> sourceClass
Class of the source for this Violation.
-
customMessage
private final String customMessage
A custom violation overriding the default violation from the bundle.
-
-
Constructor Detail
-
Violation
public Violation(int lineNo, int columnNo, int columnCharIndex, int tokenType, String bundle, String key, Object[] args, SeverityLevel severityLevel, String moduleId, Class<?> sourceClass, String customMessage)
Creates a newViolation
instance.- Parameters:
lineNo
- line number associated with the violationcolumnNo
- column number associated with the violationcolumnCharIndex
- column char index associated with the violationtokenType
- token type of the event associated with violation. SeeTokenTypes
bundle
- resource bundle namekey
- the key to locate the translationargs
- arguments for the translationseverityLevel
- severity level for the violationmoduleId
- the id of the module the violation is associated withsourceClass
- the Class that is the source of the violationcustomMessage
- optional custom violation overriding the default
-
Violation
public Violation(int lineNo, int columnNo, int tokenType, String bundle, String key, Object[] args, SeverityLevel severityLevel, String moduleId, Class<?> sourceClass, String customMessage)
Creates a newViolation
instance.- Parameters:
lineNo
- line number associated with the violationcolumnNo
- column number associated with the violationtokenType
- token type of the event associated with violation. SeeTokenTypes
bundle
- resource bundle namekey
- the key to locate the translationargs
- arguments for the translationseverityLevel
- severity level for the violationmoduleId
- the id of the module the violation is associated withsourceClass
- the Class that is the source of the violationcustomMessage
- optional custom violation overriding the default
-
Violation
public Violation(int lineNo, int columnNo, String bundle, String key, Object[] args, SeverityLevel severityLevel, String moduleId, Class<?> sourceClass, String customMessage)
Creates a newViolation
instance.- Parameters:
lineNo
- line number associated with the violationcolumnNo
- column number associated with the violationbundle
- resource bundle namekey
- the key to locate the translationargs
- arguments for the translationseverityLevel
- severity level for the violationmoduleId
- the id of the module the violation is associated withsourceClass
- the Class that is the source of the violationcustomMessage
- optional custom violation overriding the default
-
Violation
public Violation(int lineNo, int columnNo, String bundle, String key, Object[] args, String moduleId, Class<?> sourceClass, String customMessage)
Creates a newViolation
instance.- Parameters:
lineNo
- line number associated with the violationcolumnNo
- column number associated with the violationbundle
- resource bundle namekey
- the key to locate the translationargs
- arguments for the translationmoduleId
- the id of the module the violation is associated withsourceClass
- the Class that is the source of the violationcustomMessage
- optional custom violation overriding the default
-
Violation
public Violation(int lineNo, String bundle, String key, Object[] args, SeverityLevel severityLevel, String moduleId, Class<?> sourceClass, String customMessage)
Creates a newViolation
instance.- Parameters:
lineNo
- line number associated with the violationbundle
- resource bundle namekey
- the key to locate the translationargs
- arguments for the translationseverityLevel
- severity level for the violationmoduleId
- the id of the module the violation is associated withsourceClass
- the source class for the violationcustomMessage
- optional custom violation overriding the default
-
Violation
public Violation(int lineNo, String bundle, String key, Object[] args, String moduleId, Class<?> sourceClass, String customMessage)
Creates a newViolation
instance. The column number defaults to 0.- Parameters:
lineNo
- line number associated with the violationbundle
- name of a resource bundle that contains audit event violationskey
- the key to locate the translationargs
- arguments for the translationmoduleId
- the id of the module the violation is associated withsourceClass
- the name of the source for the violationcustomMessage
- optional custom violation overriding the default
-
-
Method Detail
-
getLineNo
public int getLineNo()
Gets the line number.- Returns:
- the line number
-
getColumnNo
public int getColumnNo()
Gets the column number.- Returns:
- the column number
-
getColumnCharIndex
public int getColumnCharIndex()
Gets the column char index.- Returns:
- the column char index
-
getTokenType
public int getTokenType()
Gets the token type.- Returns:
- the token type
-
getSeverityLevel
public SeverityLevel getSeverityLevel()
Gets the severity level.- Returns:
- the severity level
-
getModuleId
public String getModuleId()
Returns id of module.- Returns:
- the module identifier.
-
getKey
public String getKey()
Returns the violation key to locate the translation, can also be used in IDE plugins to map audit event violations to corrective actions.- Returns:
- the violation key
-
getSourceName
public String getSourceName()
Gets the name of the source for this Violation.- Returns:
- the name of the source for this Violation
-
setLocale
public static void setLocale(Locale locale)
Sets a locale to use for localization.- Parameters:
locale
- the locale to use for localization
-
clearCache
public static void clearCache()
Clears the cache.
-
equals
public boolean equals(Object object)
Indicates whether some other object is "equal to" this one. Suppression on enumeration is needed so code stays consistent.
-
compareTo
public int compareTo(Violation other)
- Specified by:
compareTo
in interfaceComparable<Violation>
-
getViolation
public String getViolation()
Gets the translated violation.- Returns:
- the translated violation
-
getCustomViolation
private String getCustomViolation()
Returns the formatted custom violation if one is configured.- Returns:
- the formatted custom violation or
null
if there is no custom violation
-
getBundle
private ResourceBundle getBundle(String bundleName)
Find a ResourceBundle for a given bundle name. Uses the classloader of the class emitting this violation, to be sure to get the correct bundle.- Parameters:
bundleName
- the bundle name- Returns:
- a ResourceBundle
-
-