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 pattern)
        Static factory for obtaining new Query instances.
        Parameters:
        language - The language for querying
        pattern - The query pattern
        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
      • countStrings

        @Deprecated(since="1.7.0",
                    forRemoval=true)
        public int countStrings()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Just get dedicated collection, and compute size()
      • countCaptures

        @Deprecated(since="1.7.0",
                    forRemoval=true)
        public int countCaptures()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Just get dedicated collection, and compute size()
      • countPatterns

        @Deprecated(since="1.7.0",
                    forRemoval=true)
        public int countPatterns()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Just get dedicated collection, and compute size()
      • getCaptureName

        @Deprecated(since="1.7.0",
                    forRemoval=true)
        public String getCaptureName​(@NotNull
                                     @NotNull Object ignored)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Should not be used anymore
        See Also:
        QueryMatch
      • hasCaptures

        public boolean hasCaptures()
        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()
      • 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