Package net.sourceforge.pmd.reporting
Class RuleContext
java.lang.Object
net.sourceforge.pmd.reporting.RuleContext
The API for rules to report violations or errors during analysis. This forwards events to a
FileAnalysisListener. 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
Modifier and TypeMethodDescriptionvoidaddViolation(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(Reportable reportable,AstInfo<?> astInfo,String message,Object... formatArgs) 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.voidaddViolationWithPosition(Node node,JavaccToken token,String message,Object... formatArgs) Record a new violation of the contextual rule, at the given token location.voidaddViolationWithPosition(Reportable reportable,AstInfo<?> astInfo,FileLocation location,String message,Object... formatArgs) Record a new violation of the contextual rule, at the given location (node or token).
Method Details
addViolation
Record a new violation of the contextual rule, at the given node.- Parameters:
location- Location of the violation
addViolation
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:
addViolationWithMessage
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
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
addViolationWithPosition
@Experimentalpublic void addViolationWithPosition(Node node,JavaccToken token,String message,Object... formatArgs) Record a new violation of the contextual rule, at the given token location. 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.- Experimental Status:
- Since 7.17.0. This will probably never be stabilized, will instead be replaced by a fluent API or something to report violations. Do not use this outside of the PMD codebase. See[core] Add fluent API to report violations #5039.
- Parameters:
node- Location of the violation (node or token) - only used to determine suppressiontoken- Report location of the violationmessage- Violation messageformatArgs- Format arguments for the message
addViolationWithPosition
@Experimentalpublic void addViolationWithPosition(Reportable reportable,AstInfo<?> astInfo,FileLocation location,String message,Object... formatArgs) Record a new violation of the contextual rule, at the given location (node or token). 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.- Experimental Status:
- Since 7.9.0. This will probably never be stabilized, will instead be replaced by a fluent API or something to report violations. Do not use this outside of the PMD codebase. See[core] Add fluent API to report violations #5039.
- Parameters:
reportable- Location of the violation (node or token) - only used to determine suppressionastInfo- Info about the root of the tree (Node.getAstInfo())location- Report location of the violationmessage- Violation messageformatArgs- Format arguments for the message
addViolationNoSuppress
@Experimentalpublic void addViolationNoSuppress(Reportable reportable,AstInfo<?> astInfo,String message,Object... formatArgs) - Experimental Status:
- Since 7.14.0. See[core] Add rule to report unnecessary suppression comments/annotations #5609