model: add `full_name` to entities that miss one
authorJean Privat <jean@pryen.org>
Tue, 16 Dec 2014 04:08:18 +0000 (23:08 -0500)
committerJean Privat <jean@pryen.org>
Wed, 17 Dec 2014 04:52:46 +0000 (23:52 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/model/model.nit

index f84b38f..6309385 100644 (file)
@@ -527,6 +527,21 @@ class MClassDef
        # Actually the name of the `mclass`
        redef fun name do return mclass.name
 
+       # The module and class name separated by a '#'.
+       #
+       # The short-name of the class is used for introduction.
+       # Example: "my_module#MyClass"
+       #
+       # The full-name of the class is used for refinement.
+       # Example: "my_module#intro_module::MyClass"
+       redef var full_name is lazy do
+               if is_intro then
+                       return "{mmodule.full_name}#{mclass.name}"
+               else
+                       return "{mmodule.full_name}#{mclass.full_name}"
+               end
+       end
+
        redef fun model do return mmodule.model
 
        # All declared super-types
@@ -1034,6 +1049,8 @@ class MClassType
 
        redef fun to_s do return mclass.to_s
 
+       redef fun full_name do return mclass.full_name
+
        redef fun need_anchor do return false
 
        redef fun anchor_to(mmodule: MModule, anchor: MClassType): MClassType
@@ -1142,10 +1159,20 @@ class MGenericType
                self.to_s = "{mclass}[{arguments.join(", ")}]"
        end
 
-       # Recursively print the type of the arguments within brackets.
+       # The short-name of the class, then the full-name of each type arguments within brackets.
        # Example: `"Map[String, List[Int]]"`
        redef var to_s: String is noinit
 
+       # The full-name of the class, then the full-name of each type arguments within brackets.
+       # Example: `"standard::Map[standard::String, standard::List[standard::Int]]"`
+       redef var full_name is lazy do
+               var args = new Array[String]
+               for t in arguments do
+                       args.add t.full_name
+               end
+               return "{mclass.full_name}[{args.join(", ")}]}"
+       end
+
        redef var need_anchor: Bool is noinit
 
        redef fun resolve_for(mtype, anchor, mmodule, cleanup_virtual)
@@ -1286,6 +1313,8 @@ class MVirtualType
        end
 
        redef fun to_s do return self.mproperty.to_s
+
+       redef fun full_name do return self.mproperty.full_name
 end
 
 # The type associated to a formal parameter generic type of a class
@@ -1330,6 +1359,8 @@ class MParameterType
 
        redef fun to_s do return name
 
+       redef var full_name is lazy do return "{mclass.full_name}::{name}"
+
        redef fun lookup_bound(mmodule: MModule, resolved_receiver: MType): MType
        do
                assert not resolved_receiver.need_anchor
@@ -1449,6 +1480,8 @@ class MNullableType
 
        redef var to_s: String is noinit
 
+       redef var full_name is lazy do return "nullable {mtype.full_name}"
+
        redef fun need_anchor do return mtype.need_anchor
        redef fun as_nullable do return self
        redef fun as_notnullable do return mtype
@@ -1501,6 +1534,7 @@ class MNullType
        super MType
        redef var model: Model
        redef fun to_s do return "null"
+       redef fun full_name do return "null"
        redef fun as_nullable do return self
        redef fun need_anchor do return false
        redef fun resolve_for(mtype, anchor, mmodule, cleanup_virtual) do return self
@@ -1943,6 +1977,39 @@ abstract class MPropDef
        # Actually the name of the `mproperty`
        redef fun name do return mproperty.name
 
+       # The full-name of mpropdefs combine the information about the `classdef` and the `mproperty`.
+       #
+       # Therefore the combination of identifiers is awful,
+       # the worst case being
+       #
+       # ~~~nitish
+       # "{mclassdef.mmodule.full_name}#{mclassdef.mclass.intro_mmodule.full_name}::{mclassdef.name}#{mproperty.intro_mclassdef.mmodule.full_name}::{mproperty.intro_mclassdef.name}::{name}"
+       # ~~~
+       #
+       # Fortunately, the full-name is simplified when entities are repeated.
+       # The simplest form is "my_module#MyClass#my_property".
+       redef var full_name is lazy do
+               var res = new FlatBuffer
+               res.append mclassdef.mmodule.full_name
+               res.append "#"
+               if not mclassdef.is_intro then
+                       res.append mclassdef.mclass.intro_mmodule.full_name
+                       res.append "::"
+               end
+               res.append mclassdef.name
+               res.append "#"
+               if mproperty.intro_mclassdef.mmodule != mclassdef.mmodule then
+                       res.append mproperty.intro_mclassdef.mmodule.full_name
+                       res.append "::"
+               end
+               if mclassdef.mclass != mproperty.intro_mclassdef.mclass then
+                       res.append mproperty.intro_mclassdef.mclass.name
+                       res.append "::"
+               end
+               res.append name
+               return res.to_s
+       end
+
        redef fun model do return mclassdef.model
 
        # Internal name combining the module, the class and the property