Package ch.usi.si.seart.treesitter
Class Query
- java.lang.Object
-
- ch.usi.si.seart.treesitter.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 particularLanguage, 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classQuery.BuilderFacilitates the construction ofQueryinstances.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Query.Builderbuilder()Obtain a newBuilderfor constructing a query instance.voidclose()Delete the external resource, freeing all the memory that it used.booleanequals(Object obj)static QuerygetFor(@NotNull Language language, @NotNull String... patterns)Static factory for obtaining new query instances.StringgetPattern()Returns a concatenated, possibly non-rooted symbolic expression consisting of the individual query patterns.booleanhasCaptures()Check if this query has captures.inthashCode()booleanisNull()Checks whether the memory address associated with this external resource isnullptr.Query.BuildertoBuilder()Obtain a newBuilderinitialized with the current query settings.StringtoString()
-
-
-
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 queryingpatterns- The query patterns- Returns:
- A new query instance
- Since:
- 1.7.0
-
builder
public static Query.Builder builder()
Obtain a newBuilderfor constructing a query instance.- Returns:
- a new query builder
- Since:
- 1.7.0
-
toBuilder
public Query.Builder toBuilder()
Obtain a newBuilderinitialized 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:
trueif the query has captures,falseotherwise
-
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 isnullptr.- Returns:
trueif the memory address is 0, otherwisefalse
-
close
public void close()
Delete the external resource, freeing all the memory that it used.- Specified by:
closein interfaceAutoCloseable
-
-