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

Commit 6ed0f18

Browse files
committed
Moved native methods for TSTree to TSTree.Native class
1 parent 63f85f0 commit 6ed0f18

File tree

6 files changed

+84
-87
lines changed

6 files changed

+84
-87
lines changed

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

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,52 @@ public class TSTree implements AutoCloseable {
88
this.pointer = pointer;
99
}
1010

11+
/** Close and delete this tree. */
1112
@Override
1213
public void close() {
13-
TreeSitter.treeDelete(pointer);
14+
Native.delete(pointer);
1415
}
1516

17+
/**
18+
* Get the root node of this tree.
19+
*
20+
* @return The root node.
21+
*/
1622
public TSNode getRootNode() {
17-
return TreeSitter.treeRootNode(pointer);
23+
return Native.rootNode(pointer);
1824
}
1925

26+
/**
27+
* Make a shallow copy of this tree. This is very fast.
28+
*
29+
* @return The copy of this tree.
30+
*/
2031
public TSTree copy() {
21-
return new TSTree(TreeSitter.treeCopy(pointer));
32+
return new TSTree(Native.copy(pointer));
2233
}
2334

35+
/**
36+
* Notify that this tree has been edited.
37+
*
38+
* @param edit The edit.
39+
*/
2440
public void edit(TSInputEdit edit) {
25-
TreeSitter.treeEdit(pointer, edit);
41+
Native.edit(pointer, edit);
2642
}
2743

28-
public long getPointer() {
44+
/**
45+
* Get the pointer of this tree.
46+
*
47+
* @return The pointer.
48+
*/
49+
long getPointer() {
2950
return pointer;
3051
}
52+
53+
private static class Native {
54+
public static native void edit(long tree, TSInputEdit inputEdit);
55+
public static native void delete(long tree);
56+
public static native long copy(long tree);
57+
public static native TSNode rootNode(long tree);
58+
}
3159
}

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

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,8 @@
22

33
public class TreeSitter {
44

5-
// -------------------------------------------
6-
// ---------- Section: TSParser --------------
7-
// -------------------------------------------
8-
9-
// -------------------------------------------
10-
// ---------- Section: TSTreeCursor ----------
11-
// -------------------------------------------
12-
135
// -------------------------------------------
146
// ---------- Section: TSTree ----------------
157
// -------------------------------------------
16-
/**
17-
* Notify that the tree has been edited.
18-
*
19-
* @param tree The pointer to the tree.
20-
* @param inputEdit The edit descriptor.
21-
*/
22-
public static native void treeEdit(long tree, TSInputEdit inputEdit);
23-
24-
/**
25-
* Delete the given tree.
26-
*
27-
* @param tree The pointer to the tree.
28-
*/
29-
public static native void treeDelete(long tree);
30-
31-
/**
32-
* Creates shallow of the given tree. This is very fast. Suitable for use in multiple threads.
33-
*
34-
* @param tree The pointer to the tree to copy.
35-
* @return The pointer to the copied tree.
36-
*/
37-
public static native long treeCopy(long tree);
38-
39-
/**
40-
* Get the root node of the given tree.
41-
*
42-
* @param tree The pointer to the tree.
43-
* @return The root node.
44-
*/
45-
public static native TSNode treeRootNode(long tree);
46-
47-
/**
48-
* @param language
49-
* @param source
50-
* @return
51-
*/
528
public static native long tsQueryNew(long language, String source);
539
}

genh.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -eu
44

55
script_dir=$(realpath $(dirname $0))
66

7-
for header in TreeSitter TSLanguages.Native TSLanguage.Native TSParser.Native TSTreeCursor.Native TSNode
7+
for header in TreeSitter TSLanguages.Native TSLanguage.Native TSParser.Native TSTreeCursor.Native TSTree.Native TSNode
88
do
99
javah -d $script_dir/lib -classpath ${script_dir}/android-tree-sitter/src/main/java com.itsaky.androidide.treesitter.${header}
1010
done

lib/com_itsaky_androidide_treesitter_TSTree_Native.h

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/com_itsaky_androidide_treesitter_TreeSitter.h

Lines changed: 0 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ts_tree.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
#include "com_itsaky_androidide_treesitter_TreeSitter.h"
1+
#include "com_itsaky_androidide_treesitter_TSTree_Native.h"
22
#include "ts_utils.h"
33

4-
JNIEXPORT void JNICALL Java_com_itsaky_androidide_treesitter_TreeSitter_treeEdit(
4+
JNIEXPORT void JNICALL Java_com_itsaky_androidide_treesitter_TSTree_00024Native_edit(
55
JNIEnv* env, jclass self, jlong tree, jobject inputEdit) {
66

77
TSInputEdit edit = _unmarshalInputEdit(env, inputEdit);
88
ts_tree_edit((TSTree*) tree, &edit);
99
}
1010

11-
JNIEXPORT void JNICALL Java_com_itsaky_androidide_treesitter_TreeSitter_treeDelete(
11+
JNIEXPORT void JNICALL Java_com_itsaky_androidide_treesitter_TSTree_00024Native_delete(
1212
JNIEnv* env, jclass self, jlong tree) {
1313
ts_tree_delete((TSTree*)tree);
1414
}
1515

16-
JNIEXPORT jlong JNICALL Java_com_itsaky_androidide_treesitter_TreeSitter_treeCopy(
16+
JNIEXPORT jlong JNICALL Java_com_itsaky_androidide_treesitter_TSTree_00024Native_copy(
1717
JNIEnv* env, jclass self, jlong tree) {
1818
return (jlong) ts_tree_copy((TSTree*)tree);
1919
}
2020

21-
JNIEXPORT jobject JNICALL Java_com_itsaky_androidide_treesitter_TreeSitter_treeRootNode(
21+
JNIEXPORT jobject JNICALL Java_com_itsaky_androidide_treesitter_TSTree_00024Native_rootNode(
2222
JNIEnv* env, jclass self, jlong tree) {
2323
return _marshalNode(env, ts_tree_root_node((TSTree*)tree));
2424
}

0 commit comments

Comments
 (0)