ci: do not error when nothing with nitunit_some
[nit.git] / contrib / neo_doxygen / src / model / graph.nit
index 18f91c4..9df491a 100644 (file)
@@ -18,6 +18,7 @@ module model::graph
 import neo4j
 import more_collections
 import location
+import descriptions
 
 # A Neo4j graph.
 class NeoGraph
@@ -128,8 +129,14 @@ abstract class Entity
        # 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)
@@ -137,8 +144,6 @@ abstract class Entity
        end
 
        # The short (unqualified) name.
-       #
-       # May be also set by `full_name=`.
        fun name=(name: String) do
                self["name"] = name
        end
@@ -156,56 +161,26 @@ abstract class Entity
        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
+       fun location=(location: nullable neo_doxygen::Location) do
                self["location"] = location
        end
 
        # Get the location of the entity in the source code.
-       fun location: nullable Location do
-               return self["location"].as(nullable Location)
+       fun location: nullable neo_doxygen::Location do
+               return self["location"].as(nullable neo_doxygen::Location)
        end
 
        # Put the entity in the graph.
        #
        # 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)
@@ -227,12 +202,12 @@ abstract class CodeBlock
        super Entity
 
        init do
-               self["location"] = new Location
+               self["location"] = new neo_doxygen::Location
        end
 
-       redef fun location=(location: nullable Location) do
+       redef fun location=(location) do
                if location == null then
-                       super(new Location)
+                       super(new neo_doxygen::Location)
                else
                        super
                end
@@ -246,7 +221,7 @@ end
 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
@@ -258,7 +233,7 @@ abstract class Compound
 
        # 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.
        #
@@ -271,7 +246,7 @@ abstract class Compound
 
        # 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:
@@ -310,8 +285,6 @@ class Namespace
        super Compound
 
        # The inner namespaces.
-       #
-       # Left empty for the root namespace.
        var inner_namespaces: SimpleCollection[NamespaceRef] = new Array[NamespaceRef]
 
        init do
@@ -319,29 +292,26 @@ class Namespace
                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)
@@ -388,9 +358,7 @@ class RootNamespace
 
        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