metamodel: MMLocalClass::[] aborts if no global class
authorJean Privat <jean@pryen.org>
Thu, 11 Jun 2009 18:58:33 +0000 (14:58 -0400)
committerJean Privat <jean@pryen.org>
Wed, 24 Jun 2009 19:47:10 +0000 (15:47 -0400)
Previous behavior was to return null.
Adapts existing clients by using the new MMLocalClass::has_global_property.

Signed-off-by: Jean Privat <jean@pryen.org>

src/compiling/compiling_global.nit
src/metamodel/inheritance.nit
src/nitdoc.nit

index f883907..c404b8d 100644 (file)
@@ -621,10 +621,9 @@ special TableEltProp
                        if s == pc then
                                found = true
                        else if found and c.che < s then
-                               var p = s[g]
-                               if p != null then
+                               if s.has_global_property(g) then
                                        #print "found {s.module}::{s}::{p}"
-                                       return p.cname
+                                       return s[g].cname
                                end
                        end
                end
index dd6a9ba..9988426 100644 (file)
@@ -193,11 +193,13 @@ redef class MMLocalClass
 
        redef meth [](glob)
        do
-               var prop = super(glob)
-               if prop == null and _global_properties.has(glob) then
-                       prop = inherit_local_property(glob)
+               if _local_property_by_global.has_key(glob) then
+                       return _local_property_by_global[glob]
+               else if has_global_property(glob) then
+                       return inherit_local_property(glob)
+               else
+                       abort
                end
-               return prop
        end
 
        # Add default super class in direct parent and in super classes if this is not the Object class
@@ -338,8 +340,7 @@ redef class MMLocalClass
                        # First compute the set of bottom properties
                        var impls = new ArraySet[MMLocalProperty]
                        for sc in supers do
-                               var p = sc[glob]
-                               if p != null then impls.add(p)
+                               if sc.has_global_property(glob) then impls.add(sc[glob])
                        end
                        # Second, extract most specific
                        var impls2 = ghier.select_smallests(impls)
@@ -377,9 +378,8 @@ redef class MMLocalProperty
                set_global(g)
                var impls = new Array[MMLocalProperty]
                for sc in local_class.che.direct_greaters do
-                       var p = sc[g]
-                       if p == null then continue
-                       impls.add(p)
+                       if not sc.has_global_property(g) then continue
+                       impls.add(sc[g])
                end
                g.add_local_property(self, impls)
        end
index 30d29da..df1cad4 100644 (file)
@@ -605,10 +605,12 @@ redef class MMSrcModule
                                end
                        else
                                for m in owned_modules do
-                                       var mc = m[c.global]
-                                       if mc != null and mc.need_doc(dctx) then 
-                                               new_classes.add(c)
-                                               break
+                                       if m.global_classes.has(c.global) then
+                                               var mc = m[c.global]
+                                               if mc.need_doc(dctx) then
+                                                       new_classes.add(c)
+                                                       break
+                                               end
                                        end
                                end
                        end
@@ -714,8 +716,10 @@ special MMEntity
        redef meth need_doc(dctx) do
                if module == dctx.module then
                        for m in dctx.owned_modules do
-                               var c = m[global]
-                               if c != null and c.need_doc(dctx) then return true
+                               if m.global_classes.has(global) then
+                                       var c = m[global]
+                                       if c.need_doc(dctx) then return true
+                               end
                        end
                end
                return false
@@ -875,10 +879,12 @@ special MMEntity
                        if p.local_class != self or not p.need_doc(dctx) then
                                var cla = new Array[MMLocalClass]
                                for m in dctx.owned_modules do
+                                       if not m.global_classes.has(global) then continue
                                        var c = m[global]
-                                       if c == null or not c isa MMConcreteClass then continue
+                                       if not c isa MMConcreteClass then continue
+                                       if not c.has_global_property(g) then continue
                                        var p2 = c[g]
-                                       if p2 == null or p2.local_class != c or not p2.need_doc(dctx) then continue
+                                       if p2.local_class != c or not p2.need_doc(dctx) then continue
                                        cla.add(c)
                                end
                                if cla.is_empty then continue