/[eiffelstudio]/branches/eth/eve/Src/framework/code_analysis/rules/ca_npath_rule.e
ViewVC logotype

Contents of /branches/eth/eve/Src/framework/code_analysis/rules/ca_npath_rule.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 93426 - (show annotations)
Tue Nov 19 08:45:14 2013 UTC (6 years ago) by zurfluhs
File size: 4851 byte(s)
Code Analysis: GUI:

- analysis options in class indexing clauses
  - rules that ignore class
  - library / nonlibrary classes
1 note
2 description: "Summary description for {CA_NPATH_RULE}."
3 author: ""
4 date: "$Date$"
5 revision: "$Revision$"
6
7 class
8 CA_NPATH_RULE
9
10 inherit
11 CA_STANDARD_RULE
12 redefine id end
13
14 create
15 make
16
17 feature {NONE} -- Initialization
18
19 make
20 do
21 is_enabled := True
22 create {CA_WARNING} severity
23 create violations.make
24 create {LINKED_STACK[INTEGER]} npath_stack.make
25 end
26
27 feature {NONE} -- Activation
28
29 register_actions (a_checker: CA_ALL_RULES_CHECKER)
30 do
31 a_checker.add_feature_pre_action (agent process_feature)
32 a_checker.add_do_pre_action (agent pre_process_do)
33 a_checker.add_do_post_action (agent post_process_do)
34 a_checker.add_once_pre_action (agent pre_process_once)
35 a_checker.add_once_post_action (agent post_process_once)
36 a_checker.add_if_pre_action (agent pre_process_if)
37 a_checker.add_if_post_action (agent post_process_if)
38 a_checker.add_loop_pre_action (agent pre_process_loop)
39 a_checker.add_loop_post_action (agent post_process_loop)
40 a_checker.add_inspect_pre_action (agent pre_process_inspect)
41 a_checker.add_inspect_post_action (agent post_process_inspect)
42 end
43
44
45 feature -- Properties
46
47 title: STRING
48 do
49 Result := ca_names.npath_title
50 end
51
52 id: STRING = "CA034T"
53 -- "T" stands for 'under test'.
54
55 description: STRING
56 do
57 Result := ca_names.npath_description
58 end
59
60 options: LINKED_LIST[CA_RULE_OPTION[INTEGER]]
61 local
62 l_threshold: CA_RULE_OPTION[INTEGER]
63 once
64 create l_threshold.make_with_caption (ca_names.npath_threshold_option)
65 l_threshold.set_valid_choice_agent (agent is_threshold_within_bounds)
66 l_threshold.set_choice (200) -- default option
67
68 create Result.make
69 Result.extend (l_threshold)
70 end
71
72
73 is_system_wide: BOOLEAN
74 once
75 Result := False
76 end
77
78 format_violation_description (a_violation: CA_RULE_VIOLATION; a_formatter: TEXT_FORMATTER)
79 local
80 l_info: LINKED_LIST[ANY]
81 do
82 l_info := a_violation.long_description_info
83 a_formatter.add_string (ca_messages.npath_violation_1)
84 if attached {FEATURE_AS} l_info.first as l_feat then
85 a_formatter.add_feature_name (l_feat.feature_name.name_32, a_violation.affected_class)
86 end
87 a_formatter.add_string (ca_messages.npath_violation_2)
88 if attached {INTEGER} l_info.at (2) as l_npath then
89 a_formatter.add_int (l_npath)
90 end
91 a_formatter.add_string (ca_messages.npath_violation_3)
92 if attached {INTEGER} l_info.at (3) as l_max then
93 a_formatter.add_int (l_max)
94 end
95 a_formatter.add_char ('.')
96 end
97
98 feature {NONE} -- Options
99
100 is_threshold_within_bounds (a_threshold: INTEGER): BOOLEAN
101 do
102 Result := a_threshold >= 10 and a_threshold <= 10000
103 end
104
105 feature {NONE} -- Rule Checking
106
107 npath_stack: STACK[INTEGER]
108
109 process_feature (a_feature_as: FEATURE_AS)
110 do
111 current_feature := a_feature_as
112 end
113
114 pre_process_do (a_do: DO_AS)
115 do
116 prepare_routine
117 end
118 post_process_do (a_do: DO_AS)
119 do
120 evaluate_routine
121 end
122 pre_process_once (a_once: ONCE_AS)
123 do
124 prepare_routine
125 end
126 post_process_once (a_once: ONCE_AS)
127 do
128 evaluate_routine
129 end
130
131 prepare_routine
132 do
133 npath_stack.wipe_out
134 npath_stack.put (1)
135 end
136
137 evaluate_routine
138 local
139 l_violation: CA_RULE_VIOLATION
140 l_npath, l_threshold: INTEGER
141 do
142 check npath_stack.count = 1 end
143 l_npath := npath_stack.item
144
145 l_threshold := options.first.choice
146
147 if l_npath > l_threshold then
148 create l_violation.make_with_rule (Current)
149 check attached current_feature end
150 l_violation.set_location (current_feature.start_location)
151 l_violation.long_description_info.extend (current_feature)
152 l_violation.long_description_info.extend (l_npath)
153 l_violation.long_description_info.extend (l_threshold)
154 violations.extend (l_violation)
155 end
156 end
157
158 pre_process_if (a_if: IF_AS)
159 do
160 npath_stack.put (1)
161 end
162
163 post_process_if (a_if: IF_AS)
164 local
165 inner_npath, outer_npath: INTEGER
166 do
167 inner_npath := npath_stack.item + 1
168 npath_stack.remove
169 outer_npath := npath_stack.item
170 npath_stack.replace (inner_npath * outer_npath)
171 end
172
173 pre_process_loop (a_loop: LOOP_AS)
174 do
175 npath_stack.put (1)
176 end
177
178 post_process_loop (a_loop: LOOP_AS)
179 local
180 inner_npath, outer_npath: INTEGER
181 do
182 inner_npath := npath_stack.item + 1
183 npath_stack.remove
184 outer_npath := npath_stack.item
185 npath_stack.replace (inner_npath * outer_npath)
186 end
187
188 pre_process_inspect (a_inspect: INSPECT_AS)
189 do
190 npath_stack.put (1)
191 end
192
193 post_process_inspect (a_inspect: INSPECT_AS)
194 local
195 inner_npath, outer_npath: INTEGER
196 do
197 inner_npath := npath_stack.item + 1
198 npath_stack.remove
199 outer_npath := npath_stack.item
200 npath_stack.replace (inner_npath * outer_npath)
201 end
202
203 process_and_then (a_and_then: BIN_AND_THEN_AS)
204 do
205
206 end
207
208 process_or_else (a_or_else: BIN_OR_ELSE_AS)
209 do
210
211 end
212
213 current_feature: detachable FEATURE_AS
214
215 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision

  ViewVC Help
Powered by ViewVC 1.1.23