Skip to content

Commit f7fc596

Browse files
feat(node): implement missing methods
- getFirstChildForByte - getFirstNamedChildForByte
1 parent 9da6529 commit f7fc596

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/main/java/io/github/treesitter/jtreesitter/Node.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,24 @@ public Optional<Node> getNamedChild(@Unsigned int index) throws IndexOutOfBounds
234234
return optional(ts_node_named_child(arena, self, index));
235235
}
236236

237+
/**
238+
* Get the node's first child that contains or starts after the given byte offset.
239+
*
240+
* @since 0.25.0
241+
*/
242+
public Optional<Node> getFirstChildForByte(@Unsigned int byte_offset) {
243+
return optional(ts_node_first_child_for_byte(arena, self, byte_offset));
244+
}
245+
246+
/**
247+
* Get the node's first <em>named</em> child that contains or starts after the given byte offset.
248+
*
249+
* @since 0.25.0
250+
*/
251+
public Optional<Node> getFirstNamedChildForByte(@Unsigned int byte_offset) {
252+
return optional(ts_node_first_named_child_for_byte(arena, self, byte_offset));
253+
}
254+
237255
/**
238256
* Get the node's first child with the given field ID, if any.
239257
*

src/test/java/io/github/treesitter/jtreesitter/NodeTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,18 @@ void getNamedChild() {
171171
assertEquals("class_declaration", child.getGrammarType());
172172
}
173173

174+
@Test
175+
void getFirstChildForByte() {
176+
var child = node.getFirstChildForByte(15).orElseThrow();
177+
assertEquals("line_comment", child.getGrammarType());
178+
}
179+
180+
@Test
181+
void getFirstNamedChildForByte() {
182+
var child = node.getFirstNamedChildForByte(15).orElseThrow();
183+
assertEquals("line_comment", child.getGrammarType());
184+
}
185+
174186
@Test
175187
void getChildByFieldId() {
176188
var child = node.getChild(0).orElseThrow();

0 commit comments

Comments
 (0)