src/model: generalize visibility to all MEntities
[nit.git] / src / model / model.nit
index 00f8052..d4ca515 100644 (file)
@@ -30,6 +30,15 @@ import mdoc
 import ordered_tree
 private import more_collections
 
+redef class MEntity
+       # The visibility of the MEntity.
+       #
+       # MPackages, MGroups and MModules are always public.
+       # The visibility of `MClass` and `MProperty` is defined by the keyword used.
+       # `MClassDef` and `MPropDef` return the visibility of `MClass` and `MProperty`.
+       fun visibility: MVisibility do return public_visibility
+end
+
 redef class Model
        # All known classes
        var mclasses = new Array[MClass]
@@ -465,7 +474,7 @@ class MClass
 
        # The visibility of the class
        # In Nit, the visibility of a class cannot evolve in refinements
-       var visibility: MVisibility
+       redef var visibility
 
        init
        do
@@ -593,6 +602,8 @@ class MClassDef
 
        redef var location: Location
 
+       redef fun visibility do return mclass.visibility
+
        # Internal name combining the module and the class
        # Example: "mymodule$MyClass"
        redef var to_s is noinit
@@ -1167,6 +1178,8 @@ class MClassType
 
        redef fun model do return self.mclass.intro_mmodule.model
 
+       redef fun location do return mclass.location
+
        # TODO: private init because strongly bounded to its mclass. see `mclass.mclass_type`
 
        # The formal arguments of the type
@@ -1372,6 +1385,8 @@ class MVirtualType
        # Its the definitions of this property that determine the bound or the virtual type.
        var mproperty: MVirtualTypeProp
 
+       redef fun location do return mproperty.location
+
        redef fun model do return self.mproperty.intro_mclassdef.mmodule.model
 
        redef fun lookup_bound(mmodule: MModule, resolved_receiver: MType): MType
@@ -1502,6 +1517,8 @@ class MParameterType
 
        redef fun model do return self.mclass.intro_mmodule.model
 
+       redef fun location do return mclass.location
+
        # The position of the parameter (0 for the first parameter)
        # FIXME: is `position` a better name?
        var rank: Int
@@ -1627,6 +1644,8 @@ abstract class MProxyType
        # The base type
        var mtype: MType
 
+       redef fun location do return mtype.location
+
        redef fun model do return self.mtype.model
        redef fun need_anchor do return mtype.need_anchor
        redef fun as_nullable do return mtype.as_nullable
@@ -1980,7 +1999,7 @@ abstract class MProperty
        end
 
        # The visibility of the property
-       var visibility: MVisibility
+       redef var visibility
 
        # Is the property usable as an initializer?
        var is_autoinit = false is writable
@@ -2247,6 +2266,8 @@ abstract class MPropDef
 
        redef var location: Location
 
+       redef fun visibility do return mproperty.visibility
+
        init
        do
                mclassdef.mpropdefs.add(self)