diff --git a/dist/java/src/mp/code/BufferController.java b/dist/java/src/mp/code/BufferController.java index c0a706b..818bed6 100644 --- a/dist/java/src/mp/code/BufferController.java +++ b/dist/java/src/mp/code/BufferController.java @@ -2,7 +2,7 @@ package mp.code; import mp.code.data.Cursor; import mp.code.data.TextChange; -import mp.code.exceptions.CodeMPException; +import mp.code.exceptions.ControllerException; import java.util.Optional; @@ -18,23 +18,23 @@ public class BufferController { return get_name(this.ptr); } - private static native String get_content(long self) throws CodeMPException; - public String getContent() throws CodeMPException { + private static native String get_content(long self) throws ControllerException; + public String getContent() throws ControllerException { return get_content(this.ptr); } - private static native TextChange try_recv(long self) throws CodeMPException; - public Optional tryRecv() throws CodeMPException { + private static native TextChange try_recv(long self) throws ControllerException; + public Optional tryRecv() throws ControllerException { return Optional.ofNullable(try_recv(this.ptr)); } - private static native Cursor recv(long self) throws CodeMPException; - public Cursor recv() throws CodeMPException { + private static native Cursor recv(long self) throws ControllerException; + public Cursor recv() throws ControllerException { return recv(this.ptr); } - private static native void send(long self, TextChange change) throws CodeMPException; - public void send(TextChange change) throws CodeMPException { + private static native void send(long self, TextChange change) throws ControllerException; + public void send(TextChange change) throws ControllerException { send(this.ptr, change); } diff --git a/dist/java/src/mp/code/Client.java b/dist/java/src/mp/code/Client.java index c2edb30..a49d507 100644 --- a/dist/java/src/mp/code/Client.java +++ b/dist/java/src/mp/code/Client.java @@ -1,7 +1,8 @@ package mp.code; import cz.adamh.utils.NativeUtils; -import mp.code.exceptions.CodeMPException; +import mp.code.exceptions.ConnectionException; +import mp.code.exceptions.ConnectionRemoteException; import java.io.IOException; import java.util.Optional; @@ -9,7 +10,7 @@ import java.util.Optional; public class Client { private final long ptr; - public static native Client connect(String url, String username, String password) throws CodeMPException; + public static native Client connect(String url, String username, String password) throws ConnectionException; Client(long ptr) { this.ptr = ptr; } @@ -19,28 +20,28 @@ public class Client { return get_url(this.ptr); } - private static native Workspace join_workspace(long self, String id) throws CodeMPException; - public Workspace joinWorkspace(String id) throws CodeMPException { + private static native Workspace join_workspace(long self, String id) throws ConnectionException; + public Workspace joinWorkspace(String id) throws ConnectionException { return join_workspace(this.ptr, id); } - private static native void create_workspace(long self, String id) throws CodeMPException; - public void createWorkspace(String id) throws CodeMPException { - return create_workspace(this.ptr, id); + private static native void create_workspace(long self, String id) throws ConnectionRemoteException; + public void createWorkspace(String id) throws ConnectionRemoteException { + create_workspace(this.ptr, id); } - private static native void delete_workspace(long self, String id) throws CodeMPException; - public void deleteWorkspace(String id) throws CodeMPException { - return delete_workspace(this.ptr, id); + private static native void delete_workspace(long self, String id) throws ConnectionRemoteException; + public void deleteWorkspace(String id) throws ConnectionRemoteException { + delete_workspace(this.ptr, id); } - private static native void invite_to_workspace(long self, String ws, String usr) throws CodeMPException; - public void inviteToWorkspace(String ws, String usr) throws CodeMPException { - return invite_to_workspace(this.ptr, id); + private static native void invite_to_workspace(long self, String ws, String usr) throws ConnectionRemoteException; + public void inviteToWorkspace(String ws, String usr) throws ConnectionRemoteException { + invite_to_workspace(this.ptr, ws, usr); } - private static native String[] list_workspaces(long self, boolean owned, boolean invited) throws CodeMPException; - public String[] listWorkspaces(boolean owned, boolean invited) throws CodeMPException { + private static native String[] list_workspaces(long self, boolean owned, boolean invited) throws ConnectionRemoteException; + public String[] listWorkspaces(boolean owned, boolean invited) throws ConnectionRemoteException { return list_workspaces(this.ptr, owned, invited); } @@ -54,9 +55,9 @@ public class Client { return Optional.ofNullable(get_workspace(this.ptr)); } - private static native void refresh_native(long self); - public void refresh() { - return refresh_native(this.ptr); + private static native void refresh_native(long self) throws ConnectionRemoteException; + public void refresh() throws ConnectionRemoteException { + refresh_native(this.ptr); } private static native void free(long self); diff --git a/dist/java/src/mp/code/CursorController.java b/dist/java/src/mp/code/CursorController.java index 93d67db..fb93983 100644 --- a/dist/java/src/mp/code/CursorController.java +++ b/dist/java/src/mp/code/CursorController.java @@ -1,7 +1,7 @@ package mp.code; import mp.code.data.Cursor; -import mp.code.exceptions.CodeMPException; +import mp.code.exceptions.ControllerException; import java.util.Optional; @@ -12,18 +12,18 @@ public class CursorController { this.ptr = ptr; } - private static native Cursor try_recv(long self) throws CodeMPException; - public Optional tryRecv() throws CodeMPException { + private static native Cursor try_recv(long self) throws ControllerException; + public Optional tryRecv() throws ControllerException { return Optional.ofNullable(try_recv(this.ptr)); } - private static native Cursor recv(long self) throws CodeMPException; - public Cursor recv() throws CodeMPException { + private static native Cursor recv(long self) throws ControllerException; + public Cursor recv() throws ControllerException { return recv(this.ptr); } - private static native void send(long self, Cursor cursor) throws CodeMPException; - public void send(Cursor cursor) throws CodeMPException { + private static native void send(long self, Cursor cursor) throws ControllerException; + public void send(Cursor cursor) throws ControllerException { send(this.ptr, cursor); } diff --git a/dist/java/src/mp/code/Workspace.java b/dist/java/src/mp/code/Workspace.java index 3d1f8ce..ddc971a 100644 --- a/dist/java/src/mp/code/Workspace.java +++ b/dist/java/src/mp/code/Workspace.java @@ -4,7 +4,9 @@ import java.util.Optional; import java.util.UUID; import mp.code.data.DetachResult; -import mp.code.exceptions.CodeMPException; +import mp.code.exceptions.ConnectionException; +import mp.code.exceptions.ConnectionRemoteException; +import mp.code.exceptions.ControllerException; public class Workspace { private final long ptr; @@ -33,13 +35,13 @@ public class Workspace { return get_file_tree(this.ptr, filter.orElse(null)); } - private static native void create_buffer(String path) throws CodeMPException; - public void createBuffer(String path) throws CodeMPException { + private static native void create_buffer(String path) throws ConnectionRemoteException; + public void createBuffer(String path) throws ConnectionRemoteException { create_buffer(path); } - private static native BufferController attach_to_buffer(long self, String path) throws CodeMPException; - public BufferController attachToBuffer(String path) throws CodeMPException { + private static native BufferController attach_to_buffer(long self, String path) throws ConnectionException; + public BufferController attachToBuffer(String path) throws ConnectionException { return attach_to_buffer(ptr, path); } @@ -48,33 +50,33 @@ public class Workspace { return detach_from_buffer(this.ptr, path); } - private static native void fetch_buffers(long self) throws CodeMPException; - public void fetchBuffers() throws CodeMPException { + private static native void fetch_buffers(long self) throws ConnectionRemoteException; + public void fetchBuffers() throws ConnectionRemoteException { fetch_buffers(this.ptr); } - private static native void fetch_users(long self) throws CodeMPException; - public void fetchUsers() throws CodeMPException { + private static native void fetch_users(long self) throws ConnectionRemoteException; + public void fetchUsers() throws ConnectionRemoteException { fetch_buffers(this.ptr); } - private static native UUID[] list_buffer_users(long self, String path) throws CodeMPException; - public UUID[] listBufferUsers(String path) throws CodeMPException { + private static native UUID[] list_buffer_users(long self, String path) throws ConnectionRemoteException; + public UUID[] listBufferUsers(String path) throws ConnectionRemoteException { return list_buffer_users(this.ptr, path); } - private static native void delete_buffer(long self, String path) throws CodeMPException; - public void deleteBuffer(String path) throws CodeMPException { + private static native void delete_buffer(long self, String path) throws ConnectionRemoteException; + public void deleteBuffer(String path) throws ConnectionRemoteException { delete_buffer(this.ptr, path); } - private static native Event event(long self) throws CodeMPException; - public Event event() throws CodeMPException { + private static native Event event(long self) throws ControllerException; + public Event event() throws ControllerException { return event(this.ptr); } - private static native BufferController select_buffer(long self, long timeout) throws CodeMPException; - public Optional selectBuffer(long timeout) throws CodeMPException { + private static native BufferController select_buffer(long self, long timeout) throws ControllerException; + public Optional selectBuffer(long timeout) throws ControllerException { return Optional.ofNullable(select_buffer(this.ptr, timeout)); } diff --git a/dist/java/src/mp/code/exceptions/ChannelException.java b/dist/java/src/mp/code/exceptions/ChannelException.java deleted file mode 100644 index 54ac520..0000000 --- a/dist/java/src/mp/code/exceptions/ChannelException.java +++ /dev/null @@ -1,7 +0,0 @@ -package mp.code.exceptions; - -public class ChannelException extends CodeMPException { - public ChannelException(String input) { - super(input); - } -} diff --git a/dist/java/src/mp/code/exceptions/CodeMPException.java b/dist/java/src/mp/code/exceptions/CodeMPException.java deleted file mode 100644 index f9acc36..0000000 --- a/dist/java/src/mp/code/exceptions/CodeMPException.java +++ /dev/null @@ -1,10 +0,0 @@ -package mp.code.exceptions; - -/** - * A generic class for all our exceptions coming through the JNI from the library. - */ -public abstract class CodeMPException extends Exception { - protected CodeMPException(String msg) { - super(msg); - } -} diff --git a/dist/java/src/mp/code/exceptions/ConnectionException.java b/dist/java/src/mp/code/exceptions/ConnectionException.java new file mode 100644 index 0000000..264e1cc --- /dev/null +++ b/dist/java/src/mp/code/exceptions/ConnectionException.java @@ -0,0 +1,10 @@ +package mp.code.exceptions; + +/** + * An exception that may occur when processing network requests. + */ +public abstract class ConnectionException extends Exception { + protected ConnectionException(String msg) { + super(msg); + } +} diff --git a/dist/java/src/mp/code/exceptions/ConnectionRemoteException.java b/dist/java/src/mp/code/exceptions/ConnectionRemoteException.java new file mode 100644 index 0000000..32975ef --- /dev/null +++ b/dist/java/src/mp/code/exceptions/ConnectionRemoteException.java @@ -0,0 +1,10 @@ +package mp.code.exceptions; + +/** + * An exception returned by the server as a response. + */ +public abstract class ConnectionRemoteException extends Exception { + protected ConnectionRemoteException(String msg) { + super(msg); + } +} diff --git a/dist/java/src/mp/code/exceptions/ConnectionTransportException.java b/dist/java/src/mp/code/exceptions/ConnectionTransportException.java new file mode 100644 index 0000000..a4fe22e --- /dev/null +++ b/dist/java/src/mp/code/exceptions/ConnectionTransportException.java @@ -0,0 +1,10 @@ +package mp.code.exceptions; + +/** + * An exception that occurred from the underlying tonic layer. + */ +public abstract class ConnectionTransportException extends Exception { + protected ConnectionTransportException(String msg) { + super(msg); + } +} diff --git a/dist/java/src/mp/code/exceptions/ControllerException.java b/dist/java/src/mp/code/exceptions/ControllerException.java new file mode 100644 index 0000000..4a26f39 --- /dev/null +++ b/dist/java/src/mp/code/exceptions/ControllerException.java @@ -0,0 +1,13 @@ +package mp.code.exceptions; + +/** + * An exception that may occur when a {@link mp.code.BufferController} or + * a {@link mp.code.CursorController} perform an illegal operation. + * It may also occur as a result of {@link mp.code.Workspace#event()} and + * {@link mp.code.Workspace#selectBuffer(long)}. + */ +public abstract class ControllerException extends Exception { + protected ControllerException(String msg) { + super(msg); + } +} diff --git a/dist/java/src/mp/code/exceptions/ControllerStoppedException.java b/dist/java/src/mp/code/exceptions/ControllerStoppedException.java new file mode 100644 index 0000000..b8f8d52 --- /dev/null +++ b/dist/java/src/mp/code/exceptions/ControllerStoppedException.java @@ -0,0 +1,11 @@ +package mp.code.exceptions; + +/** + * An exception that occurs when attempting to send an operation when + * the worker has already stopped. + */ +public class ControllerStoppedException extends ControllerException { + protected ControllerStoppedException(String msg) { + super(msg); + } +} diff --git a/dist/java/src/mp/code/exceptions/ControllerUnfulfilledException.java b/dist/java/src/mp/code/exceptions/ControllerUnfulfilledException.java new file mode 100644 index 0000000..5c5a9cd --- /dev/null +++ b/dist/java/src/mp/code/exceptions/ControllerUnfulfilledException.java @@ -0,0 +1,11 @@ +package mp.code.exceptions; + +/** + * An exception that occurs when the underlying controller stopped before + * fulfilling the request, without rejecting it first. + */ +public class ControllerUnfulfilledException extends ControllerException { + protected ControllerUnfulfilledException(String msg) { + super(msg); + } +} diff --git a/dist/java/src/mp/code/exceptions/DeadlockedException.java b/dist/java/src/mp/code/exceptions/DeadlockedException.java deleted file mode 100644 index 2e4fa9e..0000000 --- a/dist/java/src/mp/code/exceptions/DeadlockedException.java +++ /dev/null @@ -1,7 +0,0 @@ -package mp.code.exceptions; - -public class DeadlockedException extends CodeMPException { - public DeadlockedException(String s) { - super(s); - } -} diff --git a/dist/java/src/mp/code/exceptions/InvalidStateException.java b/dist/java/src/mp/code/exceptions/InvalidStateException.java deleted file mode 100644 index 202d249..0000000 --- a/dist/java/src/mp/code/exceptions/InvalidStateException.java +++ /dev/null @@ -1,7 +0,0 @@ -package mp.code.exceptions; - -public class InvalidStateException extends CodeMPException { - public InvalidStateException(String message) { - super(message); - } -} diff --git a/dist/java/src/mp/code/exceptions/TransportException.java b/dist/java/src/mp/code/exceptions/TransportException.java deleted file mode 100644 index 0f6e476..0000000 --- a/dist/java/src/mp/code/exceptions/TransportException.java +++ /dev/null @@ -1,7 +0,0 @@ -package mp.code.exceptions; - -public class TransportException extends CodeMPException { - public TransportException(String message) { - super(message); - } -} diff --git a/src/ffi/java/buffer.rs b/src/ffi/java/buffer.rs index 41e915d..57dbb5a 100644 --- a/src/ffi/java/buffer.rs +++ b/src/ffi/java/buffer.rs @@ -12,7 +12,7 @@ pub extern "system" fn Java_mp_code_BufferController_get_1name( self_ptr: jlong, ) -> jstring { let controller = unsafe { Box::leak(Box::from_raw(self_ptr as *mut crate::buffer::Controller)) }; - let content = controller.name(); + let content = controller.path(); env.new_string(content) .jexcept(&mut env) .as_raw() diff --git a/src/ffi/java/client.rs b/src/ffi/java/client.rs index 3203b56..50767d1 100644 --- a/src/ffi/java/client.rs +++ b/src/ffi/java/client.rs @@ -3,7 +3,7 @@ use crate::{client::Client, Workspace}; use super::{JExceptable, RT}; -/// Connects to a given URL and returns a [Client] to interact with that server. +/// Connect to a given URL and return a [Client] to interact with that server. #[no_mangle] pub extern "system" fn Java_mp_code_Client_connect<'local>( mut env: JNIEnv, @@ -30,7 +30,7 @@ pub extern "system" fn Java_mp_code_Client_connect<'local>( }).jexcept(&mut env).as_raw() } -/// Joins a [Workspace] and returns a pointer to it. +/// Join a [Workspace] and return a pointer to it. #[no_mangle] pub extern "system" fn Java_mp_code_Client_join_1workspace<'local>( mut env: JNIEnv<'local>, @@ -52,7 +52,7 @@ pub extern "system" fn Java_mp_code_Client_join_1workspace<'local>( }).jexcept(&mut env).as_raw() } -/// Creates a workspace on server, if allowed to +/// Create a workspace on server, if allowed to. #[no_mangle] pub extern "system" fn Java_mp_code_Client_create_1workspace<'local>( mut env: JNIEnv<'local>, @@ -69,7 +69,7 @@ pub extern "system" fn Java_mp_code_Client_create_1workspace<'local>( .jexcept(&mut env); } -/// Deletes a workspace on server, if allowed to +/// Delete a workspace on server, if allowed to. #[no_mangle] pub extern "system" fn Java_mp_code_Client_delete_1workspace<'local>( mut env: JNIEnv<'local>, @@ -86,7 +86,7 @@ pub extern "system" fn Java_mp_code_Client_delete_1workspace<'local>( .jexcept(&mut env); } -/// Invites another user to an owned workspace +/// Invite another user to an owned workspace. #[no_mangle] pub extern "system" fn Java_mp_code_Client_invite_1to_1workspace<'local>( mut env: JNIEnv<'local>, @@ -107,7 +107,7 @@ pub extern "system" fn Java_mp_code_Client_invite_1to_1workspace<'local>( .jexcept(&mut env); } -/// List available workspaces +/// List available workspaces. #[no_mangle] pub extern "system" fn Java_mp_code_Client_list_1workspaces<'local>( mut env: JNIEnv<'local>, @@ -146,7 +146,7 @@ fn spawn_updater(workspace: Workspace) -> Workspace { workspace } -/// Leaves a [Workspace] and returns whether or not the client was in such workspace. +/// Leave a [Workspace] and return whether or not the client was in such workspace. #[no_mangle] pub extern "system" fn Java_mp_code_Client_leave_1workspace<'local>( mut env: JNIEnv<'local>, @@ -161,7 +161,7 @@ pub extern "system" fn Java_mp_code_Client_leave_1workspace<'local>( .jexcept(&mut env) } -/// Gets a [Workspace] by name and returns a pointer to it. +/// Get a [Workspace] by name and returns a pointer to it. #[no_mangle] pub extern "system" fn Java_mp_code_Client_get_1workspace<'local>( mut env: JNIEnv<'local>, @@ -182,7 +182,7 @@ pub extern "system" fn Java_mp_code_Client_get_1workspace<'local>( }).unwrap_or_default().as_raw() } -/// Refresh client's session token +/// Refresh the client's session token. #[no_mangle] pub extern "system" fn Java_mp_code_Client_refresh<'local>( mut env: JNIEnv<'local>, @@ -190,10 +190,11 @@ pub extern "system" fn Java_mp_code_Client_refresh<'local>( self_ptr: jlong, ) { let client = unsafe { Box::leak(Box::from_raw(self_ptr as *mut Client)) }; - RT.block_on(client.refresh()).jexcept(&mut env); + RT.block_on(client.refresh()) + .jexcept(&mut env); } -/// Sets up the tracing subscriber. +/// Set up the tracing subscriber. #[no_mangle] pub extern "system" fn Java_mp_code_Client_setup_1tracing<'local>( mut env: JNIEnv, diff --git a/src/ffi/java/cursor.rs b/src/ffi/java/cursor.rs index 7a43807..355f7c5 100644 --- a/src/ffi/java/cursor.rs +++ b/src/ffi/java/cursor.rs @@ -3,7 +3,7 @@ use crate::api::Controller; use super::{JExceptable, RT}; -/// Tries to fetch a [crate::api::Cursor], or returns null if there's nothing. +/// Try to fetch a [crate::api::Cursor], or returns null if there's nothing. #[no_mangle] pub extern "system" fn Java_mp_code_CursorController_try_1recv( mut env: JNIEnv, @@ -15,7 +15,7 @@ pub extern "system" fn Java_mp_code_CursorController_try_1recv( jni_recv(&mut env, cursor) } -/// Blocks until it receives a [crate::api::Cursor]. +/// Block until it receives a [crate::api::Cursor]. #[no_mangle] pub extern "system" fn Java_mp_code_CursorController_recv( mut env: JNIEnv, @@ -56,7 +56,7 @@ fn jni_recv(env: &mut JNIEnv, cursor: Option) -> jobject { }.as_raw() } -/// Receives from Java, converts and sends a [crate::api::Cursor]. +/// Receive from Java, converts and sends a [crate::api::Cursor]. #[no_mangle] pub extern "system" fn Java_mp_code_CursorController_send<'local>( mut env: JNIEnv, diff --git a/src/ffi/java/mod.rs b/src/ffi/java/mod.rs index aa1719c..7c0ca05 100644 --- a/src/ffi/java/mod.rs +++ b/src/ffi/java/mod.rs @@ -16,7 +16,7 @@ lazy_static::lazy_static! { pub(crate) static ref RT: tokio::runtime::Runtime = tokio::runtime::Runtime::new().expect("could not create tokio runtime"); } -/// Sets up logging. Useful for debugging. +/// Set up logging. Useful for debugging. pub(crate) fn setup_logger(debug: bool, path: Option) { let format = tracing_subscriber::fmt::format() .with_level(true) @@ -43,23 +43,44 @@ pub(crate) fn setup_logger(debug: bool, path: Option) { } } -/// A trait meant for our [crate::Result] type to make converting it to Java easier. +/// A trait meant for our local result type to make converting it to Java easier. /// jni-rs technically has [jni::errors::ToException], but this approach keeps it stream-like. pub(crate) trait JExceptable { - /// Unwraps it and throws an appropriate Java exception if it's an error. + /// Unwrap it and throws an appropriate Java exception if it's an error. /// Theoretically it returns the type's default value, but the exception makes the value ignored. fn jexcept(self, env: &mut jni::JNIEnv) -> T; } -impl JExceptable for crate::Result where T: Default { +impl JExceptable for crate::errors::ConnectionResult where T: Default { fn jexcept(self, env: &mut jni::JNIEnv) -> T { if let Err(err) = &self { let msg = format!("{err}"); match err { - crate::Error::InvalidState { .. } => env.throw_new("mp/code/exceptions/InvalidStateException", msg), - crate::Error::Deadlocked => env.throw_new("mp/code/exceptions/DeadlockedException", msg), - crate::Error::Transport { .. } => env.throw_new("mp/code/exceptions/TransportException", msg), - crate::Error::Channel { .. } => env.throw_new("mp/code/exceptions/ChannelException", msg) + crate::errors::ConnectionError::Transport(_) => env.throw_new("mp/code/exceptions/ConnectionTransportException", msg), + crate::errors::ConnectionError::Remote(_) => env.throw_new("mp/code/exceptions/ConnectionRemoteException", msg), + }.jexcept(env); + } + self.unwrap_or_default() + } +} + +impl JExceptable for crate::errors::RemoteResult where T: Default { + fn jexcept(self, env: &mut jni::JNIEnv) -> T { + if let Err(err) = &self { + let msg = format!("{err}"); + env.throw_new("mp/code/exceptions/connection/RemoteException", msg).jexcept(env); + } + self.unwrap_or_default() + } +} + +impl JExceptable for crate::errors::ControllerResult where T: Default { + fn jexcept(self, env: &mut jni::JNIEnv) -> T { + if let Err(err) = &self { + let msg = format!("{err}"); + match err { + crate::errors::ControllerError::Stopped => env.throw_new("mp/code/exceptions/ControllerStoppedException", msg), + crate::errors::ControllerError::Unfulfilled => env.throw_new("mp/code/exceptions/ControllerUnfulfilledException", msg), }.jexcept(env); } self.unwrap_or_default() @@ -94,7 +115,7 @@ pub(crate) trait JObjectify<'local> { /// The error type, likely to be [jni::errors::Error]. type Error; - /// Attempts to convert the given object to a [jni::objects::JObject]. + /// Attempt to convert the given object to a [jni::objects::JObject]. fn jobjectify(self, env: &mut jni::JNIEnv<'local>) -> Result, Self::Error>; } diff --git a/src/ffi/java/utils.rs b/src/ffi/java/utils.rs index ef421c4..18abd03 100644 --- a/src/ffi/java/utils.rs +++ b/src/ffi/java/utils.rs @@ -2,7 +2,7 @@ use jni::{objects::{JClass, JString}, sys::jlong, JNIEnv}; use super::JExceptable; -/// Calculates the XXH3 hash for a given String. +/// Calculate the XXH3 hash for a given String. #[no_mangle] pub extern "system" fn Java_mp_code_Utils_hash<'local>( mut env: JNIEnv, diff --git a/src/ffi/java/workspace.rs b/src/ffi/java/workspace.rs index 71e9ca1..14e57ef 100644 --- a/src/ffi/java/workspace.rs +++ b/src/ffi/java/workspace.rs @@ -3,7 +3,7 @@ use crate::Workspace; use super::{JExceptable, JObjectify, RT}; -/// Gets the workspace id. +/// Get the workspace id. #[no_mangle] pub extern "system" fn Java_mp_code_Workspace_get_1workspace_1id<'local>( mut env: JNIEnv<'local>, @@ -14,7 +14,7 @@ pub extern "system" fn Java_mp_code_Workspace_get_1workspace_1id<'local>( env.new_string(workspace.id()).jexcept(&mut env).as_raw() } -/// Gets a cursor controller by name and returns a pointer to it. +/// Get a cursor controller by name and returns a pointer to it. #[no_mangle] pub extern "system" fn Java_mp_code_Workspace_get_1cursor<'local>( mut env: JNIEnv<'local>, @@ -27,7 +27,7 @@ pub extern "system" fn Java_mp_code_Workspace_get_1cursor<'local>( ).jexcept(&mut env).as_raw() } -/// Gets a buffer controller by name and returns a pointer to it. +/// Get a buffer controller by name and returns a pointer to it. #[no_mangle] pub extern "system" fn Java_mp_code_Workspace_get_1buffer<'local>( mut env: JNIEnv<'local>, @@ -47,7 +47,7 @@ pub extern "system" fn Java_mp_code_Workspace_get_1buffer<'local>( }).unwrap_or_default().as_raw() } -/// Creates a new buffer. +/// Create a new buffer. #[no_mangle] pub extern "system" fn Java_mp_code_Workspace_create_1buffer<'local>( mut env: JNIEnv, @@ -63,7 +63,7 @@ pub extern "system" fn Java_mp_code_Workspace_create_1buffer<'local>( .jexcept(&mut env); } -/// Gets the filetree. +/// Get the filetree. #[no_mangle] pub extern "system" fn Java_mp_code_Workspace_get_1file_1tree( mut env: JNIEnv, @@ -95,7 +95,7 @@ pub extern "system" fn Java_mp_code_Workspace_get_1file_1tree( }).jexcept(&mut env).as_raw() } -/// Attaches to a buffer and returns a pointer to its [crate::buffer::Controller]. +/// Attach to a buffer and return a pointer to its [crate::buffer::Controller]. #[no_mangle] pub extern "system" fn Java_mp_code_Workspace_attach_1to_1buffer<'local>( mut env: JNIEnv, @@ -116,6 +116,7 @@ pub extern "system" fn Java_mp_code_Workspace_attach_1to_1buffer<'local>( }).jexcept(&mut env).as_raw() } +/// Detach from a buffer. #[no_mangle] pub extern "system" fn Java_mp_code_Workspace_detach_1from_1buffer<'local>( mut env: JNIEnv, @@ -128,9 +129,9 @@ pub extern "system" fn Java_mp_code_Workspace_detach_1from_1buffer<'local>( .map(|path| path.to_string_lossy().to_string()) .jexcept(&mut env); let name = match workspace.detach(&path) { - crate::workspace::worker::DetachResult::NotAttached => "NOT_ATTACHED", - crate::workspace::worker::DetachResult::Detaching => "DETACHED", - crate::workspace::worker::DetachResult::AlreadyDetached => "ALREADY_DETACHED" + crate::workspace::DetachResult::NotAttached => "NOT_ATTACHED", + crate::workspace::DetachResult::Detaching => "DETACHED", + crate::workspace::DetachResult::AlreadyDetached => "ALREADY_DETACHED" }; env.find_class("mp/code/data/DetachResult") @@ -140,7 +141,7 @@ pub extern "system" fn Java_mp_code_Workspace_detach_1from_1buffer<'local>( .as_raw() } -/// Updates the local buffer list. +/// Update the local buffer list. #[no_mangle] pub extern "system" fn Java_mp_code_Workspace_fetch_1buffers( mut env: JNIEnv, @@ -151,7 +152,7 @@ pub extern "system" fn Java_mp_code_Workspace_fetch_1buffers( RT.block_on(workspace.fetch_buffers()).jexcept(&mut env); } -/// Updates the local user list. +/// Update the local user list. #[no_mangle] pub extern "system" fn Java_mp_code_Workspace_fetch_1users( mut env: JNIEnv, @@ -162,7 +163,7 @@ pub extern "system" fn Java_mp_code_Workspace_fetch_1users( RT.block_on(workspace.fetch_users()).jexcept(&mut env); } -/// Lists users attached to a buffer. +/// List users attached to a buffer. #[no_mangle] pub extern "system" fn Java_mp_code_Workspace_list_1buffer_1users<'local>( mut env: JNIEnv, @@ -189,7 +190,7 @@ pub extern "system" fn Java_mp_code_Workspace_list_1buffer_1users<'local>( }).jexcept(&mut env).as_raw() } -/// Deletes a buffer. +/// Delete a buffer. #[no_mangle] pub extern "system" fn Java_mp_code_Workspace_delete_1buffer<'local>( mut env: JNIEnv, @@ -201,10 +202,11 @@ pub extern "system" fn Java_mp_code_Workspace_delete_1buffer<'local>( let buffer = unsafe { env.get_string_unchecked(&input) } .map(|buffer| buffer.to_string_lossy().to_string()) .jexcept(&mut env); - RT.block_on(workspace.delete(&buffer)).jexcept(&mut env); + RT.block_on(workspace.delete(&buffer)) + .jexcept(&mut env); } -/// Receives a workspace event if present. +/// Receive a workspace event if present. #[no_mangle] pub extern "system" fn Java_mp_code_Workspace_event( mut env: JNIEnv, @@ -236,7 +238,7 @@ pub extern "system" fn Java_mp_code_Workspace_event( }).jexcept(&mut env).as_raw() } -/// Polls a list of buffers, returning the first ready one. +/// Poll a list of buffers, returning the first ready one. #[no_mangle] pub extern "system" fn Java_mp_code_Workspace_select_1buffer( mut env: JNIEnv,