1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
19 # A list of filters that can be applied on a MEntity
22 # By default ModelFilter accepts all mentity.
25 # var filter = new ModelFilter
26 # assert filter.accept_mentity(my_mentity) == true
29 # To quickly configure the filters, options can be passed to the constructor:
31 # var filter = new ModelFilter(
32 # min_visibility = protected_visibility,
33 # accept_fictive = false,
34 # accept_test = false,
35 # accept_redef = false,
36 # accept_extern = false,
37 # accept_attribute = false,
38 # accept_empty_doc = false
43 # Accept `mentity` based on all the options from `self`?
45 # If one of the filter returns `false` then the `mentity` is not accepted.
46 fun accept_mentity
(mentity
: MEntity): Bool do
47 if not accept_mentity_visibility
(mentity
) then return false
48 if not accept_mentity_fictive
(mentity
) then return false
49 if not accept_mentity_test
(mentity
) then return false
50 if not accept_mentity_redef
(mentity
) then return false
51 if not accept_mentity_extern
(mentity
) then return false
52 if not accept_mentity_example
(mentity
) then return false
53 if not accept_mentity_attribute
(mentity
) then return false
54 if not accept_mentity_empty_doc
(mentity
) then return false
55 if not accept_mentity_inherited
(mentity
) then return false
56 if not accept_mentity_full_name
(mentity
) then return false
60 # Minimum visibility an entity must have to be accepted
62 # Default is `private_visibility`.
63 var min_visibility
: MVisibility = private_visibility
is optional
, writable
65 # Accept `mentity` if its visibility is above `min_visibility`
66 fun accept_mentity_visibility
(mentity
: MEntity): Bool do
67 return mentity
.visibility
>= min_visibility
70 # Accept fictive entities?
73 var accept_fictive
= true is optional
, writable
75 # Accept only non-fictive entities
77 # See `MEntity::is_fictive`.
78 fun accept_mentity_fictive
(mentity
: MEntity): Bool do
79 if accept_fictive
then return true
80 return not mentity
.is_fictive
83 # Accept nitunit test suites?
86 var accept_test
= true is optional
, writable
88 # Accept only entities that are not `nitunit` related
89 fun accept_mentity_test
(mentity
: MEntity): Bool do
90 if accept_test
then return true
91 if mentity
isa MProperty then return accept_mentity
(mentity
.intro
)
92 if mentity
isa MMethodDef then
93 if mentity
.is_before
then return false
94 if mentity
.is_before_all
then return false
95 if mentity
.is_after
then return false
96 if mentity
.is_after_all
then return false
98 return not mentity
.is_test
101 # Accept redef classdefs and propdefs?
104 var accept_redef
= true is optional
, writable
106 # Accept a MClassDefs and MPropeDefs onyl if they are an introduction
108 # See `MClassDef::is_intro` and `MPropDef::is_intro`.
109 fun accept_mentity_redef
(mentity
: MEntity): Bool do
110 if accept_redef
then return true
111 if mentity
isa MClassDef then
112 return mentity
.is_intro
113 else if mentity
isa MPropDef then
114 return mentity
.is_intro
119 # Accept extern entities?
122 var accept_extern
= true is optional
, writable
124 # Accept only non- extern entities
126 # See `MEntity::is_extern`.
127 fun accept_mentity_extern
(mentity
: MEntity): Bool do
128 if accept_extern
then return true
129 if mentity
isa MMethodDef then
130 return not mentity
.is_extern
135 # Accept `MAttribute` and `MAttributeDef` instances?
138 var accept_attribute
= true is optional
, writable
140 # Accept only entities that are not a `MAttribute` or `MAttributeDef`
141 fun accept_mentity_attribute
(mentity
: MEntity): Bool do
142 if accept_attribute
then return true
143 if mentity
isa MAttribute then return false
144 if mentity
isa MAttributeDef then return false
148 # Accept entities with empty documentation?
151 var accept_empty_doc
= true is optional
, writable
153 # Accept only entities with documentation
154 fun accept_mentity_empty_doc
(mentity
: MEntity): Bool do
155 if accept_empty_doc
then return true
156 return mentity
.mdoc_or_fallback
!= null
162 var accept_example
= true is optional
164 # Accept only entities that are not example related
165 fun accept_mentity_example
(mentity
: MEntity): Bool do
166 if accept_example
then return true
167 return not mentity
.is_example
170 # If set, accept only entities local to `accept_inherited`
171 var accept_inherited
: nullable MEntity = null is optional
173 # Accept only entities local to `accept_inherited`
175 # This means no imported or inherited entities.
176 fun accept_mentity_inherited
(mentity
: MEntity): Bool do
177 var context
= accept_inherited
178 if context
== null then return true
179 if context
isa MPackage then
180 if mentity
isa MGroup then return mentity
.mpackage
== context
181 if mentity
isa MModule then return mentity
.mpackage
== context
183 if context
isa MGroup then
184 if mentity
isa MModule then return mentity
.mgroup
== context
186 if context
isa MModule then
187 if mentity
isa MClass then return mentity
.intro
.mmodule
== context
188 if mentity
isa MClassDef then return mentity
.mmodule
== context
190 if context
isa MClass then
191 if mentity
isa MProperty then return mentity
.intro_mclassdef
.mclass
== context
192 if mentity
isa MPropDef then return mentity
.mclassdef
.mclass
== context
194 if context
isa MClassDef then
195 if mentity
isa MProperty then return mentity
.intro_mclassdef
== context
196 if mentity
isa MPropDef then return mentity
.mclassdef
== context
201 # If set, accept only entities where `MEntity::full_name` contains `string`
202 var accept_full_name
: nullable String = null is optional
, writable
204 # Accept only entities where `MEntity::full_name` contains `string`
205 fun accept_mentity_full_name
(mentity
: MEntity): Bool do
206 var string
= accept_full_name
207 if string
== null then return true
208 return mentity
.full_name
.has
(string
)