/[eiffelstudio]/branches/eth/eve/Src/Eiffel/interface/lite/override/ecl_error_displayer.e
ViewVC logotype

Contents of /branches/eth/eve/Src/Eiffel/interface/lite/override/ecl_error_displayer.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94983 - (show annotations)
Fri May 2 11:05:28 2014 UTC (5 years, 5 months ago) by jasonw
File size: 7925 byte(s)
<<Merged from trunk#94978.>>
1 note
2 description: "A specialized version of {ERROR_DISPLAYER} to display errors in a format readable by external tools."
3 legal: "See notice at end of class."
4 status: "See notice at end of class."
5 date: "$Date$"
6 revision: "$Revision$"
7
8 class
9 ECL_ERROR_DISPLAYER
10
11 inherit
12 ERROR_DISPLAYER
13
14 OUTPUT_WINDOW_USER
15 rename
16 make as make_base
17 export
18 {NONE} all
19 end
20
21 SHARED_ERROR_TRACER
22 export
23 {NONE} all
24 end
25
26 create
27 make
28
29 feature {NONE} -- Initialization
30
31 make (a_name: like application_name; a_window: like output_window)
32 -- Initialize error displayer using an output window `a_window' and a application name `a_name'
33 require
34 a_name_attached: a_name /= Void
35 not_a_name_is_empty: not a_name.is_empty
36 a_window_attached: a_window /= Void
37 do
38 application_name := a_name
39 make_base (a_window)
40 ensure
41 application_name_set: application_name = a_name
42 output_window_set: output_window = a_window
43 end
44
45 feature -- Access
46
47 application_name: READABLE_STRING_GENERAL
48 -- Name of application to use when displaying errors
49
50 feature -- Element change
51
52 set_application_name (a_name: like application_name)
53 -- Set `application_name' with `a_name'
54 require
55 a_name_attached: a_name /= Void
56 not_a_name_is_empty: not a_name.is_empty
57 do
58 application_name := a_name
59 ensure
60 application_name_set: application_name = a_name
61 end
62
63 feature -- Output
64
65 trace (a_handler: ERROR_HANDLER)
66 -- Display warnings messages from `handler'.
67 do
68 -- For batch compilers etc, we report the errors last to ensure they are shown on the terminal
69 -- closes to the next operation.
70 if a_handler.has_warning then
71 trace_warnings (a_handler)
72 end
73 if a_handler.has_error then
74 trace_errors (a_handler)
75 end
76 end
77
78 trace_warnings (a_handler: ERROR_HANDLER)
79 -- Display warnings messages from `handler'.
80 local
81 l_warnings: LIST [ERROR]
82 do
83 l_warnings := a_handler.warning_list
84 if not l_warnings.is_empty then
85 l_warnings.do_all (agent (a_item: ERROR)
86 require
87 a_item_attached: a_item /= Void
88 do
89 display_warning ({WARNING} #? a_item, output_window)
90 end)
91 output_window.put_new_line
92 end
93 end
94
95 trace_errors (a_handler: ERROR_HANDLER)
96 -- Display error messages from `handler'.
97 do
98 if a_handler.has_error then
99 a_handler.error_list.do_all (agent display_error (?, output_window))
100 output_window.put_new_line
101 end
102 end
103
104 force_display
105 -- Make sure the user can see the messages we send.
106 do
107 output_window.display
108 end
109
110 feature {NONE} -- Implementation
111
112 display_warning (a_warning: WARNING; a_window: like output_window)
113 -- Display warning `a_warning' using output window `a_window'
114 require
115 a_warning_attached: a_warning /= Void
116 a_window_attached: a_window /= Void
117 do
118 display_error (a_warning, a_window)
119 end
120
121 display_error (a_error: ERROR; a_window: like output_window)
122 -- Display error `a_error' using output window `a_window'
123 require
124 a_error_attached: a_error /= Void
125 a_window_attached: a_window /= Void
126 local
127 l_se: SYNTAX_ERROR
128 l_code: INTEGER
129 l_file: PLAIN_TEXT_FILE
130 l_parse_error: CONF_ERROR_PARSE
131 l_line: STRING
132 l_pos: INTEGER
133 do
134 l_se ?= a_error
135 a_window.put_new_line
136
137 -- Context
138 if a_error.has_associated_file then
139 a_window.put_string (relative_file_path (a_error.file_name))
140 a_window.put_string ("(")
141 a_window.put_string (a_error.column.out)
142 a_window.put_string (", ")
143 a_window.put_string (a_error.line.out)
144 a_window.put_string (")")
145 else
146 a_window.put_string (application_name)
147 l_parse_error ?= a_error
148 if l_parse_error /= Void then
149 a_window.put_string ("(")
150 a_window.put_string (l_parse_error.column.out)
151 a_window.put_string (", ")
152 a_window.put_string (l_parse_error.row.out)
153 a_window.put_string (")")
154 end
155 end
156
157 -- Code
158 a_window.put_string (" : ")
159 a_window.put_string (a_error.error_string)
160 a_window.put_string (" ")
161 if l_se = Void then
162 a_window.put_string (a_error.code.as_upper)
163 else
164 a_window.put_string ("SYNTAX")
165 end
166 l_code := a_error.subcode
167 if l_code > 0 then
168 a_window.put_string (l_code.out)
169 end
170
171 -- Description
172 create l_file.make_with_path (short_help_file_name (a_error))
173 if l_file.exists and not l_file.is_empty then
174 a_window.put_string (": ")
175
176 -- Read file to extract short description
177 l_file.open_read
178 l_file.read_line
179 l_line := l_file.last_string
180 if l_line /= Void and then not l_line.is_empty then
181 l_pos := l_line.index_of (':', 1)
182 if l_pos > 0 then
183 -- Remove prefix
184 l_line.keep_tail (l_line.count - l_pos)
185 l_line.prune_all_leading (' ')
186 l_line.prune_all_trailing (' ')
187 end
188 if not l_line.is_empty then
189 l_line.put (l_line.item (1).as_upper, 1)
190 a_window.put_string (l_line)
191 end
192 end
193 l_file.close
194 end
195
196 a_window.put_new_line
197 tracer.trace_context (a_window, a_error)
198 end
199
200 short_help_file_name (a_error: ERROR): PATH
201 -- Retrieve's short help file name from `a_error'
202 do
203 Result := eiffel_layout.error_path.extended ("short").extended (a_error.help_file_name)
204 if a_error.subcode /= 0 then
205 Result := Result.appended (a_error.subcode.out)
206 end
207 ensure
208 result_attached: Result /= Void
209 not_result_is_empty: not Result.is_empty
210 end
211
212 relative_file_path (a_path: READABLE_STRING_GENERAL): READABLE_STRING_GENERAL
213 -- Retrieve relative file path to project ECF.
214 local
215 l_project: E_PROJECT
216 l_dir: READABLE_STRING_32
217 l_count: INTEGER
218 l_pos: INTEGER
219 do
220 l_project := shared_project.eiffel_project
221 l_dir := l_project.project_directory.path.name.as_lower
222 l_count := l_dir.count
223 if l_count < a_path.count + 1 then
224 l_pos := a_path.as_lower.substring_index (l_dir, 1)
225 if l_pos = 1 then
226 Result := a_path.substring (l_count + 2, a_path.count)
227 end
228 end
229 if Result = Void then
230 Result := a_path
231 end
232 ensure
233 result_attached: Result /= Void
234 not_result_is_empty: not Result.is_empty
235 end
236
237 feature {NONE} -- Implementation
238
239 shared_project: SHARED_EIFFEL_PROJECT
240 -- Access to shared Eiffel project
241 once
242 create Result
243 ensure
244 result_attached: Result /= Void
245 end
246
247 eiffel_layout: EIFFEL_ENV
248 -- Access to shared Eiffel project
249 once
250 Result := (create {EIFFEL_LAYOUT}).eiffel_layout
251 ensure
252 result_attached: Result /= Void
253 end
254
255 invariant
256 application_name_attached: application_name /= Void
257 not_application_name_is_empty: not application_name.is_empty
258
259 note
260 copyright: "Copyright (c) 1984-2013, Eiffel Software"
261 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
262 licensing_options: "http://www.eiffel.com/licensing"
263 copying: "[
264 This file is part of Eiffel Software's Eiffel Development Environment.
265
266 Eiffel Software's Eiffel Development Environment is free
267 software; you can redistribute it and/or modify it under
268 the terms of the GNU General Public License as published
269 by the Free Software Foundation, version 2 of the License
270 (available at the URL listed under "license" above).
271
272 Eiffel Software's Eiffel Development Environment is
273 distributed in the hope that it will be useful, but
274 WITHOUT ANY WARRANTY; without even the implied warranty
275 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
276 See the GNU General Public License for more details.
277
278 You should have received a copy of the GNU General Public
279 License along with Eiffel Software's Eiffel Development
280 Environment; if not, write to the Free Software Foundation,
281 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
282 ]"
283 source: "[
284 Eiffel Software
285 5949 Hollister Ave., Goleta, CA 93117 USA
286 Telephone 805-685-1006, Fax 805-685-6869
287 Website http://www.eiffel.com
288 Customer support http://support.eiffel.com
289 ]"
290 end -- class {ECL_ERROR_DISPLAYER}

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23