Merge: proposal for model: Generalize access to `model` form `MEntitiy`.
authorJean Privat <jean@pryen.org>
Tue, 22 Jul 2014 02:57:05 +0000 (22:57 -0400)
committerJean Privat <jean@pryen.org>
Tue, 22 Jul 2014 02:57:05 +0000 (22:57 -0400)
Since, MEntity are model things, let the user access to the model from them.

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

Pull-Request: #598
Reviewed-by: Jean Privat <jean@pryen.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 be29e6f..7568e9b 100644 (file)
@@ -387,6 +387,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]
 
@@ -510,6 +512,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]
@@ -601,8 +605,7 @@ end
 abstract class MType
        super MEntity
 
-       # The model of the type
-       fun model: Model is abstract
+       redef fun name do return to_s
 
        # Return true if `self` is an subtype of `sup`.
        # The typing is done using the standard typing policy of Nit.
@@ -1508,8 +1511,10 @@ end
 
 # A parameter in a signature
 class MParameter
+       super MEntity
+
        # The name of the parameter
-       var name: String
+       redef var name: String
 
        # The static type of the parameter
        var mtype: MType
@@ -1517,6 +1522,12 @@ class MParameter
        # Is the parameter a vararg?
        var is_vararg: Bool
 
+       init(name: String, mtype: MType, is_vararg: Bool) do
+               self.name = name
+               self.mtype = mtype
+               self.is_vararg = is_vararg
+       end
+
        redef fun to_s
        do
                if is_vararg then
@@ -1533,6 +1544,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.
@@ -1593,6 +1606,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
 
@@ -1847,6 +1862,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