57bbce3e38b86b64e62bfb5272a8dd3e8996330b
[nit.git] / src / nitpick.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 # A program that collect potential style and code issues
16 module nitpick
17
18 import frontend
19
20 redef class ToolContext
21 # Modules to analyze, other modules will only get a shallow processing.
22 var mmodules_to_check = new HashSet[MModule]
23 redef fun phase_process_npropdef(phase, npropdef)
24 do
25 var pd = npropdef.mpropdef
26
27 # Do not analyze the property bodies outside specified modules
28 if pd != null and not mmodules_to_check.has(pd.mclassdef.mmodule) then return
29 super
30 end
31 end
32
33 # Create a tool context to handle options and paths
34 var toolcontext = new ToolContext
35 toolcontext.tooldescription = "Usage: nitpick [OPTION]... <file.nit>...\nCollect potential style and code issues."
36
37 # We do not add other options, so process them now!
38 toolcontext.process_options(args)
39
40 # Get arguments
41 var arguments = toolcontext.option_context.rest
42
43 # We need a model to collect stuffs
44 var model = new Model
45 # A model builder to parse files
46 var modelbuilder = new ModelBuilder(model, toolcontext)
47
48 # Here we load an process all modules passed on the command line
49 var mmodules = modelbuilder.parse_full(arguments)
50 toolcontext.mmodules_to_check.add_all mmodules
51
52 modelbuilder.run_phases