Package net.sourceforge.pmd
Class RuleContext
- java.lang.Object
-
- net.sourceforge.pmd.RuleContext
-
public final class RuleContext extends Object
The API for rules to report violations or errors during analysis. This forwards events to aFileAnalysisListener. It implements violation suppression by filtering some violations out, according to theViolationSuppressors for the language. A RuleContext contains a Rule instance and violation reporting methods implicitly report only for that rule. Contrary to PMD 6, RuleContext is not unique throughout the analysis, a separate one is used per file and rule.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddViolation(Node location)Record a new violation of the contextual rule, at the given node.voidaddViolation(Node location, Object... formatArgs)Record a new violation of the contextual rule, at the given node.voidaddViolationNoSuppress(RuleViolation rv)Force the recording of a violation, ignoring the violation suppression mechanism (ViolationSuppressor).voidaddViolationWithMessage(Node location, String message)Record a new violation of the contextual rule, at the given node.voidaddViolationWithMessage(Node location, String message, Object... formatArgs)Record a new violation of the contextual rule, at the given node.voidaddViolationWithPosition(Node node, int beginLine, int endLine, String message, Object... formatArgs)Record a new violation of the contextual rule, at the given node.static RuleContextcreate(FileAnalysisListener listener, Rule rule)Create a new RuleContext.RulegetRule()Deprecated.Used inAbstractRule.asCtx(Object), when that is gone, will be removed.
-
-
-
Method Detail
-
getRule
@Deprecated @InternalApi public Rule getRule()
Deprecated.Used inAbstractRule.asCtx(Object), when that is gone, will be removed.
-
addViolation
public void addViolation(Node location)
Record a new violation of the contextual rule, at the given node.- Parameters:
location- Location of the violation
-
addViolation
public void addViolation(Node location, Object... formatArgs)
Record a new violation of the contextual rule, at the given node. The default violation message (Rule.getMessage()) is formatted using the given format arguments.- Parameters:
location- Location of the violationformatArgs- Format arguments for the message- See Also:
MessageFormat
-
addViolationWithMessage
public void addViolationWithMessage(Node location, String message)
Record a new violation of the contextual rule, at the given node. The given violation message (Rule.getMessage()) is treated as a format string for aMessageFormatand should hence use appropriate escapes. No formatting arguments are provided.- Parameters:
location- Location of the violationmessage- Violation message
-
addViolationWithMessage
public void addViolationWithMessage(Node location, String message, Object... formatArgs)
Record a new violation of the contextual rule, at the given node. The given violation message (Rule.getMessage()) is treated as a format string for aMessageFormatand should hence use appropriate escapes. The given formatting arguments are used.- Parameters:
location- Location of the violationmessage- Violation messageformatArgs- Format arguments for the message
-
addViolationWithPosition
public void addViolationWithPosition(Node node, int beginLine, int endLine, String message, Object... formatArgs)
Record a new violation of the contextual rule, at the given node. The position is refined using the given begin and end line numbers. The given violation message (Rule.getMessage()) is treated as a format string for aMessageFormatand should hence use appropriate escapes. The given formatting arguments are used.- Parameters:
node- Location of the violationmessage- Violation messageformatArgs- Format arguments for the message
-
addViolationNoSuppress
@InternalApi public void addViolationNoSuppress(RuleViolation rv)
Force the recording of a violation, ignoring the violation suppression mechanism (ViolationSuppressor).- Parameters:
rv- A violation
-
create
@InternalApi public static RuleContext create(FileAnalysisListener listener, Rule rule)
Create a new RuleContext. The listener must be closed by its creator.
-
-