Class XpathQueryGenerator
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.xpath.XpathQueryGenerator
-
public class XpathQueryGenerator extends java.lang.Object
Generates xpath queries. Xpath queries are generated based on receivedDetailAst
element, line number, column number and token type. Token type parameter is optional.Example class
public class Main { public String sayHello(String name) { return "Hello, " + name; } }
Following expression returns list of queries. Each query is the string representing full path to the node inside Xpath tree, whose line number is 3 and column number is 4.
new XpathQueryGenerator(rootAst, 3, 4).generate();
Result list
- /CLASS_DEF[./IDENT[@text='Main']]/OBJBLOCK/METHOD_DEF[./IDENT[@text='sayHello']]
- /CLASS_DEF[./IDENT[@text='Main']]/OBJBLOCK/METHOD_DEF[./IDENT[@text='sayHello']] /MODIFIERS
- /CLASS_DEF[./IDENT[@text='Main']]/OBJBLOCK/METHOD_DEF[./IDENT[@text='sayHello']] /MODIFIERS/LITERAL_PUBLIC
-
-
Constructor Summary
Constructors Constructor Description XpathQueryGenerator(DetailAST rootAst, int lineNumber, int columnNumber, int tokenType, FileText fileText, int tabWidth)
Creates a newXpathQueryGenerator
instance.XpathQueryGenerator(DetailAST rootAst, int lineNumber, int columnNumber, FileText fileText, int tabWidth)
Creates a newXpathQueryGenerator
instance.XpathQueryGenerator(TreeWalkerAuditEvent event, int tabWidth)
Creates a newXpathQueryGenerator
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<java.lang.String>
generate()
Returns list of xpath queries of nodes, matching line number, column number and token type.static java.lang.String
generateXpathQuery(DetailAST ast)
Returns full xpath query for given ast element.
-
-
-
Constructor Detail
-
XpathQueryGenerator
public XpathQueryGenerator(TreeWalkerAuditEvent event, int tabWidth)
Creates a newXpathQueryGenerator
instance.- Parameters:
event
-TreeWalkerAuditEvent
objecttabWidth
- distance between tab stop position
-
XpathQueryGenerator
public XpathQueryGenerator(DetailAST rootAst, int lineNumber, int columnNumber, FileText fileText, int tabWidth)
Creates a newXpathQueryGenerator
instance.- Parameters:
rootAst
- root astlineNumber
- line number of the element for which the query should be generatedcolumnNumber
- column number of the element for which the query should be generatedfileText
- theFileText
objecttabWidth
- distance between tab stop position
-
XpathQueryGenerator
public XpathQueryGenerator(DetailAST rootAst, int lineNumber, int columnNumber, int tokenType, FileText fileText, int tabWidth)
Creates a newXpathQueryGenerator
instance.- Parameters:
rootAst
- root astlineNumber
- line number of the element for which the query should be generatedcolumnNumber
- column number of the element for which the query should be generatedtokenType
- token type of the element for which the query should be generatedfileText
- theFileText
objecttabWidth
- distance between tab stop position
-
-
Method Detail
-
generate
public java.util.List<java.lang.String> generate()
Returns list of xpath queries of nodes, matching line number, column number and token type. This approach uses DetailAST traversal. DetailAST means detail abstract syntax tree.- Returns:
- list of xpath queries of nodes, matching line number, column number and token type
-
generateXpathQuery
public static java.lang.String generateXpathQuery(DetailAST ast)
Returns full xpath query for given ast element.- Parameters:
ast
-DetailAST
ast element- Returns:
- full xpath query for given ast element
-
-