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

Commit

Permalink
v2: add .encode()
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Bezzubov <bzz@apache.org>
  • Loading branch information
bzz committed Jun 6, 2019
1 parent 413c430 commit e2718c7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
- ./sbt "testOnly org.bblfsh.client.v2.BblfshClientParseTest -- -z \"Parsed UAST for .java file\""
- ./sbt "testOnly org.bblfsh.client.v2.BblfshClientParseTest -- -z \"Decoded UAST after parsing\""
- ./sbt "testOnly org.bblfsh.client.v2.BblfshClientParseTest -- -z \"Decoded UAST RootNode\""
- ./sbt "testOnly org.bblfsh.client.v2.BblfshClientParseTest -- -z \"Encoding back the RootNode of decoded UAST\""

after_failure: *failure_logs_anchor

Expand Down
4 changes: 2 additions & 2 deletions src/main/native/org_bblfsh_client_v2_Context.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/main/native/org_bblfsh_client_v2_libuast_Libuast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ContextExt {
return toJ(root);
}

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

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

ContextExt *p = getHandle<ContextExt>(env, self, "nativeContext");
return p->Encode(node, fmt);
return nullptr;
}

JNIEXPORT void JNICALL Java_org_bblfsh_client_v2_Context_dispose(JNIEnv *env,
jobject self) {
ContextExt *p = getHandle<ContextExt>(env, self, "nativeContext");
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/bblfsh/client/v2/Context.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.nio.ByteBuffer

case class Context(nativeContext: Long) {
@native def root(): Node
@native def encode(n: Node, format: Int): ByteBuffer
@native def encode(n: Node): ByteBuffer
@native def dispose()

@native def filter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class BblfshClientParseTest extends FlatSpec
}

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

val encodedBytes: ByteBuffer = uast.encode(rootNode, 0)
val encodedBytes: ByteBuffer = uastCtx.encode(rootNode)

encodedBytes.capacity should be (resp.uast.asReadOnlyByteBuffer.capacity)
encodedBytes shouldEqual resp.uast.asReadOnlyByteBuffer
Expand Down

0 comments on commit e2718c7

Please sign in to comment.