Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 0d76c98

Browse files
committed
v2 jni: refactoring, extract a constant
Signed-off-by: Alexander Bezzubov <[email protected]>
1 parent 8162713 commit 0d76c98

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/main/native/org_bblfsh_client_v2_libuast_Libuast.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobject asJvmBuffer(uast::Buffer buf) {
1515
return env->NewDirectByteBuffer(buf.ptr, buf.size);
1616
}
1717

18+
const char *nativeContext = "nativeContext";
19+
1820
jfieldID getHandleField(JNIEnv *env, jobject obj, const char *name) {
1921
jclass cls = env->GetObjectClass(obj);
2022
if (env->ExceptionOccurred() || !cls) {
@@ -145,22 +147,22 @@ JNIEXPORT jobject JNICALL Java_org_bblfsh_client_v2_libuast_Libuast_filter(
145147
// v2.Context()
146148
JNIEXPORT jobject JNICALL Java_org_bblfsh_client_v2_Context_root(JNIEnv *env,
147149
jobject self) {
148-
ContextExt *p = getHandle<ContextExt>(env, self, "nativeContext");
150+
ContextExt *p = getHandle<ContextExt>(env, self, nativeContext);
149151
return p->RootNode();
150152
}
151153

152154
JNIEXPORT jobject JNICALL Java_org_bblfsh_client_v2_Context_encode(
153155
JNIEnv *env, jobject self, jobject node) {
154156
UastFormat fmt = UAST_BINARY; // TODO(bzz): make it argument & enum
155157

156-
ContextExt *p = getHandle<ContextExt>(env, self, "nativeContext");
158+
ContextExt *p = getHandle<ContextExt>(env, self, nativeContext);
157159
return p->Encode(node, fmt);
158160
}
159161

160162
JNIEXPORT void JNICALL Java_org_bblfsh_client_v2_Context_dispose(JNIEnv *env,
161163
jobject self) {
162-
ContextExt *p = getHandle<ContextExt>(env, self, "nativeContext");
163-
setHandle<ContextExt>(env, self, 0, "nativeContext");
164+
ContextExt *p = getHandle<ContextExt>(env, self, nativeContext);
165+
setHandle<ContextExt>(env, self, 0, nativeContext);
164166
delete p;
165167
}
166168

0 commit comments

Comments
 (0)