X-Git-Url: http://nitlanguage.org?ds=sidebyside diff --git a/src/model/model_visitor.nit b/src/model/model_visitor.nit index b7a2cd3..d733912 100644 --- a/src/model/model_visitor.nit +++ b/src/model/model_visitor.nit @@ -41,19 +41,20 @@ # ~~~ module model_visitor -import model +import model_filters # The abstract model visitor template. # # Specific visitor must implement the `visit` method to perform the work. abstract class ModelVisitor + # Visit the entity `e`. # # This method setups `current_entity` and call `visit`. # 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 + if not accept_mentity(e) then return var old_entity = current_entity current_entity = e visit(e) @@ -68,23 +69,31 @@ abstract class ModelVisitor # It should not be called directly but used by `enter_visit` protected fun visit(e: MEntity) is abstract - # Filter classes and method on the visibility. + # Filters to apply when visiting the model. # - # If set, only the classes and method with at least the given - # visibility level will be visited. - var min_visibility: nullable MVisibility = null is writable - - # Is `visibility` acceptable with regard to `min_visibility`? - private fun accept_visitibily(visibility: MVisibility): Bool - do - var min = min_visibility - return min == null or min <= visibility + # See ModelFilters for configuration. + var filter: ModelFilter is lazy, writable, optional do + return new ModelFilter( + min_visibility = protected_visibility, + accept_fictive = false, + accept_test = false, + accept_example = false, + accept_redef = true, + accept_extern = true, + accept_attribute = true, + accept_empty_doc = true + ) end - # Include fictive entities? + # Should we accept this `mentity` from the view? # - # By default, fictive entities (see `MEntity::is_fictive`) are not visited. - var include_fictive = false is writable + # If no `override_filter` is passed then use `self.filter`. + fun accept_mentity(mentity: MEntity, override_filter: nullable ModelFilter): Bool do + if override_filter != null then + return override_filter.accept_mentity(mentity) + end + return filter.accept_mentity(mentity) + end end redef class MEntity @@ -124,7 +133,6 @@ redef class MModule # On class importation, nothing is visited (the `MClass` and the `MClassDef` are visited in imported modules). redef fun visit_all(v) do for x in mclassdefs do - if not v.accept_visitibily(x.mclass.visibility) then return if x.is_intro then v.enter_visit(x.mclass) v.enter_visit(x) end @@ -139,7 +147,6 @@ redef class MClassDef # On property inheritance, nothing is visited (the `MProperty` and the `MPropDef` are visited in inherited classes). redef fun visit_all(v) do for x in mpropdefs do - if not v.accept_visitibily(x.mproperty.visibility) then return if x.is_intro then v.enter_visit(x.mproperty) v.enter_visit(x) end