src/model: add `is_generated` filter
authorAlexandre Terrasa <alexandre@moz-code.org>
Fri, 1 Jun 2018 15:43:23 +0000 (11:43 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Sat, 2 Jun 2018 15:59:30 +0000 (11:59 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/model/model_filters.nit

index 572ccbd..2c6cead 100644 (file)
@@ -15,6 +15,7 @@
 module model_filters
 
 import model_examples
+import parse_annotations
 
 # A list of filters that can be applied on a MEntity
 #
@@ -47,6 +48,7 @@ class ModelFilter
                if not accept_mentity_broken(mentity) then return false
                if not accept_mentity_visibility(mentity) then return false
                if not accept_mentity_fictive(mentity) then return false
+               if not accept_mentity_generated(mentity) then return false
                if not accept_mentity_test(mentity) then return false
                if not accept_mentity_redef(mentity) then return false
                if not accept_mentity_extern(mentity) then return false
@@ -81,6 +83,28 @@ class ModelFilter
                return not mentity.is_fictive
        end
 
+       # Accept generated entities?
+       #
+       # Default is `true`.
+       var accept_generated = true is optional, writable
+
+       # Accept only non-generated entities
+       #
+       # See `MEntity::is_generated`.
+       fun accept_mentity_generated(mentity: MEntity): Bool do
+               if accept_generated then return true
+               if mentity isa MClass then mentity = mentity.intro
+               if mentity isa MProperty then mentity = mentity.intro
+               if mentity isa MModule then
+                       return not mentity.has_annotation("generated")
+               else if mentity isa MClassDef then
+                       return not mentity.has_annotation("generated")
+               else if mentity isa MPropDef then
+                       return not mentity.has_annotation("generated")
+               end
+               return true
+       end
+
        # Accept nitunit test suites?
        #
        # Default is `true`.