neo_doxygen: Import type parameters
authorJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Thu, 30 Oct 2014 20:37:46 +0000 (16:37 -0400)
committerJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Tue, 4 Nov 2014 17:16:09 +0000 (12:16 -0500)
Not tested yet.

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

contrib/neo_doxygen/src/doxml/compounddef.nit
contrib/neo_doxygen/src/doxml/entitydef.nit
contrib/neo_doxygen/src/model/class_compound.nit

index 10f289f..4cd42ca 100644 (file)
@@ -24,6 +24,7 @@ class CompoundDefListener
 
        var compound: Compound is writable, noinit
        private var memberdef: MemberDefListener is noinit
+       private var param_listener: TypeParamListener is noinit
 
        # Default attributes for members in the current section.
        private var member_defaults: MemberDefaults is noinit
@@ -44,6 +45,7 @@ class CompoundDefListener
                var defaults = new MemberDefaults("public", false, false)
 
                memberdef = new MemberDefListener(reader, self)
+               param_listener = new TypeParamListener(reader, self)
 
                member_defaults = defaults
                section_kinds = new DefaultMap[String, MemberDefaults](defaults)
@@ -107,7 +109,9 @@ class CompoundDefListener
                        if member_defaults.is_special then
                                super # TODO
                        end
-               else
+               else if "param" == local_name then
+                       param_listener.listen_until(dox_uri, local_name)
+               else if "templateparamlist" != local_name then
                        super
                end
        end
@@ -125,6 +129,8 @@ class CompoundDefListener
                        end
                else if local_name == "basecompoundref" then
                        compound.declare_super(refid, text.to_s, prot, virt)
+               else if "param" == local_name and compound isa ClassCompound then
+                       compound.as(ClassCompound).add_type_parameter(param_listener.parameter)
                else
                        super
                end
index 9bad28a..6c11a6c 100644 (file)
@@ -120,3 +120,10 @@ abstract class ParamListener[T: Parameter]
                end
        end
 end
+
+# Processes the content of a `<param>` element in a `<templateparamlist>` element.
+class TypeParamListener
+       super ParamListener[TypeParameter]
+
+       redef fun create_parameter do return new TypeParameter(graph)
+end
index 986695e..7663c0a 100644 (file)
@@ -80,6 +80,11 @@ class ClassCompound
                class_def.declare_member(member)
        end
 
+       # Append the specified type parameter.
+       fun add_type_parameter(parameter: TypeParameter) do
+               class_type.arguments.add(parameter)
+       end
+
        redef fun put_in_graph do
                super
                class_type.put_in_graph
@@ -176,6 +181,7 @@ class ClassType
        # You may use this attribute or `class_compound` to specify the class.
        var class_compound_id: String = "" is writable
 
+       # The type arguments or the type parameters.
        var arguments = new Array[TypeEntity]
 
        init do
@@ -184,7 +190,7 @@ class ClassType
        end
 
        # Return the number of arguments.
-       fun arity: Int do return 0 # TODO
+       fun arity: Int do return arguments.length
 
        fun is_generic: Bool do return arity > 0