model: Generalize access to `model` form `MEntitiy`.
authorAlexandre Terrasa <alexandre@moz-code.org>
Mon, 21 Jul 2014 18:29:31 +0000 (14:29 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Mon, 21 Jul 2014 18:29:31 +0000 (14:29 -0400)
Since, MEntity are model things, let the user access to the model from them.

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/model/mmodule.nit
src/model/model.nit
src/model/model_base.nit
src/model/mproject.nit

index 2b7e5af..648eb49 100644 (file)
@@ -72,7 +72,7 @@ class MModule
        super MConcern
 
        # The model considered
-       var model: Model
+       redef var model: Model
 
        # placebo for old module nesting hierarchy
        # return null if self is not nested (ie. is a top-level module)
index 0179592..8d9c915 100644 (file)
@@ -380,6 +380,8 @@ class MClass
                end
        end
 
+       redef fun model do return intro_mmodule.model
+
        # All class definitions (introduction and refinements)
        var mclassdefs: Array[MClassDef] = new Array[MClassDef]
 
@@ -496,6 +498,8 @@ class MClassDef
        # Actually the name of the `mclass`
        redef fun name do return mclass.name
 
+       redef fun model do return mmodule.model
+
        # All declared super-types
        # FIXME: quite ugly but not better idea yet
        var supertypes: Array[MClassType] = new Array[MClassType]
@@ -588,8 +592,6 @@ abstract class MType
        super MEntity
 
        redef fun name do return to_s
-       # The model of the type
-       fun model: Model is abstract
 
        # Return true if `self` is an subtype of `sup`.
        # The typing is done using the standard typing policy of Nit.
@@ -1530,6 +1532,8 @@ class MParameter
                var res = new MParameter(self.name, newtype, self.is_vararg)
                return res
        end
+
+       redef fun model do return mtype.model
 end
 
 # A service (global property) that generalize method, attribute, etc.
@@ -1590,6 +1594,8 @@ abstract class MProperty
        # associated definition, this method will abort
        fun intro: MPROPDEF do return mpropdefs.first
 
+       redef fun model do return intro.model
+
        # Alias for `name`
        redef fun to_s do return name
 
@@ -1844,6 +1850,8 @@ abstract class MPropDef
        # Actually the name of the `mproperty`
        redef fun name do return mproperty.name
 
+       redef fun model do return mclassdef.model
+
        # Internal name combining the module, the class and the property
        # Example: "mymodule#MyClass#mymethod"
        redef var to_s: String
index 666ce8e..ef17543 100644 (file)
@@ -27,6 +27,9 @@ end
 abstract class MEntity
        # The short (unqualified) name of this model entity
        fun name: String is abstract
+
+       # A Model Entity has a direct link to its model
+       fun model: Model is abstract
 end
 
 # Something that represents a concern
index 7bd502e..0b8010e 100644 (file)
@@ -27,7 +27,7 @@ class MProject
        redef var name: String
 
        # The model of the project
-       var model: Model
+       redef var model: Model
 
        # The root of the group tree
        var root: nullable MGroup writable = null
@@ -95,6 +95,8 @@ class MGroup
                end
        end
 
+       redef fun model do return mproject.model
+
        redef fun parent_concern do
                if not is_root then return parent
                return mproject