Class XpathFilterElement
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.filters.XpathFilterElement
-
- All Implemented Interfaces:
TreeWalkerFilter
public class XpathFilterElement extends Object implements TreeWalkerFilter
This filter element is immutable and processesTreeWalkerAuditEvent
objects based on the criteria of file, check, module id, xpathQuery.
-
-
Field Summary
Fields Modifier and Type Field Description private Pattern
checkRegexp
The regexp to match check names against.private Pattern
fileRegexp
The regexp to match file names against.private boolean
isEmptyConfig
Indicates if all properties are set to null.private Pattern
messageRegexp
The regexp to match message names against.private String
moduleId
Module id filter.private net.sf.saxon.sxpath.XPathExpression
xpathExpression
Xpath expression.private String
xpathQuery
Xpath query.
-
Constructor Summary
Constructors Constructor Description XpathFilterElement(String files, String checks, String message, String moduleId, String query)
Creates aXpathElement
instance.XpathFilterElement(Pattern files, Pattern checks, Pattern message, String moduleId, String query)
Creates aXpathElement
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept(TreeWalkerAuditEvent event)
Determines whether or not a filteredTreeWalkerAuditEvent
is accepted.boolean
equals(Object other)
private List<net.sf.saxon.om.Item>
getItems(TreeWalkerAuditEvent event)
Returns list of nodes matching xpath expression given event.private static String
getPatternSafely(Pattern pattern)
Util method to get pattern String value from Pattern object safely, return null if pattern object is null.int
hashCode()
private boolean
isFileNameAndModuleAndModuleNameMatching(TreeWalkerAuditEvent event)
Is matching by file name, module id and Check name.private boolean
isMessageNameMatching(TreeWalkerAuditEvent event)
Is matching by message.private boolean
isXpathQueryMatching(TreeWalkerAuditEvent event)
Is matching by xpath query.
-
-
-
Field Detail
-
fileRegexp
private final Pattern fileRegexp
The regexp to match file names against.
-
checkRegexp
private final Pattern checkRegexp
The regexp to match check names against.
-
messageRegexp
private final Pattern messageRegexp
The regexp to match message names against.
-
xpathExpression
private final net.sf.saxon.sxpath.XPathExpression xpathExpression
Xpath expression.
-
xpathQuery
private final String xpathQuery
Xpath query.
-
isEmptyConfig
private final boolean isEmptyConfig
Indicates if all properties are set to null.
-
-
Constructor Detail
-
XpathFilterElement
public XpathFilterElement(String files, String checks, String message, String moduleId, String query)
Creates aXpathElement
instance.- Parameters:
files
- regular expression for names of filtered fileschecks
- regular expression for filtered check classesmessage
- regular expression for messages.moduleId
- the module idquery
- the xpath query- Throws:
IllegalArgumentException
- if the xpath query is not expected.
-
XpathFilterElement
public XpathFilterElement(Pattern files, Pattern checks, Pattern message, String moduleId, String query)
Creates aXpathElement
instance.- Parameters:
files
- regular expression for names of filtered fileschecks
- regular expression for filtered check classesmessage
- regular expression for messages.moduleId
- the module idquery
- the xpath query- Throws:
IllegalArgumentException
- if the xpath query is not correct.
-
-
Method Detail
-
accept
public boolean accept(TreeWalkerAuditEvent event)
Description copied from interface:TreeWalkerFilter
Determines whether or not a filteredTreeWalkerAuditEvent
is accepted.- Specified by:
accept
in interfaceTreeWalkerFilter
- Parameters:
event
- the TreeWalkerAuditEvent to filter.- Returns:
- true if the event is accepted.
-
isFileNameAndModuleAndModuleNameMatching
private boolean isFileNameAndModuleAndModuleNameMatching(TreeWalkerAuditEvent event)
Is matching by file name, module id and Check name.- Parameters:
event
- event- Returns:
- true if it is matching
-
isMessageNameMatching
private boolean isMessageNameMatching(TreeWalkerAuditEvent event)
Is matching by message.- Parameters:
event
- event- Returns:
- true if it is matching or not set.
-
isXpathQueryMatching
private boolean isXpathQueryMatching(TreeWalkerAuditEvent event)
Is matching by xpath query.- Parameters:
event
- event- Returns:
- true if it is matching or not set.
-
getItems
private List<net.sf.saxon.om.Item> getItems(TreeWalkerAuditEvent event)
Returns list of nodes matching xpath expression given event.- Parameters:
event
-TreeWalkerAuditEvent
object- Returns:
- list of nodes matching xpath expression given event
- Throws:
IllegalStateException
- if the xpath query could not be evaluated.
-
getPatternSafely
private static String getPatternSafely(Pattern pattern)
Util method to get pattern String value from Pattern object safely, return null if pattern object is null.- Parameters:
pattern
- pattern object- Returns:
- value of pattern or null
-
-