Class XpathQueryGenerator


  • public class XpathQueryGenerator
    extends java.lang.Object
    Generates xpath queries. Xpath queries are generated based on received DetailAst 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
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XpathQueryGenerator

        public XpathQueryGenerator​(TreeWalkerAuditEvent event,
                                   int tabWidth)
        Creates a new XpathQueryGenerator instance.
        Parameters:
        event - TreeWalkerAuditEvent object
        tabWidth - distance between tab stop position
      • XpathQueryGenerator

        public XpathQueryGenerator​(DetailAST rootAst,
                                   int lineNumber,
                                   int columnNumber,
                                   FileText fileText,
                                   int tabWidth)
        Creates a new XpathQueryGenerator instance.
        Parameters:
        rootAst - root ast
        lineNumber - line number of the element for which the query should be generated
        columnNumber - column number of the element for which the query should be generated
        fileText - the FileText object
        tabWidth - distance between tab stop position
      • XpathQueryGenerator

        public XpathQueryGenerator​(DetailAST rootAst,
                                   int lineNumber,
                                   int columnNumber,
                                   int tokenType,
                                   FileText fileText,
                                   int tabWidth)
        Creates a new XpathQueryGenerator instance.
        Parameters:
        rootAst - root ast
        lineNumber - line number of the element for which the query should be generated
        columnNumber - column number of the element for which the query should be generated
        tokenType - token type of the element for which the query should be generated
        fileText - the FileText object
        tabWidth - 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