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

Contents of /branches/eth/eve/Src/framework/code_analysis/ca_code_analyzer.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 93174 - (show annotations)
Mon Oct 28 12:30:08 2013 UTC (6 years ago) by zurfluhs
File size: 3667 byte(s)
Code Analysis: distinction between class-wide and system-wide rules.
1 note
2 description: "Summary description for {CA_CODE_ANALYZER}."
3 author: "Stefan Zurfluh"
4 date: "$Date$"
5 revision: "$Revision$"
6
7 class
8 CA_CODE_ANALYZER
9
10 inherit {NONE}
11 SHARED_EIFFEL_PROJECT
12
13 create
14 make
15
16 feature {NONE} -- Initialization
17
18 make
19 -- Initialization for `Current'.
20 do
21 create settings
22 create rules.make
23 -- Adding example rules
24 rules.extend (create {CA_SELF_ASSIGNMENT_RULE}.make)
25 rules.extend (create {CA_UNUSED_ARGUMENT_RULE}.make)
26
27 create classes_to_analyze.make
28 create rule_violations.make (100)
29 end
30
31 feature -- Analysis interface
32
33 analyze
34 local
35 l_rules_checker: CA_ALL_RULES_CHECKER
36 do
37 create l_rules_checker.make
38 across rules as l_rules loop
39 if l_rules.item.is_enabled then -- important: only add enabled rules
40 if system_wide_check or else (not l_rules.item.is_system_wide) then
41 -- do not add system wide rules if we check only parts of the system
42 l_rules.item.prepare_checking (l_rules_checker)
43 end
44 end
45 end
46
47 across classes_to_analyze as l_classes loop
48 l_rules_checker.run_on_class (l_classes.item)
49
50 rule_violations.extend (create {SORTED_TWO_WAY_LIST[CA_RULE_VIOLATION]}.make, l_classes.item)
51
52 -- TODO: perhaps replace by more elegant and performant solution
53 across rules as l_rules loop
54 across l_rules.item.violations as l_v loop
55 rule_violations.at (l_classes.item).extend (l_v.item)
56 end
57 l_rules.item.violations.wipe_out
58 end
59 end
60
61 clear_classes_to_analyze
62 ensure
63 violation_list_exists: analysis_successful implies rule_violations /= Void
64 end
65
66 clear_classes_to_analyze
67 do
68 classes_to_analyze.wipe_out
69 end
70
71 add_whole_system
72 local
73 l_groups: LIST [CONF_GROUP]
74 l_cluster: CLUSTER_I
75 do
76 from
77 l_groups := eiffel_universe.groups
78 l_groups.start
79 until
80 l_groups.after
81 loop
82 l_cluster ?= l_groups.item_for_iteration
83 -- Only load top-level clusters, as they are loaded recursively afterwards
84 if l_cluster /= Void and then l_cluster.parent_cluster = Void then
85 add_cluster (l_cluster)
86 end
87 l_groups.forth
88 end
89
90 system_wide_check := True
91 end
92
93 add_cluster (a_cluster: CLUSTER_I)
94 local
95 l_conf_class: CONF_CLASS
96 l_class_i: CLASS_I
97 do
98 system_wide_check := False
99
100 from
101 a_cluster.classes.start
102 until
103 a_cluster.classes.after
104 loop
105 l_conf_class := a_cluster.classes.item_for_iteration
106 l_class_i := eiffel_universe.class_named (l_conf_class.name, a_cluster)
107 add_class (l_class_i)
108 a_cluster.classes.forth
109 end
110 if a_cluster.sub_clusters /= Void then
111 from
112 a_cluster.sub_clusters.start
113 until
114 a_cluster.sub_clusters.after
115 loop
116 add_cluster (a_cluster.sub_clusters.item_for_iteration)
117 a_cluster.sub_clusters.forth
118 end
119 end
120 end
121
122 add_classes (a_classes: ITERABLE[CLASS_I])
123 do
124 system_wide_check := False
125
126 across a_classes as l_classes loop
127 add_class (l_classes.item)
128 end
129 end
130
131 add_class (a_class: CLASS_I)
132 local
133 l_class_c: CLASS_C
134 do
135 system_wide_check := False
136
137 if a_class.is_compiled then
138 l_class_c := a_class.compiled_class
139 check l_class_c /= Void end
140 print ("Analyzing class " + a_class.name + "...%N")
141 classes_to_analyze.extend (l_class_c)
142 else
143 print ("Class " + a_class.name + " not compiled (skipped).%N")
144 end
145 end
146
147 feature -- Properties
148
149 analysis_successful: BOOLEAN
150
151 rules: LINKED_LIST[CA_RULE]
152
153 rule_violations: detachable HASH_TABLE[SORTED_TWO_WAY_LIST[CA_RULE_VIOLATION], CLASS_C]
154
155 feature {NONE} -- Implementation
156
157 settings: CA_SETTINGS
158
159 classes_to_analyze: LINKED_SET[CLASS_C]
160
161 system_wide_check: BOOLEAN
162
163 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23