model_visitor: skip fictive entities by default
authorJean Privat <jean@pryen.org>
Wed, 21 Oct 2015 20:30:08 +0000 (16:30 -0400)
committerJean Privat <jean@pryen.org>
Wed, 21 Oct 2015 20:30:08 +0000 (16:30 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/model/model_visitor.nit
src/test_model_visitor.nit
tests/sav/test_model_visitor_args1.res

index f6169cf..b7a2cd3 100644 (file)
@@ -53,6 +53,7 @@ abstract class ModelVisitor
        # If `e` is null, nothing is done.
        fun enter_visit(e: nullable MEntity) do
                if e == null then return
+               if e.is_fictive and not include_fictive then return
                var old_entity = current_entity
                current_entity = e
                visit(e)
@@ -79,6 +80,11 @@ abstract class ModelVisitor
                var min = min_visibility
                return min == null or min <= visibility
        end
+
+       # Include fictive entities?
+       #
+       # By default, fictive entities (see `MEntity::is_fictive`) are not visited.
+       var include_fictive = false is writable
 end
 
 redef class MEntity
index be2899b..9dd07e8 100644 (file)
@@ -45,8 +45,14 @@ redef fun do_work(mainmodule, given_mmodules, modelbuilder)
 do
        var model = modelbuilder.model
 
-       print "All entities:"
+       print "All entities, including fictive ones:"
        var v = new TestModelVisitor
+       v.include_fictive = true
+       v.enter_visit(model)
+       v.cpt.print_elements(10)
+
+       print "All entities:"
+       v = new TestModelVisitor
        v.enter_visit(model)
        v.cpt.print_elements(10)
 
index 1b30918..5a930fe 100644 (file)
@@ -1,3 +1,15 @@
+All entities, including fictive ones:
+ list:
+  MMethodDef: 17 (30.35%)
+  MMethod: 15 (26.78%)
+  MClassDef: 7 (12.50%)
+  MClass: 7 (12.50%)
+  MAttributeDef: 3 (5.35%)
+  MAttribute: 3 (5.35%)
+  Model: 1 (1.78%)
+  MGroup: 1 (1.78%)
+  MPackage: 1 (1.78%)
+  MModule: 1 (1.78%)
 All entities:
  list:
   MMethodDef: 17 (30.35%)