Merge: doc: fixed some typos and other misc. corrections
[nit.git] / src / frontend / serialization_code_gen_phase.nit
index 253a3a1..1ae78e6 100644 (file)
@@ -53,7 +53,7 @@ private class SerializationPhasePostModel
        do
                var code = new Array[String]
                code.add """
-redef init from_deserializer(v: Deserializer)
+redef init from_deserializer(v)
 do
        super
        v.notify_of_creation self
@@ -110,7 +110,7 @@ do
                        v.errors.add new AttributeMissingError(self, "{{{name}}}")
                end"""
                                else code.add """
-               v.errors.add new Error("Deserialization Error: attribute `{class_name}::{{{name}}}` missing from JSON object")"""
+               v.errors.add new AttributeMissingError(self, "{{{name}}}")"""
 
                                code.add """
        else if not {{{name}}} isa {{{type_name}}} then
@@ -143,7 +143,11 @@ do
                if deserializer_npropdef == null then return
 
                # Collect local types expected to be deserialized
-               var types_to_deserialize = new Set[String]
+               #
+               # Map types' `name` to their `full_name`.
+               #
+               # FIXME use only the full name when there's a `class_full_name`
+               var types_to_deserialize = new Map[String, String]
 
                ## Local serializable standard class without parameters
                for nclassdef in nclassdefs do
@@ -151,7 +155,7 @@ do
                        if mclass == null then continue
 
                        if mclass.arity == 0 and mclass.kind == concrete_kind then
-                               types_to_deserialize.add mclass.name
+                               types_to_deserialize[mclass.name] = mclass.full_name
                        end
                end
 
@@ -188,7 +192,7 @@ do
                                                break
                                        end
 
-                                       if is_serializable then types_to_deserialize.add mtype.to_s
+                                       if is_serializable then types_to_deserialize[mtype.name] = mtype.full_name
                                end
                        end
                end
@@ -198,8 +202,15 @@ do
                code.add "redef fun deserialize_class_intern(name)"
                code.add "do"
 
-               for name in types_to_deserialize do
-                       code.add "      if name == \"{name}\" then return new {name}.from_deserializer(self)"
+               for name, full_name in types_to_deserialize do
+
+                       if full_name.has('-') then
+                               # Invalid module name, it is either artificial or a script
+                               # without module declaration (like those generated by nitunit)
+                               full_name = name
+                       end
+
+                       code.add "      if name == \"{name}\" then return new {full_name}.from_deserializer(self)"
                end
 
                code.add "      return super"