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

Commit e2718c7

Browse files
committed
v2: add .encode()
Signed-off-by: Alexander Bezzubov <[email protected]>
1 parent 413c430 commit e2718c7

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
- ./sbt "testOnly org.bblfsh.client.v2.BblfshClientParseTest -- -z \"Parsed UAST for .java file\""
4444
- ./sbt "testOnly org.bblfsh.client.v2.BblfshClientParseTest -- -z \"Decoded UAST after parsing\""
4545
- ./sbt "testOnly org.bblfsh.client.v2.BblfshClientParseTest -- -z \"Decoded UAST RootNode\""
46+
- ./sbt "testOnly org.bblfsh.client.v2.BblfshClientParseTest -- -z \"Encoding back the RootNode of decoded UAST\""
4647

4748
after_failure: *failure_logs_anchor
4849

src/main/native/org_bblfsh_client_v2_Context.h

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/native/org_bblfsh_client_v2_libuast_Libuast.cc

+10-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ContextExt {
9393
return toJ(root);
9494
}
9595

96-
// Encode serializes existing-on-guest-side UAST.
96+
// Encode serializes external UAST.
9797
// Borrows the reference.
9898
jobject Encode(jobject node, UastFormat format) {
9999
NodeHandle h = toHandle(node);
@@ -149,6 +149,15 @@ JNIEXPORT jobject JNICALL Java_org_bblfsh_client_v2_Context_root(JNIEnv *env,
149149
return p->RootNode();
150150
}
151151

152+
JNIEXPORT jobject JNICALL Java_org_bblfsh_client_v2_Context_encode(
153+
JNIEnv *env, jobject self, jobject node) {
154+
UastFormat fmt = UAST_BINARY; // TODO(bzz): make it argument & enum
155+
156+
ContextExt *p = getHandle<ContextExt>(env, self, "nativeContext");
157+
return p->Encode(node, fmt);
158+
return nullptr;
159+
}
160+
152161
JNIEXPORT void JNICALL Java_org_bblfsh_client_v2_Context_dispose(JNIEnv *env,
153162
jobject self) {
154163
ContextExt *p = getHandle<ContextExt>(env, self, "nativeContext");

src/main/scala/org/bblfsh/client/v2/Context.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import java.nio.ByteBuffer
44

55
case class Context(nativeContext: Long) {
66
@native def root(): Node
7-
@native def encode(n: Node, format: Int): ByteBuffer
7+
@native def encode(n: Node): ByteBuffer
88
@native def dispose()
99

1010
@native def filter()

src/test/scala/org/bblfsh/client/v2/BblfshClientParseTest.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ class BblfshClientParseTest extends FlatSpec
5555
}
5656

5757
"Encoding back the RootNode of decoded UAST" should "produce same bytes" in {
58-
val uast = resp.uast.decode()
59-
val rootNode: Node = uast.root()
58+
val uastCtx: Context = resp.uast.decode()
59+
val rootNode: Node = uastCtx.root()
6060
println(s"Root node: $rootNode")
6161

62-
val encodedBytes: ByteBuffer = uast.encode(rootNode, 0)
62+
val encodedBytes: ByteBuffer = uastCtx.encode(rootNode)
6363

6464
encodedBytes.capacity should be (resp.uast.asReadOnlyByteBuffer.capacity)
6565
encodedBytes shouldEqual resp.uast.asReadOnlyByteBuffer

0 commit comments

Comments
 (0)