Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit cd00365

Browse files
committed
feat: add static convenience method for TSQuery creation
1 parent efa9c1d commit cd00365

File tree

1 file changed

+16
-0
lines changed
  • android-tree-sitter/src/main/java/com/itsaky/androidide/treesitter

1 file changed

+16
-0
lines changed

android-tree-sitter/src/main/java/com/itsaky/androidide/treesitter/TSQuery.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.itsaky.androidide.treesitter;
1919

20+
import android.text.TextUtils;
2021
import java.util.Objects;
2122

2223
public class TSQuery implements AutoCloseable {
@@ -157,6 +158,21 @@ private void validatePatternIndex(int pattern) {
157158
}
158159
}
159160

161+
/**
162+
* Creates a new {@link TSQuery} with the given {@link TSLanguage} and query source. If the
163+
* language or the query source is invalid, {@link TSQuery#EMPTY} is returned.
164+
*
165+
* @param language The {@link TSLanguage} for the query.
166+
* @param query The query source.
167+
* @return The {@link TSQuery} object.
168+
*/
169+
public static TSQuery create(TSLanguage language, String query) {
170+
if (language == null || query == null || TextUtils.getTrimmedLength(query) == 0) {
171+
return EMPTY;
172+
}
173+
return new TSQuery(language, query);
174+
}
175+
160176
/**
161177
* An empty query. Instances of this class are invalid queries and does not have any patterns,
162178
* capture names, etc. The <code>get*Count()</code> methods always return <code>0</code>, the

0 commit comments

Comments
 (0)