module model_filters
-import model
+import model_examples
+import parse_annotations
# A list of filters that can be applied on a MEntity
#
# ~~~
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
+ if not accept_mentity_example(mentity) then return false
if not accept_mentity_attribute(mentity) then return false
if not accept_mentity_empty_doc(mentity) then return false
if not accept_mentity_inherited(mentity) then return false
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`.
return mentity.mdoc_or_fallback != null
end
+ # Accept examples?
+ #
+ # Default is `true`.
+ var accept_example = true is optional, writable
+
+ # Accept only entities that are not example related
+ fun accept_mentity_example(mentity: MEntity): Bool do
+ if accept_example then return true
+ return not mentity.is_example
+ 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`
#
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