Skip to content

Commit

Permalink
refactor: remove unused stuffs from jni-utils.h
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Feb 1, 2025
1 parent 071297e commit 718d09d
Showing 1 changed file with 6 additions and 65 deletions.
71 changes: 6 additions & 65 deletions app/src/main/jni/librime_jni/jni-utils.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
/*
* SPDX-FileCopyrightText: 2024 Rime community
* SPDX-FileCopyrightText: 2015 - 2025 Rime community
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

// SPDX-FileCopyrightText: 2015 - 2024 Rime community
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef TRIME_JNI_UTILS_H
#define TRIME_JNI_UTILS_H
#pragma once

#include <jni.h>
#include <utf8.h>
Expand All @@ -22,12 +16,6 @@ static inline void throwJavaException(JNIEnv *env, const char *msg) {
env->DeleteLocalRef(c);
}

static inline jint extract_int(JNIEnv *env, jobject f) {
return env->CallIntMethod(
f,
env->GetMethodID(env->FindClass("java/lang/Integer"), "intValue", "()I"));
}

class CString {
private:
JNIEnv *env_;
Expand Down Expand Up @@ -89,28 +77,12 @@ class JString {
jstring operator*() { return jstring_; }
};

class JClass {
private:
JNIEnv *env_;
jclass jclass_;

public:
JClass(JNIEnv *env, const char *name)
: env_(env), jclass_(env->FindClass(name)) {}

~JClass() { env_->DeleteLocalRef(jclass_); }

operator jclass() { return jclass_; }

jclass operator*() { return jclass_; }
};

class JEnv {
private:
JNIEnv *env;
JNIEnv *env = nullptr;

public:
JEnv(JavaVM *jvm) {
explicit JEnv(JavaVM *jvm) {
if (jvm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) ==
JNI_EDETACHED) {
jvm->AttachCurrentThread(&env, nullptr);
Expand All @@ -136,18 +108,6 @@ class GlobalRefSingleton {
jclass Boolean;
jmethodID BooleanInit;

jclass HashMap;
jmethodID HashMapInit;
jmethodID HashMapPut;

jclass ArrayList;
jmethodID ArrayListInit;
jmethodID ArrayListAdd;

jclass Pair;
jmethodID PairFirst;
jmethodID PairSecond;

jclass Rime;
jmethodID HandleRimeMessage;

Expand Down Expand Up @@ -180,7 +140,7 @@ class GlobalRefSingleton {
jclass KeyEvent;
jmethodID KeyEventInit;

GlobalRefSingleton(JavaVM *jvm_) : jvm(jvm_) {
explicit GlobalRefSingleton(JavaVM *jvm_) : jvm(jvm_) {
JNIEnv *env;
jvm->AttachCurrentThread(&env, nullptr);

Expand All @@ -198,23 +158,6 @@ class GlobalRefSingleton {
env->NewGlobalRef(env->FindClass("java/lang/Boolean")));
BooleanInit = env->GetMethodID(Boolean, "<init>", "(Z)V");

HashMap = reinterpret_cast<jclass>(
env->NewGlobalRef(env->FindClass("java/util/HashMap")));
HashMapInit = env->GetMethodID(HashMap, "<init>", "()V");
HashMapPut = env->GetMethodID(
HashMap, "put",
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

ArrayList = reinterpret_cast<jclass>(
env->NewGlobalRef(env->FindClass("java/util/ArrayList")));
ArrayListInit = env->GetMethodID(ArrayList, "<init>", "(I)V");
ArrayListAdd = env->GetMethodID(ArrayList, "add", "(ILjava/lang/Object;)V");

Pair = reinterpret_cast<jclass>(
env->NewGlobalRef(env->FindClass("kotlin/Pair")));
PairFirst = env->GetMethodID(Pair, "getFirst", "()Ljava/lang/Object;");
PairSecond = env->GetMethodID(Pair, "getSecond", "()Ljava/lang/Object;");

Rime = reinterpret_cast<jclass>(
env->NewGlobalRef(env->FindClass("com/osfans/trime/core/Rime")));
HandleRimeMessage = env->GetStaticMethodID(Rime, "handleRimeMessage",
Expand Down Expand Up @@ -277,9 +220,7 @@ class GlobalRefSingleton {
env->GetMethodID(KeyEvent, "<init>", "(IILjava/lang/String;)V");
}

const JEnv AttachEnv() const { return JEnv(jvm); }
[[nodiscard]] JEnv AttachEnv() const { return JEnv(jvm); }
};

extern GlobalRefSingleton *GlobalRef;

#endif // TRIME_JNI_UTILS_H

0 comments on commit 718d09d

Please sign in to comment.