From: Alexis Laferrière Date: Sun, 2 Feb 2014 04:59:59 +0000 (-0500) Subject: phase/serialization: add utilities to get name and type of attributes X-Git-Tag: v0.6.4~16^2~9 X-Git-Url: http://nitlanguage.org phase/serialization: add utilities to get name and type of attributes Signed-off-by: Alexis Laferrière --- diff --git a/src/serialization_phase.nit b/src/serialization_phase.nit index f129a40..d17a40a 100644 --- a/src/serialization_phase.nit +++ b/src/serialization_phase.nit @@ -54,11 +54,7 @@ private class SerializationPhase code.add " super" for attribute in npropdefs do if attribute isa AAttrPropdef then - var name - if attribute.n_id == null then - name = attribute.n_id2.text - else name = attribute.n_id.text - + var name = attribute.name code.add " v.serialize_attribute(\"{name}\", {name})" end @@ -68,3 +64,23 @@ private class SerializationPhase npropdefs.push(toolcontext.parse_propdef(code.join("\n"))) end end + +redef class AAttrPropdef + private fun name: String + do + if n_id == null then return n_id2.text + return n_id.text + end + + private fun type_name: String + do + var name = n_type.n_id.text + + var types = n_type.n_types + if not types.is_empty then + var params = new Array[String] + for t in types do params.add(t.n_id.text) + return "{name}[{params.join(", ")}]" + else return name + end +end