fix(java): new filetree, mistake in create_buffer

This commit is contained in:
zaaarf 2024-08-21 23:41:22 +02:00
parent 4004f2011f
commit 21f1948f04
No known key found for this signature in database
GPG key ID: 102E445F4C3F829B
2 changed files with 19 additions and 8 deletions

View file

@ -28,14 +28,14 @@ public class Workspace {
return Optional.ofNullable(get_buffer(this.ptr, path)); return Optional.ofNullable(get_buffer(this.ptr, path));
} }
private static native String[] get_file_tree(long self); private static native String[] get_file_tree(long self, String filter);
public String[] getFileTree() { public String[] getFileTree(Optional<String> filter) {
return get_file_tree(this.ptr); return get_file_tree(this.ptr, filter.orElse(null));
} }
private static native long create_buffer(String path) throws CodeMPException; private static native void create_buffer(String path) throws CodeMPException;
public BufferController createBuffer(String path) throws CodeMPException { public void createBuffer(String path) throws CodeMPException {
return new BufferController(create_buffer(path)); create_buffer(path);
} }
private static native BufferController attach_to_buffer(long self, String path) throws CodeMPException; private static native BufferController attach_to_buffer(long self, String path) throws CodeMPException;

View file

@ -69,9 +69,20 @@ pub extern "system" fn Java_mp_code_Workspace_get_1file_1tree(
mut env: JNIEnv, mut env: JNIEnv,
_class: JClass, _class: JClass,
self_ptr: jlong, self_ptr: jlong,
filter: JString
) -> jobjectArray { ) -> jobjectArray {
let workspace = unsafe { Box::leak(Box::from_raw(self_ptr as *mut Workspace)) }; let workspace = unsafe { Box::leak(Box::from_raw(self_ptr as *mut Workspace)) };
let file_tree = workspace.filetree(); let filter: Option<String> = if filter.is_null() {
None
} else {
Some(
env.get_string(&filter)
.map(|s| s.into())
.jexcept(&mut env)
)
};
let file_tree = workspace.filetree(filter.as_deref());
env.find_class("java/lang/String") env.find_class("java/lang/String")
.and_then(|class| env.new_object_array(file_tree.len() as i32, class, JObject::null())) .and_then(|class| env.new_object_array(file_tree.len() as i32, class, JObject::null()))
.map(|arr| { .map(|arr| {