Class Query

  • All Implemented Interfaces:
    AutoCloseable

    public class Query
    extends Object
    A query consists of one or more patterns, where each pattern is a symbolic expression (S-expression) that matches a certain set of nodes in an abstract syntax tree. Each 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. Query instances are immutable and can be safely shared among threads.
    Since:
    1.0.0
    Author:
    Ozren Dabić
    See Also:
    Query Syntax
    • Method Detail

      • getFor

        public static Query getFor​(@NotNull
                                   @NotNull Language language,
                                   @NotNull
                                   @NotNull String... patterns)
        Static factory for obtaining new query instances.
        Parameters:
        language - The language for querying
        patterns - The query patterns
        Returns:
        A new query instance
        Since:
        1.7.0
      • builder

        public static Query.Builder builder()
        Obtain a new Builder for constructing a query instance.
        Returns:
        a new query builder
        Since:
        1.7.0
      • toBuilder

        public Query.Builder toBuilder()
        Obtain a new Builder initialized with the current query settings.
        Returns:
        a new query builder
        Since:
        1.8.0
      • hasCaptures

        public boolean hasCaptures()
        Check if this query has captures.
        Returns:
        true if the query has captures, false otherwise
      • getPattern

        public String getPattern()
        Returns a concatenated, possibly non-rooted symbolic expression consisting of the individual query patterns.
        Returns:
        the full query s-expression
      • isNull

        public final boolean isNull()
        Checks whether the memory address associated with this external resource is nullptr.
        Returns:
        true if the memory address is 0, otherwise false
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • close

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