Class Query

  • All Implemented Interfaces:
    AutoCloseable

    public class Query
    extends Object
    A query consists of one or more patterns, where each pattern is an S-expression that matches a certain set of nodes in a syntax tree. The query is associated with a particular language, and can only be run on syntax nodes parsed with that language. The expression to match a given node consists of a pair of parentheses containing two things: the node's type, and optionally, a series of other S-expressions that match the node's children. For example, this pattern would match any binary_expression node whose children are both number_literal nodes:
         (binary_expression (number_literal) (number_literal))
     
    Children can also be omitted. For example, this would match any binary_expression where at least one of child is a string_literal node:
         (binary_expression (string_literal))
     
    The underlying query value is immutable and can be safely shared between threads.
    Since:
    1.0.0
    Author:
    Ozren Dabić
    • Constructor Detail

      • Query

        public Query​(@NotNull
                     @NotNull Language language,
                     @NotNull
                     @NotNull String pattern)
    • Method Detail

      • close

        public void close()
        Delete the query, freeing all the memory that it used.
        Specified by:
        close in interface AutoCloseable
      • countStrings

        public int countStrings()
        Returns:
        The number of string literals in this query
      • countCaptures

        public int countCaptures()
        Returns:
        The number of captures in this query
      • countPatterns

        public int countPatterns()
        Returns:
        The number of patterns in this query
      • getCaptureName

        public String getCaptureName​(@NotNull
                                     @NotNull QueryCapture capture)
        Parameters:
        capture - The query capture
        Returns:
        The name of the provided query captures
      • hasCaptures

        public boolean hasCaptures()
        Returns:
        true if the query has captures, false otherwise
      • isNull

        public final boolean isNull()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object