public final class XpathUtil extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static java.util.regex.Pattern |
CARRIAGE_RETURN_TO_TAG
This regexp is used to convert carriage return to carriage-return tag.
|
private static java.lang.String |
DELIMITER
Delimiter to separate xpath results.
|
private static java.util.regex.Pattern |
NEWLINE_TO_TAG
This regexp is used to convert new line to newline tag.
|
private static java.util.Set<java.lang.Integer> |
TOKEN_TYPES_WITH_TEXT_ATTRIBUTE
List of token types which support text attribute.
|
| Modifier | Constructor and Description |
|---|---|
private |
XpathUtil()
Stop instances being created.
|
| Modifier and Type | Method and Description |
|---|---|
static java.util.List<AbstractNode> |
createChildren(AbstractNode root,
AbstractNode parent,
DetailAST firstChild)
Iterates siblings of the given node and creates new Xpath-nodes.
|
static java.lang.String |
getTextAttributeValue(DetailAST ast)
Returns content of the text attribute of the ast element.
|
static java.lang.String |
printXpathBranch(java.lang.String xpath,
java.io.File file)
Returns xpath query results on file as string.
|
static boolean |
supportsTextAttribute(DetailAST ast)
Checks, if specified node can have
@text attribute. |
private static final java.util.Set<java.lang.Integer> TOKEN_TYPES_WITH_TEXT_ATTRIBUTE
detailAst.getText().equals(TokenUtil.getTokenName(detailAst.getType()))
For example:
//MODIFIERS[@text='MODIFIERS']
//OBJBLOCK[@text='OBJBLOCK']
These tokens do not match required criteria because their texts do not carry any additional
information, they do not affect the xpath requests and do not help to get more accurate
results. The texts of these nodes are useless. No matter what code you analyze, these
texts are always the same.
In addition, they make xpath queries more complex, less readable and verbose.
2. Tokens for which the texts differ from token names, but texts are always constant.
For example:
//LITERAL_VOID[@text='void']
//RCURLY[@text='}']
These tokens are not used for the same reasons as were described in the previous part.
3. Tokens for which texts are not constant. The texts of these nodes are closely related
to a concrete class, method, variable and so on.
For example:
String greeting = "HelloWorld";
//STRING_LITERAL[@text='HelloWorld']
int year = 2017;
//NUM_INT[@text=2017]
int age = 23;
//NUM_INT[@text=23]
As you can see same NUM_INT token type can have different texts, depending on
context.
public class MyClass {}
//IDENT[@text='MyClass']
Only these tokens support text attribute because they make our xpath queries more accurate.
These token types are listed below.private static final java.util.regex.Pattern NEWLINE_TO_TAG
private static final java.util.regex.Pattern CARRIAGE_RETURN_TO_TAG
private static final java.lang.String DELIMITER
private XpathUtil()
public static java.util.List<AbstractNode> createChildren(AbstractNode root, AbstractNode parent, DetailAST firstChild)
root - the root nodeparent - the parent nodefirstChild - the first DetailASTpublic static boolean supportsTextAttribute(DetailAST ast)
@text attribute.ast - DetailAst element@text attribute, false otherwisepublic static java.lang.String getTextAttributeValue(DetailAST ast)
ast - DetailAst elementpublic static java.lang.String printXpathBranch(java.lang.String xpath, java.io.File file) throws CheckstyleException, java.io.IOException
xpath - query to evaluatefile - file to run onCheckstyleException - if some parsing error happensjava.io.IOException - if an error occursCopyright © 2001-2022. All Rights Reserved.