Skip to content

Commit

Permalink
Add new private native method: Language#field
Browse files Browse the repository at this point in the history
As the name suggest, it allows us to retrieve the field name by ID.
It currently sees no use in the code, but I have plans to use it in
the constructor to eagerly fetch all the valid field names of a
language.
  • Loading branch information
dabico committed Feb 13, 2024
1 parent 84f70ad commit 05314e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/ch_usi_si_seart_treesitter_Language.cc
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,14 @@ JNIEXPORT jint JNICALL Java_ch_usi_si_seart_treesitter_Language_fields(
return (jint)ts_language_field_count(language);
}

JNIEXPORT jstring JNICALL Java_ch_usi_si_seart_treesitter_Language_field(
JNIEnv* env, jclass self, jlong languageId, jint fieldId) {
TSLanguage* language = (TSLanguage*)languageId;
TSFieldId field = (TSFieldId)fieldId;
const char* name = ts_language_field_name_for_id(language, field);
return env->NewStringUTF(name);
}

JNIEXPORT jint JNICALL Java_ch_usi_si_seart_treesitter_Language_states(
JNIEnv* env, jclass self, jlong id) {
TSLanguage* language = (TSLanguage*)id;
Expand Down
8 changes: 8 additions & 0 deletions lib/ch_usi_si_seart_treesitter_Language.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/main/java/ch/usi/si/seart/treesitter/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ public static void validate(@NotNull Language language) {
private static native int symbols(long id);
private static native Symbol symbol(long languageId, int symbolId);
private static native int fields(long id);
private static native String field(long languageId, int fieldId);
private static native int states(long id);

long id;
Expand Down

0 comments on commit 05314e2

Please sign in to comment.