Added: Add annotations and modifiers

This commit is contained in:
agnostic-apollo
2022-01-22 04:46:24 +05:00
parent 1fb4fe2510
commit bf10c72661
8 changed files with 49 additions and 32 deletions

View File

@@ -12,6 +12,9 @@ import android.media.SoundPool;
import android.text.TextUtils; import android.text.TextUtils;
import android.widget.ListView; import android.widget.ListView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.termux.R; import com.termux.R;
import com.termux.shared.termux.shell.command.runner.terminal.TermuxSession; import com.termux.shared.termux.shell.command.runner.terminal.TermuxSession;
import com.termux.shared.termux.interact.TextInputDialogUtils; import com.termux.shared.termux.interact.TextInputDialogUtils;
@@ -108,14 +111,14 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
@Override @Override
public void onTextChanged(TerminalSession changedSession) { public void onTextChanged(@NonNull TerminalSession changedSession) {
if (!mActivity.isVisible()) return; if (!mActivity.isVisible()) return;
if (mActivity.getCurrentSession() == changedSession) mActivity.getTerminalView().onScreenUpdated(); if (mActivity.getCurrentSession() == changedSession) mActivity.getTerminalView().onScreenUpdated();
} }
@Override @Override
public void onTitleChanged(TerminalSession updatedSession) { public void onTitleChanged(@NonNull TerminalSession updatedSession) {
if (!mActivity.isVisible()) return; if (!mActivity.isVisible()) return;
if (updatedSession != mActivity.getCurrentSession()) { if (updatedSession != mActivity.getCurrentSession()) {
@@ -129,7 +132,7 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
} }
@Override @Override
public void onSessionFinished(final TerminalSession finishedSession) { public void onSessionFinished(@NonNull TerminalSession finishedSession) {
TermuxService service = mActivity.getTermuxService(); TermuxService service = mActivity.getTermuxService();
if (service == null || service.wantsToStop()) { if (service == null || service.wantsToStop()) {
@@ -174,7 +177,7 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
} }
@Override @Override
public void onCopyTextToClipboard(TerminalSession session, String text) { public void onCopyTextToClipboard(@NonNull TerminalSession session, String text) {
if (!mActivity.isVisible()) return; if (!mActivity.isVisible()) return;
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
@@ -182,7 +185,7 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
} }
@Override @Override
public void onPasteTextFromClipboard(TerminalSession session) { public void onPasteTextFromClipboard(@Nullable TerminalSession session) {
if (!mActivity.isVisible()) return; if (!mActivity.isVisible()) return;
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
@@ -194,7 +197,7 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
} }
@Override @Override
public void onBell(TerminalSession session) { public void onBell(@NonNull TerminalSession session) {
if (!mActivity.isVisible()) return; if (!mActivity.isVisible()) return;
switch (mActivity.getProperties().getBellBehaviour()) { switch (mActivity.getProperties().getBellBehaviour()) {
@@ -213,7 +216,7 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
} }
@Override @Override
public void onColorsChanged(TerminalSession changedSession) { public void onColorsChanged(@NonNull TerminalSession changedSession) {
if (mActivity.getCurrentSession() == changedSession) if (mActivity.getCurrentSession() == changedSession)
updateBackgroundColor(); updateBackgroundColor();
} }

View File

@@ -50,6 +50,7 @@ tasks.withType(Test) {
} }
dependencies { dependencies {
implementation 'androidx.annotation:annotation:1.3.0'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
} }

View File

@@ -1,5 +1,8 @@
package com.termux.terminal; package com.termux.terminal;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/** /**
* The interface for communication between {@link TerminalSession} and its client. It is used to * The interface for communication between {@link TerminalSession} and its client. It is used to
* send callbacks to the client when {@link TerminalSession} changes or for sending other * send callbacks to the client when {@link TerminalSession} changes or for sending other
@@ -7,19 +10,19 @@ package com.termux.terminal;
*/ */
public interface TerminalSessionClient { public interface TerminalSessionClient {
void onTextChanged(TerminalSession changedSession); void onTextChanged(@NonNull TerminalSession changedSession);
void onTitleChanged(TerminalSession changedSession); void onTitleChanged(@NonNull TerminalSession changedSession);
void onSessionFinished(TerminalSession finishedSession); void onSessionFinished(@NonNull TerminalSession finishedSession);
void onCopyTextToClipboard(TerminalSession session, String text); void onCopyTextToClipboard(@NonNull TerminalSession session, String text);
void onPasteTextFromClipboard(TerminalSession session); void onPasteTextFromClipboard(@Nullable TerminalSession session);
void onBell(TerminalSession session); void onBell(@NonNull TerminalSession session);
void onColorsChanged(TerminalSession session); void onColorsChanged(@NonNull TerminalSession session);
void onTerminalCursorStateChange(boolean state); void onTerminalCursorStateChange(boolean state);

View File

@@ -25,7 +25,7 @@ public class Errno {
public static final Errno ERRNO_FAILED = new Errno(TYPE, Activity.RESULT_FIRST_USER + 1, "Failed"); public static final Errno ERRNO_FAILED = new Errno(TYPE, Activity.RESULT_FIRST_USER + 1, "Failed");
/** The errno type. */ /** The errno type. */
protected String type; protected final String type;
/** The errno code. */ /** The errno code. */
protected final int code; protected final int code;
/** The errno message. */ /** The errno message. */
@@ -34,7 +34,7 @@ public class Errno {
private static final String LOG_TAG = "Errno"; private static final String LOG_TAG = "Errno";
public Errno(final String type, final int code, final String message) { public Errno(@NonNull final String type, final int code, @NonNull final String message) {
this.type = type; this.type = type;
this.code = code; this.code = code;
this.message = message; this.message = message;
@@ -47,19 +47,22 @@ public class Errno {
return "type=" + type + ", code=" + code + ", message=\"" + message + "\""; return "type=" + type + ", code=" + code + ", message=\"" + message + "\"";
} }
@NonNull
public String getType() { public String getType() {
return type; return type;
} }
public String getMessage() {
return message;
}
public int getCode() { public int getCode() {
return code; return code;
} }
@NonNull
public String getMessage() {
return message;
}
/** /**
* Get the {@link Errno} of a specific type and code. * Get the {@link Errno} of a specific type and code.
* *

View File

@@ -4,6 +4,7 @@ import android.os.Build;
import android.system.Os; import android.system.Os;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.common.io.RecursiveDeleteOption; import com.google.common.io.RecursiveDeleteOption;
import com.termux.shared.file.filesystem.FileType; import com.termux.shared.file.filesystem.FileType;
@@ -97,6 +98,7 @@ public class FileUtils {
* @param path The {@code path} to convert. * @param path The {@code path} to convert.
* @return Returns the {@code normalized path}. * @return Returns the {@code normalized path}.
*/ */
@Nullable
public static String normalizePath(String path) { public static String normalizePath(String path) {
if (path == null) return null; if (path == null) return null;
@@ -247,7 +249,7 @@ public class FileUtils {
} }
/** /**
* Checks the type of file that exists at {@code filePath}. * Get the type of file that exists at {@code filePath}.
* *
* This function is a wrapper for * This function is a wrapper for
* {@link FileTypes#getFileType(String, boolean)} * {@link FileTypes#getFileType(String, boolean)}
@@ -260,6 +262,7 @@ public class FileUtils {
* returned. * returned.
* @return Returns the {@link FileType} of file. * @return Returns the {@link FileType} of file.
*/ */
@NonNull
public static FileType getFileType(final String filePath, final boolean followLinks) { public static FileType getFileType(final String filePath, final boolean followLinks) {
return FileTypes.getFileType(filePath, followLinks); return FileTypes.getFileType(filePath, followLinks);
} }
@@ -1446,8 +1449,8 @@ public class FileUtils {
} }
public static class ReadSerializableObjectResult { public static class ReadSerializableObjectResult {
public Error error; public final Error error;
public Serializable serializableObject; public final Serializable serializableObject;
ReadSerializableObjectResult(Error error, Serializable serializableObject) { ReadSerializableObjectResult(Error error, Serializable serializableObject) {
this.error = error; this.error = error;

View File

@@ -94,7 +94,7 @@ public class FileUtilsErrno extends Errno {
/** Defines the {@link Errno} mapping to get a shorter version of {@link FileUtilsErrno}. */ /** Defines the {@link Errno} mapping to get a shorter version of {@link FileUtilsErrno}. */
public static Map<Errno, Errno> ERRNO_SHORT_MAPPING = new HashMap<Errno, Errno>() {{ public static final Map<Errno, Errno> ERRNO_SHORT_MAPPING = new HashMap<Errno, Errno>() {{
put(ERRNO_FILE_NOT_FOUND_AT_PATH, ERRNO_FILE_NOT_FOUND_AT_PATH_SHORT); put(ERRNO_FILE_NOT_FOUND_AT_PATH, ERRNO_FILE_NOT_FOUND_AT_PATH_SHORT);
put(ERRNO_NON_REGULAR_FILE_FOUND, ERRNO_NON_REGULAR_FILE_FOUND_SHORT); put(ERRNO_NON_REGULAR_FILE_FOUND, ERRNO_NON_REGULAR_FILE_FOUND_SHORT);

View File

@@ -82,6 +82,7 @@ public class FileTypes {
* returned. * returned.
* @return Returns the {@link FileType} of file. * @return Returns the {@link FileType} of file.
*/ */
@NonNull
public static FileType getFileType(final String filePath, final boolean followLinks) { public static FileType getFileType(final String filePath, final boolean followLinks) {
if (filePath == null || filePath.isEmpty()) return FileType.NO_EXIST; if (filePath == null || filePath.isEmpty()) return FileType.NO_EXIST;

View File

@@ -1,5 +1,8 @@
package com.termux.shared.termux.terminal; package com.termux.shared.termux.terminal;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.termux.shared.logger.Logger; import com.termux.shared.logger.Logger;
import com.termux.terminal.TerminalSession; import com.termux.terminal.TerminalSession;
import com.termux.terminal.TerminalSessionClient; import com.termux.terminal.TerminalSessionClient;
@@ -10,31 +13,31 @@ public class TermuxTerminalSessionClientBase implements TerminalSessionClient {
} }
@Override @Override
public void onTextChanged(TerminalSession changedSession) { public void onTextChanged(@NonNull TerminalSession changedSession) {
} }
@Override @Override
public void onTitleChanged(TerminalSession updatedSession) { public void onTitleChanged(@NonNull TerminalSession updatedSession) {
} }
@Override @Override
public void onSessionFinished(final TerminalSession finishedSession) { public void onSessionFinished(@NonNull TerminalSession finishedSession) {
} }
@Override @Override
public void onCopyTextToClipboard(TerminalSession session, String text) { public void onCopyTextToClipboard(@NonNull TerminalSession session, String text) {
} }
@Override @Override
public void onPasteTextFromClipboard(TerminalSession session) { public void onPasteTextFromClipboard(@Nullable TerminalSession session) {
} }
@Override @Override
public void onBell(TerminalSession session) { public void onBell(@NonNull TerminalSession session) {
} }
@Override @Override
public void onColorsChanged(TerminalSession changedSession) { public void onColorsChanged(@NonNull TerminalSession changedSession) {
} }
@Override @Override