Skip to content

Commit 718d09d

Browse files
committed
refactor: remove unused stuffs from jni-utils.h
1 parent 071297e commit 718d09d

File tree

1 file changed

+6
-65
lines changed

1 file changed

+6
-65
lines changed

app/src/main/jni/librime_jni/jni-utils.h

Lines changed: 6 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Rime community
2+
* SPDX-FileCopyrightText: 2015 - 2025 Rime community
33
*
44
* SPDX-License-Identifier: GPL-3.0-or-later
55
*/
6-
7-
// SPDX-FileCopyrightText: 2015 - 2024 Rime community
8-
//
9-
// SPDX-License-Identifier: GPL-3.0-or-later
10-
11-
#ifndef TRIME_JNI_UTILS_H
12-
#define TRIME_JNI_UTILS_H
6+
#pragma once
137

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

25-
static inline jint extract_int(JNIEnv *env, jobject f) {
26-
return env->CallIntMethod(
27-
f,
28-
env->GetMethodID(env->FindClass("java/lang/Integer"), "intValue", "()I"));
29-
}
30-
3119
class CString {
3220
private:
3321
JNIEnv *env_;
@@ -89,28 +77,12 @@ class JString {
8977
jstring operator*() { return jstring_; }
9078
};
9179

92-
class JClass {
93-
private:
94-
JNIEnv *env_;
95-
jclass jclass_;
96-
97-
public:
98-
JClass(JNIEnv *env, const char *name)
99-
: env_(env), jclass_(env->FindClass(name)) {}
100-
101-
~JClass() { env_->DeleteLocalRef(jclass_); }
102-
103-
operator jclass() { return jclass_; }
104-
105-
jclass operator*() { return jclass_; }
106-
};
107-
10880
class JEnv {
10981
private:
110-
JNIEnv *env;
82+
JNIEnv *env = nullptr;
11183

11284
public:
113-
JEnv(JavaVM *jvm) {
85+
explicit JEnv(JavaVM *jvm) {
11486
if (jvm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) ==
11587
JNI_EDETACHED) {
11688
jvm->AttachCurrentThread(&env, nullptr);
@@ -136,18 +108,6 @@ class GlobalRefSingleton {
136108
jclass Boolean;
137109
jmethodID BooleanInit;
138110

139-
jclass HashMap;
140-
jmethodID HashMapInit;
141-
jmethodID HashMapPut;
142-
143-
jclass ArrayList;
144-
jmethodID ArrayListInit;
145-
jmethodID ArrayListAdd;
146-
147-
jclass Pair;
148-
jmethodID PairFirst;
149-
jmethodID PairSecond;
150-
151111
jclass Rime;
152112
jmethodID HandleRimeMessage;
153113

@@ -180,7 +140,7 @@ class GlobalRefSingleton {
180140
jclass KeyEvent;
181141
jmethodID KeyEventInit;
182142

183-
GlobalRefSingleton(JavaVM *jvm_) : jvm(jvm_) {
143+
explicit GlobalRefSingleton(JavaVM *jvm_) : jvm(jvm_) {
184144
JNIEnv *env;
185145
jvm->AttachCurrentThread(&env, nullptr);
186146

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

201-
HashMap = reinterpret_cast<jclass>(
202-
env->NewGlobalRef(env->FindClass("java/util/HashMap")));
203-
HashMapInit = env->GetMethodID(HashMap, "<init>", "()V");
204-
HashMapPut = env->GetMethodID(
205-
HashMap, "put",
206-
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
207-
208-
ArrayList = reinterpret_cast<jclass>(
209-
env->NewGlobalRef(env->FindClass("java/util/ArrayList")));
210-
ArrayListInit = env->GetMethodID(ArrayList, "<init>", "(I)V");
211-
ArrayListAdd = env->GetMethodID(ArrayList, "add", "(ILjava/lang/Object;)V");
212-
213-
Pair = reinterpret_cast<jclass>(
214-
env->NewGlobalRef(env->FindClass("kotlin/Pair")));
215-
PairFirst = env->GetMethodID(Pair, "getFirst", "()Ljava/lang/Object;");
216-
PairSecond = env->GetMethodID(Pair, "getSecond", "()Ljava/lang/Object;");
217-
218161
Rime = reinterpret_cast<jclass>(
219162
env->NewGlobalRef(env->FindClass("com/osfans/trime/core/Rime")));
220163
HandleRimeMessage = env->GetStaticMethodID(Rime, "handleRimeMessage",
@@ -277,9 +220,7 @@ class GlobalRefSingleton {
277220
env->GetMethodID(KeyEvent, "<init>", "(IILjava/lang/String;)V");
278221
}
279222

280-
const JEnv AttachEnv() const { return JEnv(jvm); }
223+
[[nodiscard]] JEnv AttachEnv() const { return JEnv(jvm); }
281224
};
282225

283226
extern GlobalRefSingleton *GlobalRef;
284-
285-
#endif // TRIME_JNI_UTILS_H

0 commit comments

Comments
 (0)