From: Jean Privat Date: Mon, 19 Jun 2017 20:23:39 +0000 (-0400) Subject: Merge: frontend: introduce `parse_annotations` phase X-Git-Url: http://nitlanguage.org?hp=06515268c8ad2da8d1aef9906c5380705e670612 Merge: frontend: introduce `parse_annotations` phase A simple annotations access framework. Useful when you only need to know if a module, class or property definition contains an annotation in its source code and you don't have a modelbuilder. One the phase is applied one can access the annotations through the related MEntity: ~~~nit fun is_annotated_with_foo(mentity: AnnotatedMEntity): Bool do return mentity.has_annotation("foo") end ~~~ I introduced a specific super class to avoid the introduction of `annotations` directly into the MEntity since the concept of annnotations is weird when talking about a MClass or a MType. Signed-off-by: Alexandre Terrasa Pull-Request: #2504 --- diff --git a/lib/neo4j/neo4j.nit b/lib/neo4j/neo4j.nit index 2489f9c..d512462 100644 --- a/lib/neo4j/neo4j.nit +++ b/lib/neo4j/neo4j.nit @@ -463,8 +463,10 @@ class CypherQuery # Return `self`. # # ``` - # var query = (new CypherQuery).nmatch("(n)").nwhere( - # "n.key = key").set("key", "foo") + # var query = (new CypherQuery). + # nmatch("(n)"). + # nwhere("n.key = \{key\}"). + # set("key", "foo") # # assert query.params["key"] == "foo" # ``` diff --git a/tests/test_neo4j.nit b/tests/test_neo4j.nit index 5da93bb..974a80a 100644 --- a/tests/test_neo4j.nit +++ b/tests/test_neo4j.nit @@ -26,7 +26,11 @@ var client = new Neo4jClient("http://localhost:7474") assert client.is_ok # Clear the previous objects, if any -client.cypher(new CypherQuery.from_string("MATCH (n) WHERE n.key = {key} OPTIONAL MATCH n-[r]-() DELETE r, n")) +client.cypher( + new CypherQuery.from_string( + "MATCH (n) WHERE n.key = \{key\} OPTIONAL MATCH n-[r]-() DELETE r, n" + ).set("key", key) +) var andres = new NeoNode andres.labels.add_all(["PERSON", "MALE"]) @@ -123,8 +127,9 @@ print "{res5["name"].to_s} IS LOVED BY {res5.in_nodes("LOVES").first["name"].to_ var query = (new CypherQuery). nmatch("(n: MALE)-[r: LOVES]->(m)"). nwhere("n.name = 'Andres'"). - nand("n.key = {key}"). - nreturn("n, r, m") + nand("n.key = \{key\}"). + nreturn("n, r, m"). + set("key", key) var res7 = client.cypher(query) assert res7.as(JsonObject)["data"].as(JsonArray).length == 1 diff --git a/tests/test_neo4j_batch.nit b/tests/test_neo4j_batch.nit index e098357..464eb2f 100644 --- a/tests/test_neo4j_batch.nit +++ b/tests/test_neo4j_batch.nit @@ -41,7 +41,11 @@ var client = new Neo4jClient("http://localhost:7474") assert client.is_ok # Clear the previous objects, if any -client.cypher(new CypherQuery.from_string("MATCH (n) WHERE n.key = {key} OPTIONAL MATCH n-[r]-() DELETE r, n")) +client.cypher( + new CypherQuery.from_string( + "MATCH (n) WHERE n.key = \{key\} OPTIONAL MATCH n-[r]-() DELETE r, n" + ).set("key", key) +) print "# Save batch\n" @@ -96,8 +100,9 @@ print "{res5["name"].to_s} IS LOVED BY {res5.in_nodes("LOVES").first["name"].to_ var query = (new CypherQuery). nmatch("(n: MALE)-[r: LOVES]->(m)"). nwhere("n.name = 'Andres'"). - nand("n.key = {key}"). - nreturn("n, r, m") + nand("n.key = \{key\}"). + nreturn("n, r, m"). + set("key", key) var res7 = client.cypher(query) assert res7.as(JsonObject)["data"].as(JsonArray).length == 1