Skip to content

Commit ae22c77

Browse files
feat(language): implement isSupertype
1 parent 25aff46 commit ae22c77

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

scripts/jextract.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ $env:package = 'io.github.treesitter.jtreesitter.internal'
174174
--include-constant TSSymbolTypeAnonymous `
175175
--include-constant TSSymbolTypeAuxiliary `
176176
--include-constant TSSymbolTypeRegular `
177+
--include-constant TSSymbolTypeSupertype `
177178
--header-class-name TreeSitter `
178179
--output "$($args[1])/generated-sources/jextract" `
179180
-t $env:package `

scripts/jextract.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ exec jextract \
175175
--include-constant TSSymbolTypeAnonymous \
176176
--include-constant TSSymbolTypeAuxiliary \
177177
--include-constant TSSymbolTypeRegular \
178+
--include-constant TSSymbolTypeSupertype \
178179
--header-class-name TreeSitter \
179180
--output "$2"/generated-sources/jextract \
180181
-t "$package" \

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ public boolean isVisible(@Unsigned short symbol) {
133133
return ts_language_symbol_type(self, symbol) <= TSSymbolTypeAnonymous();
134134
}
135135

136+
/** Check if the node for the given numerical ID is a supertype. */
137+
public boolean isSupertype(@Unsigned short symbol) {
138+
return ts_language_symbol_type(self, symbol) == TSSymbolTypeSupertype();
139+
}
140+
136141
/** Get the field name for the given numerical id. */
137142
public @Nullable String getFieldNameForId(@Unsigned short id) {
138143
var name = ts_language_field_name_for_id(self, id);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public List<Node> getChildrenByFieldName(String name) {
325325
public @Nullable String getFieldNameForNamedChild(@Unsigned int index) throws IndexOutOfBoundsException {
326326
if (index >= getChildCount()) {
327327
throw new IndexOutOfBoundsException(
328-
"Child index %s is out of bounds".formatted(Integer.toUnsignedString(index)));
328+
"Child index %s is out of bounds".formatted(Integer.toUnsignedString(index)));
329329
}
330330
var segment = ts_node_field_name_for_named_child(self, index);
331331
return segment.equals(MemorySegment.NULL) ? null : segment.getString(0);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ void isVisible() {
5656
assertTrue(language.isVisible((short) 1));
5757
}
5858

59+
@Test
60+
void isSupertype() {
61+
assertFalse(language.isSupertype((short) 1));
62+
}
63+
5964
@Test
6065
void getFieldNameForId() {
6166
assertNotNull(language.getFieldNameForId((short) 20));

0 commit comments

Comments
 (0)