diff --git a/.gitignore b/.gitignore index 0d57d1d..a7bf554 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ target *~ .idea src/libuast-native +src/main/proto +!src/main/proto/github.com/gogo/protobuf/gogoproto/gogo.proto +src/main/resources .history Libuast.so build/* diff --git a/README.md b/README.md index 38d1b86..415c6b7 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ guide to learn more about how to use and deploy a bblfsh server, install languag API ```scala import scala.io.Source -import org.bblfsh.client.BblfshClient +import org.bblfsh.client.v2.BblfshClient, BblfshClient._ import gopkg.in.bblfsh.sdk.v2.protocol.driver.Mode val client = BblfshClient("localhost", 9432) @@ -93,7 +93,7 @@ val resp = client.parse(filename, fileContent, Mode.SEMANTIC) println(resp.get) // Filtered response -println(client.filter(resp.get, "//uast:Import")) +println(client.filter(resp.get, "//uast:Identifier")) ``` Command line: @@ -105,7 +105,7 @@ java -jar build/bblfsh-client-assembly-*.jar -f or if you want to use a XPath query: ``` -java -jar build/bblfsh-client-assembly-*.jar -f -q "//uast:Import" +java -jar build/bblfsh-client-assembly-*.jar -f -q "//uast:Identifier" ``` Please read the [Babelfish clients](https://doc.bblf.sh/user/language-clients.html) diff --git a/src/main/scala/org/bblfsh/client/v2/BblfshClient.scala b/src/main/scala/org/bblfsh/client/v2/BblfshClient.scala index cf48e90..b8061c1 100644 --- a/src/main/scala/org/bblfsh/client/v2/BblfshClient.scala +++ b/src/main/scala/org/bblfsh/client/v2/BblfshClient.scala @@ -161,6 +161,14 @@ object BblfshClient { } } + /** Enables API: client.filter and client.iterator for client an instance of BblfshClient */ + implicit class BblfshClientMethods(val client: BblfshClient) { + def filter(node: NodeExt, query: String) = BblfshClient.filter(node, query) + def filter(node: JNode, query: String) = BblfshClient.filter(node, query) + def iterator(node: NodeExt, treeOrder: Int) = BblfshClient.iterator(node, treeOrder) + def iterator(node: JNode, treeOrder: Int) = BblfshClient.iterator(node, treeOrder) + } + /** Factory method for iterator over an external/native node */ def iterator(node: NodeExt, treeOrder: Int): Libuast.UastIterExt = { Libuast.UastIterExt(node, treeOrder)