/[eiffelstudio]/branches/eth/eve/Src/Eiffel/interface/graphical/tools/autodebug/data/es_adb_fix_contract.e
ViewVC logotype

Contents of /branches/eth/eve/Src/Eiffel/interface/graphical/tools/autodebug/data/es_adb_fix_contract.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 95332 - (show annotations)
Fri Jun 27 12:57:49 2014 UTC (5 years, 3 months ago) by maxpei
File size: 7529 byte(s)
Fixed a few bugs in AutoFix and AutoDebug.
1 note
2 description: "Summary description for {ES_ADB_FIX_CONTRACT}."
3 author: ""
4 date: "$Date$"
5 revision: "$Revision$"
6
7 class
8 ES_ADB_FIX_CONTRACT
9
10 inherit
11 ES_ADB_FIX_AUTOMATIC
12
13 create
14 make
15
16 feature{NONE} -- Initialization
17
18 make (a_fault: ES_ADB_FAULT; a_id_string: STRING; a_fix_text: STRING; a_nature_str: STRING; a_ranking: REAL)
19 -- Initialization.
20 require
21 a_fault /= Void
22 a_id_string /= Void and then not a_id_string.is_empty
23 is_valid_nature_of_change (nature_of_change_from_string (a_nature_str))
24 Ranking_maximum >= a_ranking and then a_ranking >= Ranking_minimum
25 local
26 do
27 make_automatic (a_fault, a_id_string)
28 fix_text := a_fix_text.twin
29 set_nature_of_change (nature_of_change_from_string (a_nature_str))
30 has_change_to_implementation := False
31 has_change_to_contract := True
32 has_been_applied := False
33 type := Type_contract_fix
34 set_ranking (a_ranking)
35
36 a_fault.add_fix (Current)
37 end
38
39 feature -- Access
40
41 code_before_fix: STRING
42 -- <Precursor>
43 do
44 if code_before_fix_internal = Void then
45 initialize_code_before_and_after_fix
46 end
47 Result := code_before_fix_internal
48 end
49
50 code_after_fix: STRING
51 -- <Precursor>
52 do
53 if code_after_fix_internal = Void then
54 initialize_code_before_and_after_fix
55 end
56 Result := code_after_fix_internal
57 end
58
59 feature -- Status report
60
61 is_valid_nature_of_change (a_nature: INTEGER): BOOLEAN
62 -- <Precursor>
63 do
64 Result := Nature_strengthen <= a_nature and then a_nature <= Nature_weaken_and_strengthen
65 end
66
67 feature -- Query
68
69 nature_of_change_strings: DS_HASH_TABLE [STRING_8, INTEGER]
70 -- <Precursor>
71 do
72 if nature_of_change_strings_internal = Void then
73 create nature_of_change_strings_internal.make_equal (10)
74 nature_of_change_strings_internal.force ("Strengthen", Nature_strengthen)
75 nature_of_change_strings_internal.force ("Weaken", Nature_weaken)
76 nature_of_change_strings_internal.force ("WeakenAndStrengthen", Nature_weaken_and_strengthen)
77 end
78 Result := nature_of_change_strings_internal
79 end
80
81 feature -- Operation
82
83 apply
84 -- Set `has_been_applied' to True.
85 -- WARNING: changes to contracts need to be applied manually.
86 require
87 not has_been_applied and then not fault.is_fixed
88 do
89 set_has_been_applied
90 ensure
91 has_been_applied
92 fault.is_candidate_fix_accepted
93 end
94
95 feature{NONE} -- Initialization implementation
96
97 initialize_code_before_and_after_fix
98 -- Initialize code before and after fix from `fix_text'.
99 local
100 l_lines: LIST [STRING]
101 l_line_cursor: INDEXABLE_ITERATION_CURSOR [STRING]
102 l_line: STRING
103 l_first_dot_index, l_second_dot_index: INTEGER
104 l_class_name, l_feature_name: STRING
105 l_is_pre: BOOLEAN
106 l_feature: AFX_FEATURE_TO_MONITOR
107 l_contracts: TUPLE [pre, post: EPA_HASH_SET [EPA_EXPRESSION]]
108 l_old_contracts, l_new_contracts, l_to_add, l_to_remove: EPA_HASH_SET [EPA_EXPRESSION]
109 l_expr_text: STRING
110 l_expr: EPA_AST_EXPRESSION
111 l_clause: EPA_EXPRESSION
112 l_contract_extractor: EPA_CONTRACT_EXTRACTOR
113 l_clauses: LINKED_LIST [EPA_EXPRESSION]
114 l_headline_for_feature: STRING
115 do
116 create l_contract_extractor
117 create code_before_fix_internal.make (1024)
118 create code_after_fix_internal.make (1024)
119
120 l_lines := fix_text.split ('%N')
121 from
122 l_line_cursor := l_lines.new_cursor
123 l_line_cursor.start
124 until
125 l_line_cursor.after
126 loop
127 l_line := l_line_cursor.item
128 l_line.prune_all ('%R')
129
130 if l_line.starts_with ("++:") then
131 l_expr_text := l_line.substring (4, l_line.count)
132 create l_expr.make_with_text (l_feature.context_class, l_feature.feature_, l_expr_text, l_feature.written_class)
133 l_to_add.force (l_expr)
134
135 elseif l_line.starts_with ("--:") then
136 l_expr_text := l_line.substring (4, l_line.count)
137 create l_expr.make_with_text (l_feature.context_class, l_feature.feature_, l_expr_text, l_feature.written_class)
138 l_to_remove.force (l_expr)
139
140 elseif l_line.starts_with ("<< ") then
141 l_first_dot_index := l_line.index_of ('.', 1)
142 l_second_dot_index := l_line.index_of ('.', l_first_dot_index + 1)
143 l_is_pre := l_line.ends_with (".pre.")
144 l_class_name := l_line.substring (4, l_first_dot_index - 1)
145 l_feature_name := l_line.substring (l_first_dot_index + 1, l_second_dot_index - 1)
146
147 create l_feature.make_from_feature_with_context_class (create {EPA_FEATURE_WITH_CONTEXT_CLASS}.make_from_names (l_feature_name, l_class_name))
148 create l_to_add.make_equal (5)
149 create l_to_remove.make_equal (5)
150
151 elseif l_line.starts_with (">>") then
152 if l_is_pre then
153 l_clauses := l_contract_extractor.precondition_of_feature (l_feature.feature_, l_feature.context_class)
154 l_headline_for_feature := l_feature.qualified_feature_name + " (Precondition)"
155 else
156 l_clauses := l_contract_extractor.postcondition_of_feature (l_feature.feature_, l_feature.context_class)
157 l_headline_for_feature := l_feature.qualified_feature_name + " (Postcondition)"
158 end
159 code_before_fix_internal.append ("%T-- " + l_headline_for_feature + "%N")
160 code_after_fix_internal.append ("%T-- " + l_headline_for_feature + "%N")
161
162 from
163 l_clauses.start
164 until
165 l_clauses.after
166 loop
167 l_clause := l_clauses.item_for_iteration
168 if l_to_remove.has (l_clause) then
169 code_before_fix_internal.append (l_clause.text + "%N")
170 else
171 code_before_fix_internal.append (l_clause.text + "%N")
172 code_after_fix_internal.append (l_clause.text + "%N")
173 end
174 l_clauses.forth
175 end
176 from
177 l_to_add.start
178 until
179 l_to_add.after
180 loop
181 l_clause := l_to_add.item_for_iteration
182
183 code_after_fix_internal.append (l_clause.text + "%N")
184
185 l_to_add.forth
186 end
187 code_before_fix_internal.append ("%N")
188 code_after_fix_internal.append ("%N")
189 end
190 l_line_cursor.forth
191 end
192 end
193
194 feature{NONE} -- Implementation
195
196 Nature_strengthen: INTEGER = 5
197 Nature_weaken: INTEGER = 6
198 Nature_weaken_and_strengthen: INTEGER = 7
199
200 feature{NONE} -- Cache
201
202 nature_of_change_strings_internal: like nature_of_change_strings
203 code_before_fix_internal: STRING
204 code_after_fix_internal: STRING
205
206
207 ;note
208 copyright: "Copyright (c) 1984-2014, Eiffel Software"
209 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
210 licensing_options: "http://www.eiffel.com/licensing"
211 copying: "[
212 This file is part of Eiffel Software's Eiffel Development Environment.
213
214 Eiffel Software's Eiffel Development Environment is free
215 software; you can redistribute it and/or modify it under
216 the terms of the GNU General Public License as published
217 by the Free Software Foundation, version 2 of the License
218 (available at the URL listed under "license" above).
219
220 Eiffel Software's Eiffel Development Environment is
221 distributed in the hope that it will be useful, but
222 WITHOUT ANY WARRANTY; without even the implied warranty
223 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
224 See the GNU General Public License for more details.
225
226 You should have received a copy of the GNU General Public
227 License along with Eiffel Software's Eiffel Development
228 Environment; if not, write to the Free Software Foundation,
229 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
230 ]"
231 source: "[
232 Eiffel Software
233 5949 Hollister Ave., Goleta, CA 93117 USA
234 Telephone 805-685-1006, Fax 805-685-6869
235 Website http://www.eiffel.com
236 Customer support http://support.eiffel.com
237 ]"
238 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23