import neo4j
import more_collections
import location
+import descriptions
# A Neo4j graph.
class NeoGraph
# Is empty for entities without an ID.
var model_id: String = "" is writable
+ # The full (qualified) name, as presented by the original model.
+ #
+ # Fully independant of `name`. By default, equals to `""` for the root
+ # namespace.
+ var full_name: nullable String = null is writable
+
# Associated documentation.
- var doc = new JsonArray is writable
+ var doc = new Documentation is writable
init do
self.labels.add(graph.project_name)
end
# The short (unqualified) name.
- #
- # May be also set by `full_name=`.
fun name=(name: String) do
self["name"] = name
end
end
# The namespace separator of Nit/C++.
- fun ns_separator: String do return "::"
-
- # The name separator used when calling `full_name=`.
- fun name_separator: String do return ns_separator
-
- # The full (qualified) name.
#
- # Also set `name` using `name_separator`.
- fun full_name=(full_name: String) do
- var m = full_name.search_last(name_separator)
-
- self["full_name"] = full_name
- if m == null then
- name = full_name
- else
- name = full_name.substring_from(m.after)
- end
- end
-
- # The full (qualified) name.
- fun full_name: String do
- var full_name = self["full_name"]
- assert full_name isa String
- return full_name
- end
-
- # Set the full name using the current name and the specified parent name.
- fun parent_name=(parent_name: String) do
- if parent_name.is_empty then
- self["full_name"] = name
- else
- self["full_name"] = parent_name + name_separator + name
- end
- end
+ # Used to join two or more names when we need to work around some
+ # limitations of the Nit model.
+ fun ns_separator: String do return "::"
# Set the location of the entity in the source code.
fun location=(location: nullable Location) do
#
# Called by the loader when it has finished to read the entity.
fun put_in_graph do
- if doc.length > 0 then
+ if not doc.is_empty then
set_mdoc
end
graph.all_nodes.add(self)
abstract class Compound
super Entity
- # Set the declared visibility (the proctection) of the compound.
+ # Set the declared visibility (the protection) of the compound.
fun visibility=(visibility: String) do
self["visibility"] = visibility
end
# Declare an inner namespace.
#
- # Note: Althought Doxygen indicates that the name is optional,
+ # Note: Although Doxygen indicates that the name is optional,
# declarations with an empty name are not supported yet, except for the root
# namespace. For the root namespace, both arguments are empty.
#
# Declare an inner class.
#
- # Note: Althought Doxygen indicates that both arguments are optional,
+ # Note: Although Doxygen indicates that both arguments are optional,
# declarations with an empty ID are not supported yet.
#
# Parameters:
super Compound
# The inner namespaces.
- #
- # Left empty for the root namespace.
var inner_namespaces: SimpleCollection[NamespaceRef] = new Array[NamespaceRef]
init do
self.labels.add("MGroup")
end
- redef fun declare_namespace(id: String, full_name: String) do
+ redef fun declare_namespace(id, full_name) do
inner_namespaces.add new NamespaceRef(id, full_name)
end
- redef fun declare_class(id: String, full_name: String, prot: String) do
+ redef fun declare_class(id, name, prot) do
+ assert not id.is_empty else
+ sys.stderr.write "Inner class declarations without ID are not yet supported.\n"
+ end
graph.class_to_ns[id] = self
end
redef fun put_in_graph do
super
- var full_name = self["full_name"]
+ var full_name = self.full_name
if full_name isa String then graph.namespaces[full_name] = self
end
redef fun put_edges do
super
graph.add_edge(self, "PROJECT", graph.project)
- if self["name"] == self["full_name"] and self["full_name"] != "" then
- # The root namespace does not know its children.
- var root = graph.by_id[""]
- graph.add_edge(self, "PARENT", root)
- graph.add_edge(root, "NESTS", self)
- end
for ns in inner_namespaces do
var node = ns.seek_in(graph)
graph.add_edge(node, "PARENT", self)
init do
super
- self["full_name"] = ""
- self["name"] = graph.project_name
+ full_name = ""
+ name = graph.project_name
end
-
- redef fun declare_namespace(id: String, name: String) do end
end