X-Git-Url: http://nitlanguage.org diff --git a/src/model/model_filters.nit b/src/model/model_filters.nit index 740a17a..0d47a92 100644 --- a/src/model/model_filters.nit +++ b/src/model/model_filters.nit @@ -15,6 +15,7 @@ module model_filters import model_examples +import parse_annotations # A list of filters that can be applied on a MEntity # @@ -40,12 +41,30 @@ import model_examples # ~~~ class ModelFilter + # Initialize `self` by copying the options from another `filter` + init from(filter: ModelFilter) do + init( + min_visibility = filter.min_visibility, + accept_fictive = filter.accept_fictive, + accept_test = filter.accept_test, + accept_redef = filter.accept_redef, + accept_extern = filter.accept_extern, + accept_example = filter.accept_example, + accept_attribute = filter.accept_attribute, + accept_empty_doc = filter.accept_empty_doc, + accept_inherited = filter.accept_inherited, + accept_full_name = filter.accept_full_name + ) + end + # Accept `mentity` based on all the options from `self`? # # If one of the filter returns `false` then the `mentity` is not accepted. fun accept_mentity(mentity: MEntity): Bool do + 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 @@ -80,6 +99,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`. @@ -159,7 +200,7 @@ class ModelFilter # Accept examples? # # Default is `true`. - var accept_example = true is optional + var accept_example = true is optional, writable # Accept only entities that are not example related fun accept_mentity_example(mentity: MEntity): Bool do @@ -168,7 +209,7 @@ class ModelFilter end # If set, accept only entities local to `accept_inherited` - var accept_inherited: nullable MEntity = null is optional + var accept_inherited: nullable MEntity = null is optional, writable # Accept only entities local to `accept_inherited` # @@ -207,4 +248,15 @@ class ModelFilter if string == null then return true return mentity.full_name.has(string) end + + # Accept broken classes and properties? + # + # Default is `false`. + var accept_broken = false is optional, writable + + # Accept only non broken entities + fun accept_mentity_broken(mentity: MEntity): Bool do + if accept_broken then return true + return not mentity.is_broken + end end