neo_doxygen: Import members’ type.
authorJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Sun, 2 Nov 2014 21:02:58 +0000 (16:02 -0500)
committerJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Tue, 4 Nov 2014 17:16:08 +0000 (12:16 -0500)
Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

contrib/neo_doxygen/src/doxml/listener.nit
contrib/neo_doxygen/src/doxml/memberdef.nit
contrib/neo_doxygen/src/model/linked_text.nit [new file with mode: 0644]
contrib/neo_doxygen/src/model/model.nit
contrib/neo_doxygen/src/model/type_entity.nit

index 3c4dfa8..ccdd8f5 100644 (file)
@@ -220,3 +220,53 @@ class TextListener
 
        redef fun to_s do return buffer.to_s
 end
+
+# Processes a content of type `linkedTextType`.
+abstract class LinkedTextListener[T: LinkedText]
+       super TextListener
+
+       # The read text.
+       var linked_text: T is noinit
+
+       private var refid = ""
+
+       # Create a new instance of `T`.
+       protected fun create_linked_text: T is abstract
+
+       redef fun listen_until(uri: String, local_name: String) do
+               linked_text = create_linked_text
+               refid = ""
+               super
+       end
+
+       redef fun start_dox_element(local_name: String, atts: Attributes) do
+               super
+               push_part
+               if "ref" == local_name then refid = get_required(atts, "refid")
+       end
+
+       redef fun end_dox_element(local_name: String) do
+               super
+               push_part
+               if "ref" == local_name then refid = ""
+       end
+
+       private fun push_part do
+               var s = flush_buffer
+
+               if not s.is_empty then
+                       linked_text.add_part(s, refid)
+               end
+       end
+
+       redef fun to_s do return linked_text.to_s
+end
+
+# Processes the content of a `<type>` element.
+class TypeListener
+       super LinkedTextListener[RawType]
+
+       private var raw_type: RawType is noinit
+
+       redef fun create_linked_text do return new RawType(graph)
+end
index 57d95b9..dec4264 100644 (file)
@@ -23,9 +23,11 @@ class MemberDefListener
 
        # The current member.
        var member: Member is writable, noinit
+       private var type_listener: TypeListener is noinit
 
        init do
                super
+               type_listener = new TypeListener(reader, self)
        end
 
        redef fun entity do return member
@@ -36,8 +38,7 @@ class MemberDefListener
                else if "reimplements" == local_name then
                        member.reimplement(get_required(atts, "refid"))
                else if "type" == local_name then
-                       text.listen_until(dox_uri, local_name)
-                       # TODO links
+                       type_listener.listen_until(dox_uri, local_name)
                else
                        super
                end
@@ -49,7 +50,7 @@ class MemberDefListener
                else if "name" == local_name then
                        member.name = text.to_s
                else if "type" == local_name then
-                       # TODO
+                       member.static_type = type_listener.linked_text
                else
                        super
                end
diff --git a/contrib/neo_doxygen/src/model/linked_text.nit b/contrib/neo_doxygen/src/model/linked_text.nit
new file mode 100644 (file)
index 0000000..e35adde
--- /dev/null
@@ -0,0 +1,152 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# A text with links.
+module model::linked_text
+
+import graph
+
+# A text with links.
+abstract class LinkedText
+       super Entity
+
+       # All link in the text.
+       #
+       # Do not edit directly.
+       var links: Sequence[nullable Link] = new Array[nullable Link]
+
+       # Remove all the parts.
+       fun clear_parts do
+               self["text"] = null
+               links.clear
+       end
+
+       # Remove the first part.
+       fun shift_part do
+               var text = self["text"]
+               assert text isa JsonArray
+               text.shift
+               links.shift
+               if text.is_empty then
+                       self["text"] = null
+               end
+       end
+
+       # Remove the last part.
+       fun pop_part do
+               var text = self["text"]
+               assert text isa JsonArray
+               text.pop
+               links.pop
+               if text.is_empty then
+                       self["text"] = null
+               end
+       end
+
+       # Remove the part at the specified index.
+       fun remove_part_at(index: Int) do
+               var text = self["text"]
+               assert text isa JsonArray
+               text.remove_at(index)
+               links.remove_at(index)
+               if text.is_empty then
+                       self["text"] = null
+               end
+       end
+
+       # Change a part of text.
+       #
+       # Parameters:
+       #
+       # * `index` : the index of the part.
+       # * `content` : textual content.
+       # * `refid` : `model_id` of the linked entity or `""`.
+       fun set_part(index: Int, content: String, refid: String) do
+               var text = self["text"]
+               assert text isa JsonArray
+               text[index] = content
+               if not refid.is_empty then
+                       links[index] = create_link(links.length, refid)
+               else
+                       links[index] = null
+               end
+       end
+
+       # Append a part of text.
+       #
+       # Parameters:
+       #
+       # * `content` : textual content.
+       # * `refid` : `model_id` of the linked entity or `""`.
+       fun add_part(content: String, refid: String) do
+               var text = self["text"]
+
+               if text == null then
+                       text = new JsonArray
+                       self["text"] = text
+               end
+               assert text isa JsonArray
+               text.add(content)
+               if not refid.is_empty then
+                       links.add(create_link(links.length, refid))
+               else
+                       links.add(null)
+               end
+       end
+
+       # Create a link to the specified entity.
+       protected fun create_link(rank:Int, refid: String): Link is abstract
+
+       redef fun to_s do
+               var text = self["text"]
+
+               if text isa JsonArray then
+                       return text.join("")
+               else
+                       return "UNDEFINED"
+               end
+       end
+
+       redef fun put_in_graph do
+               super
+               for link in links do
+                       if link isa Link then
+                               link.put_in_graph
+                       end
+               end
+       end
+
+       redef fun put_edges do
+               super
+               for i in [0..links.length[ do
+                       var link = links[i]
+                       if link isa Link then
+                               link["rank"] = i
+                               graph.add_edge(self, "LINK", link)
+                       end
+               end
+       end
+end
+
+# A link.
+abstract class Link
+       super Entity
+
+       # * `refid` : `model_id` of the linked entity.
+       var refid: String
+
+       redef fun put_edges do
+               graph.add_edge(self, "TARGET", graph.by_id[refid])
+       end
+end
index 6cc6dc7..d3c2af9 100644 (file)
@@ -16,6 +16,7 @@
 module model
 
 import location
+import linked_text
 import graph
 import class_compound
 import module_compound
index e1a6af5..d8ea8c0 100644 (file)
@@ -16,6 +16,7 @@
 module model::type_entity
 
 import graph
+import linked_text
 
 # Base class of all types and signatures.
 abstract class TypeEntity
@@ -40,6 +41,31 @@ class TypeParameter
        end
 end
 
+
+# A type described by a text.
+class RawType
+       super TypeEntity
+       super LinkedText
+
+       init do
+               super
+               self.labels.add("MRawType")
+       end
+
+       redef fun create_link(rank, refid) do return new TypeLink(graph, refid)
+end
+
+# A link in a `RawType`.
+class TypeLink
+       super Link
+
+       init do
+               super
+               self.labels.add("MTypePart")
+       end
+end
+
+
 # A signature of a method.
 class Signature
        super TypeEntity