metamodel: promote _filename to MMModule
[nit.git] / src / metamodel / abstractmetamodel.nit
index 4e3dbff..2c7123a 100644 (file)
@@ -126,6 +126,9 @@ class MMModule
        # The directory of the module
        readable attr _directory: MMDirectory
 
+       # The filename of the module
+       readable attr _filename: String
+
        # Module dependence hierarchy element
        readable attr _mhe: PartialOrderElement[MMModule] 
 
@@ -156,7 +159,7 @@ class MMModule
        # Dictionary of global classes
        attr _global_class_by_name: Map[Symbol, MMGlobalClass] = new HashMap[Symbol, MMGlobalClass]
 
-       protected init(name: Symbol, dir: MMDirectory, context: MMContext)
+       protected init(name: Symbol, dir: MMDirectory, context: MMContext, filename: String)
        do
                _name = name
                _directory = dir
@@ -167,6 +170,7 @@ class MMModule
                else
                        _full_name = dir.full_name_for(name)
                end
+               _filename = filename
        end
 
        # Register that a module is imported with a visibility
@@ -217,18 +221,7 @@ class MMModule
        do
                assert _local_class_by_global != null
                assert c != null
-               if _local_class_by_global.has_key(c) then
-                       return _local_class_by_global[c]
-               else
-                       return null
-               end
-       end
-
-       # Register a local class to the module
-       meth add_local_class(c: MMLocalClass)
-       do
-               c._module = self
-               _local_classes.add(c)
+               return _local_class_by_global[c]
        end
 
        # Get a local class by its name
@@ -247,11 +240,7 @@ class MMModule
        # Return null if not class match this name
        meth global_class_named(n: Symbol): MMGlobalClass
        do
-               if _global_class_by_name.has_key(n) then
-                       return _global_class_by_name[n]
-               else
-                       return null
-               end
+               return _global_class_by_name[n]
        end
 
        redef meth to_s do return name.to_s
@@ -383,10 +372,12 @@ class MMLocalClass
        readable attr _properties_by_name: Map[Symbol, Array[MMGlobalProperty]]
 
        # Create a new class with a given name and arity
-       protected init(name: Symbol, arity: Int)
+       protected init(mod: MMModule, name: Symbol, arity: Int)
        do
+               _module = mod
                _name = name
                _arity = arity
+               mod._local_classes.add(self)
        end
 
        # The corresponding local class in another module
@@ -419,16 +410,15 @@ class MMLocalClass
        # TODO: Will disapear when qualified names will be available
        meth has_global_property_by_name(n: Symbol): Bool
        do
-               return _properties_by_name.has_key(n)
+               return _properties_by_name.has_key(n) and _properties_by_name[n].length == 1
        end
 
        # Get a global property by its name
        # TODO: Will disapear when qualified names will be available
        meth get_property_by_name(n: Symbol): MMGlobalProperty
        do
-               if not has_global_property_by_name(n) then return null
+               if not has_global_property_by_name(n) then abort
                var props = _properties_by_name[n]
-               if props.length > 1 then return null
                return props.first
        end
 
@@ -444,11 +434,7 @@ class MMLocalClass
        meth method(na: Symbol): MMGlobalProperty
        do
                assert _properties_by_name != null
-               if _properties_by_name.has_key(na) then
-                       return _properties_by_name[na].first
-               end
-
-               return null
+               return _properties_by_name[na].first
        end
 
        # Select a method from its name
@@ -457,7 +443,6 @@ class MMLocalClass
        do
                assert name != null
                var gp = method(name)
-               if gp == null then return null
                var res = self[gp]
                assert res isa MMMethod
                return res
@@ -469,7 +454,6 @@ class MMLocalClass
        do
                assert name != null
                var gp = attribute(name)
-               if gp == null then return null
                var res = self[gp]
                assert res isa MMAttribute
                return res
@@ -481,9 +465,7 @@ class MMLocalClass
        do
                var classes = new Array[MMLocalClass]
                for c in cshe.greaters do
-                       var g = c.method(n)
-                       if g == null then continue
-                       classes.add(c)
+                       if c.has_global_property_by_name(n) then classes.add(c)
                end
                classes = cshe.order.select_smallests(classes)
                var res = new Array[MMLocalProperty]
@@ -519,15 +501,16 @@ class MMLocalClass
                register_local_property(prop)
        end
 
+       # Does the global property belong to the class?
+       meth has_global_property(glob: MMGlobalProperty): Bool
+       do
+               return _global_properties.has(glob)
+       end
+
        # Get a local proprty by its global property
        meth [](glob: MMGlobalProperty): MMLocalProperty
        do
-               assert _local_property_by_global != null
-               assert glob != null
-               if _local_property_by_global.has_key(glob) then
-                       return _local_property_by_global[glob]
-               end
-               return null
+               return _local_property_by_global[glob]
        end
 
        # The current MMContext