File tree Expand file tree Collapse file tree 4 files changed +11
-6
lines changed
main/java/io/github/treesitter/jtreesitter
test/java/io/github/treesitter/jtreesitter Expand file tree Collapse file tree 4 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ public CapturesIterator(
3838
3939 @ Override
4040 public boolean tryAdvance (Consumer <? super SimpleImmutableEntry <Integer , QueryMatch >> action ) {
41- var hasNoText = tree .getText () == null ;
41+ var hasNoText = ! tree .hasText () ;
4242 MemorySegment match = allocator .allocate (TSQueryMatch .layout ());
4343 MemorySegment index = allocator .allocate (C_INT );
4444 var captureNames = query .getCaptureNames ();
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public MatchesIterator(
3636
3737 @ Override
3838 public boolean tryAdvance (Consumer <? super QueryMatch > action ) {
39- var hasNoText = tree .getText () == null ;
39+ var hasNoText = ! tree .hasText () ;
4040 MemorySegment match = allocator .allocate (TSQueryMatch .layout ());
4141 var captureNames = query .getCaptureNames ();
4242 while (ts_query_cursor_next_match (cursor , match )) {
Original file line number Diff line number Diff line change @@ -44,6 +44,10 @@ MemorySegment segment() {
4444 return self ;
4545 }
4646
47+ boolean hasText () {
48+ return charset != null ;
49+ }
50+
4751 @ Nullable
4852 String getRegion (@ Unsigned int start , @ Unsigned int end ) {
4953 var length = Math .min (end , source .length ) - start ;
@@ -57,7 +61,7 @@ public Language getLanguage() {
5761
5862 /** Get the source code of the syntax tree, if available. */
5963 public @ Nullable String getText () {
60- return charset != null ? new String (source , charset ) : null ;
64+ return hasText () ? new String (source , charset ) : null ;
6165 }
6266
6367 /** Get the root node of the syntax tree. */
@@ -161,6 +165,6 @@ public void close() throws RuntimeException {
161165
162166 @ Override
163167 public String toString () {
164- return "Tree{language=%s, source=%s}" .formatted (language , source );
168+ return "Tree{language=%s, source=%s}" .formatted (language , getText () );
165169 }
166170}
Original file line number Diff line number Diff line change @@ -181,12 +181,13 @@ void getPatternAssertions() {
181181
182182 @ Test
183183 void queryWithTwoPredicates () {
184- var source = """
184+ var source =
185+ """
185186 ((identifier) @foo
186187 (#eq? @foo "foo")
187188 (#not-eq? @foo "bar"))
188189 """
189- .stripIndent ();
190+ .stripIndent ();
190191 assertQuery (source , query -> {
191192 assertEquals (1 , query .getPatternCount ());
192193 assertIterableEquals (List .of ("foo" ), query .getCaptureNames ());
You can’t perform that action at this time.
0 commit comments