+ redef fun core_serialize_to(v) do
+ v.serialize_attribute("html_synopsis", html_synopsis.write_to_string)
+ v.serialize_attribute("html_documentation", html_documentation.write_to_string)
+ end
+end
+
+redef class MPackage
+ redef fun namespace do return new Namespace.from([to_ns_ref])
+end
+
+redef class MGroup
+ redef fun namespace do
+ var p = parent
+ if p == null then
+ return new Namespace.from([to_ns_ref, ">": nullable NSEntity])
+ end
+ return new Namespace.from([p.namespace, to_ns_ref, ">": nullable NSEntity])
+ end
+end
+
+redef class MModule
+ redef fun namespace do
+ var mgroup = self.mgroup
+ if mgroup == null then
+ return new Namespace.from([to_ns_ref])
+ end
+ return new Namespace.from([mgroup.mpackage.to_ns_ref, "::", to_ns_ref: nullable NSEntity])
+ end
+
+ private fun ns_for(visibility: MVisibility): nullable Namespace do
+ if visibility <= private_visibility then return namespace
+ var mgroup = self.mgroup
+ if mgroup == null then return namespace
+ return mgroup.mpackage.namespace
+ end
+end
+
+redef class MClass
+ redef fun namespace do
+ return new Namespace.from([intro_mmodule.ns_for(visibility), "::", to_ns_ref: nullable NSEntity])
+ end
+end
+
+redef class MClassDef
+ redef fun namespace do
+ if is_intro then
+ return new Namespace.from([mmodule.ns_for(mclass.visibility), "$", to_ns_ref: nullable NSEntity])
+ else if mclass.intro_mmodule.mpackage != mmodule.mpackage then
+ return new Namespace.from([mmodule.namespace, "$", mclass.namespace: nullable NSEntity])
+ else if mclass.visibility > private_visibility then
+ return new Namespace.from([mmodule.namespace, "$", mclass.to_ns_ref: nullable NSEntity])
+ end
+ return new Namespace.from([mmodule.full_name, "$::", mclass.intro_mmodule.to_ns_ref: nullable NSEntity])
+ end
+end
+
+redef class MProperty
+ redef fun namespace do
+ if intro_mclassdef.is_intro then
+ return new Namespace.from([intro_mclassdef.mmodule.ns_for(visibility), "::", intro_mclassdef.mclass.to_ns_ref, "::", to_ns_ref: nullable NSEntity])
+ else
+ return new Namespace.from([intro_mclassdef.mmodule.namespace, "::", intro_mclassdef.mclass.to_ns_ref, "::", to_ns_ref: nullable NSEntity])
+ end
+ end
+end
+
+redef class MPropDef
+ redef fun namespace do
+ var res = new Namespace
+ res.add mclassdef.namespace
+ res.add "$"
+
+ if mclassdef.mclass == mproperty.intro_mclassdef.mclass then
+ res.add to_ns_ref
+ else
+ if mclassdef.mmodule.mpackage != mproperty.intro_mclassdef.mmodule.mpackage then
+ res.add mproperty.intro_mclassdef.mmodule.ns_for(mproperty.visibility)
+ res.add "::"
+ else if mproperty.visibility <= private_visibility then
+ if mclassdef.mmodule.namespace_for(mclassdef.mclass.visibility) != mproperty.intro_mclassdef.mmodule.mpackage then
+ res.add "::"
+ res.add mproperty.intro_mclassdef.mmodule.to_ns_ref
+ res.add "::"
+ end
+ end
+ if mclassdef.mclass != mproperty.intro_mclassdef.mclass then
+ res.add mproperty.intro_mclassdef.to_ns_ref
+ res.add "::"
+ end
+ res.add to_ns_ref
+ end
+ return res