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.
15 # Fill toolcontext information about blacklisting of warnings.
19 private import literal
21 redef class ToolContext
22 # The phase should be executed before any warning on the module is processed.
23 var no_warning_phase
: Phase = new NoWarningPhase(self, [literal_phase
])
26 private class NoWarningPhase
29 redef fun process_nmodule
(nmodule
)
32 var mmodule
= nmodule
.mmodule
33 if mmodule
== null then return
35 var source
= nmodule
.location
.file
37 var nmoduledecl
= nmodule
.n_moduledecl
38 if nmoduledecl
== null or nmoduledecl
.n_doc
== null then
39 # Disable `missing-doc` if there is no `module` clause
40 # Rationale: the presence of a `module` clause is a good heuristic to
41 # discriminate quick and dirty prototypes from nice and clean modules
42 if source
!= null then toolcontext
.warning_blacklist
[source
].add
("missing-doc")
46 # If no decl block then quit
47 if nmoduledecl
== null then return
49 var modelbuilder
= toolcontext
.modelbuilder
51 # Disable `missing-doc` for `test`
52 if source
!= null and not nmoduledecl
.get_annotations
("test").is_empty
then
53 toolcontext
.warning_blacklist
[source
].add
("missing-doc")
56 # Get all the `no_warning` annotations
57 var name
= "no_warning"
58 var annots
= nmoduledecl
.get_annotations
(name
)
60 if annots
.is_empty
then return
62 if source
== null then
63 modelbuilder
.warning
(annots
.first
, "file-less-module", "Warning: `{name}` does not currently work on file-less modules.")
67 for annot
in annots
do
68 var args
= annot
.n_args
70 modelbuilder
.error
(annot
, "Syntax Error: `{name}` expects a list of warnings. Use `\"all\
"` to disable all warnings.")
74 var tag
= arg
.as_string
76 modelbuilder
.error
(arg
, "Syntax Error: `{name}` expects String as arguments.")
80 toolcontext
.warning_blacklist
[source
].add
(tag
)