Nitsmell : Adding new code smells and print console updated
[nit.git] / src / metrics / nitsmell_toolcontext.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 module nitsmell_toolcontext
17
18 import modelbuilder
19 import csv
20 import counter
21 import console
22
23 redef class ToolContext
24
25 # --all
26 var opt_all = new OptionBool("Print all code smells for top 10 class", "--all")
27 # --get-all
28 var opt_get_all = new OptionBool("Print all code smells for all class", "--get-all")
29 # --feature-envy
30 var opt_feature_envy = new OptionBool("Print feature envy", "--feature-envy")
31 # --large-class
32 var opt_large_class = new OptionBool("Print large class", "--large-class")
33 # --long-methods
34 var opt_long_method = new OptionBool("Print long method", "--long-methods")
35 # --no-abstract-implementation
36 var opt_no_abstract_implementation = new OptionBool("Print the no implemented abstract method", "--no-abstract-implementation")
37 # --long-params
38 var opt_long_params = new OptionBool("Print long parameters", "--long-params")
39 # --move-generics
40 var opt_move_generics = new OptionBool("Print the move proposition for generic class", "--move-generics")
41 # --move-generics
42 var opt_long_method_threshold = new OptionInt("Select long method threshold", 0 ,"--long-method-threshold")
43 # --long-method-threshold
44 var opt_long_params_threshold = new OptionInt("Select long method parameters threshold", 0 ,"--long-params-threshold")
45 # --long-params-threshold
46 var opt_nocolors = new OptionBool("Disable colors in console outputs", "--no-colors")
47
48 redef init
49 do
50 super
51 self.option_context.add_option(opt_all)
52 self.option_context.add_option(opt_large_class)
53 self.option_context.add_option(opt_get_all)
54 self.option_context.add_option(opt_feature_envy)
55 self.option_context.add_option(opt_long_method)
56 self.option_context.add_option(opt_no_abstract_implementation)
57 self.option_context.add_option(opt_long_params)
58 self.option_context.add_option(opt_long_method_threshold)
59 self.option_context.add_option(opt_long_params_threshold)
60 self.option_context.add_option(opt_move_generics)
61 self.option_context.add_option(opt_nocolors)
62 end
63
64 # Format and colorize a string heading of level 1 for console output.
65 #
66 # Default style is yellow and bold.
67 fun format_h1(str: String): String do
68 if opt_nocolors.value then return str
69 return str.yellow.bold
70 end
71
72 # Format and colorize a string heading of level 2 for console output.
73 #
74 # Default style is white and bold.
75 fun format_h2(str: String): String do
76 if opt_nocolors.value then return str
77 return str.bold
78 end
79
80 # Format and colorize a string heading of level 3 for console output.
81 #
82 # Default style is white and nobold.
83 fun format_h3(str: String): String do
84 if opt_nocolors.value then return str
85 return str
86 end
87
88 # Format and colorize a string heading of level 4 for console output.
89 #
90 # Default style is green.
91 fun format_h4(str: String): String do
92 if opt_nocolors.value then return str
93 return str.green
94 end
95
96 # Format and colorize a string heading of level 5 for console output.
97 #
98 # Default style is light gray.
99 fun format_p(str: String): String do
100 if opt_nocolors.value then return str
101 return str.light_gray
102 end
103 end