Class AbstractViolationReporter
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- All Implemented Interfaces:
Configurable
,Contextualizable
- Direct Known Subclasses:
AbstractCheck
,AbstractFileSetCheck
public abstract class AbstractViolationReporter extends AbstractAutomaticBean
Serves as an abstract base class for all modules that report inspection findings. Such modules have a Severity level which is used for theviolations
that are created by the module.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
-
Field Summary
Fields Modifier and Type Field Description private String
id
The identifier of the reporter.private SeverityLevel
severityLevel
The severity level of any violations found.
-
Constructor Summary
Constructors Constructor Description AbstractViolationReporter()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
finishLocalSetup()
Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.protected Map<String,String>
getCustomMessages()
Returns an unmodifiable map instance containing the custom messages for this configuration.String
getId()
Returns the identifier of the reporter.protected String
getMessageBundle()
Returns the message bundle name resource bundle that contains the messages used by this module.private static String
getMessageBundle(String className)
For unit tests, especially with a class with no package name.String
getSeverity()
Get the severity level's name.SeverityLevel
getSeverityLevel()
Returns the severity level of the violations generated by this module.abstract void
log(int line, int col, String key, Object... args)
Log a message that has column information.abstract void
log(int line, String key, Object... args)
Log a message that has no column information.void
setId(String id)
Sets the identifier of the reporter.void
setSeverity(String severity)
Sets the severity level.-
Methods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
-
-
-
Field Detail
-
severityLevel
private SeverityLevel severityLevel
The severity level of any violations found.
-
-
Constructor Detail
-
AbstractViolationReporter
public AbstractViolationReporter()
-
-
Method Detail
-
getSeverityLevel
public final SeverityLevel getSeverityLevel()
Returns the severity level of the violations generated by this module.- Returns:
- the severity level
- See Also:
SeverityLevel
,Violation.getSeverityLevel()
-
setSeverity
public final void setSeverity(String severity)
Sets the severity level. The string should be one of the names defined in theSeverityLevel
class.- Parameters:
severity
- The new severity level- See Also:
SeverityLevel
-
getSeverity
public final String getSeverity()
Get the severity level's name.- Returns:
- the check's severity level name.
-
getId
public final String getId()
Returns the identifier of the reporter. Can be null.- Returns:
- the id
-
setId
public final void setId(String id)
Sets the identifier of the reporter. Can be null.- Parameters:
id
- the id
-
getCustomMessages
protected Map<String,String> getCustomMessages()
Returns an unmodifiable map instance containing the custom messages for this configuration.- Returns:
- unmodifiable map containing custom messages
-
getMessageBundle
protected String getMessageBundle()
Returns the message bundle name resource bundle that contains the messages used by this module.The default implementation expects the resource files to be named messages.properties, messages_de.properties, etc. The file must be placed in the same package as the module implementation.
Example: If you write com/foo/MyCoolCheck, create resource files com/foo/messages.properties, com/foo/messages_de.properties, etc.
- Returns:
- name of a resource bundle that contains the messages used by this module.
-
getMessageBundle
private static String getMessageBundle(String className)
For unit tests, especially with a class with no package name.- Parameters:
className
- class name of the module.- Returns:
- name of a resource bundle that contains the messages used by the module.
-
finishLocalSetup
protected void finishLocalSetup() throws CheckstyleException
Description copied from class:AbstractAutomaticBean
Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.The default implementation does nothing.
- Specified by:
finishLocalSetup
in classAbstractAutomaticBean
- Throws:
CheckstyleException
- if there is a configuration error.
-
log
public abstract void log(int line, String key, Object... args)
Log a message that has no column information.- Parameters:
line
- the line number where the audit event was foundkey
- the message that describes the audit eventargs
- the details of the message- See Also:
MessageFormat
-
log
public abstract void log(int line, int col, String key, Object... args)
Log a message that has column information.- Parameters:
line
- the line number where the audit event was foundcol
- the column number where the audit event was foundkey
- the message that describes the audit eventargs
- the details of the message- See Also:
MessageFormat
-
-