/[eiffelstudio]/branches/Eiffel_57_docking/Src/Eiffel/interface/new_graphical/case_tool/helper/class_name_replacer.e
ViewVC logotype

Contents of /branches/Eiffel_57_docking/Src/Eiffel/interface/new_graphical/case_tool/helper/class_name_replacer.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62171 - (show annotations)
Tue Aug 1 01:27:17 2006 UTC (13 years, 4 months ago) by larryl
File size: 6843 byte(s)
First commit docking tabbed Eiffel Studio.
1 indexing
2 description: "[
3 Facility for changing a class name globally.
4 Note: Will not replace class names in strings and comments.
5 ]"
6 legal: "See notice at end of class."
7 status: "See notice at end of class."
8 date: "$Date$"
9 revision: "$Revision$"
10
11 class
12 CLASS_NAME_REPLACER
13
14 inherit
15 SHARED_EIFFEL_PROJECT
16
17 SHARED_API_ROUTINES
18
19 EB_SHARED_INTERFACE_TOOLS
20
21 EV_SHARED_APPLICATION
22
23 feature -- Search and replace
24
25 global_class_name_replace (a_search_string, a_replace_string: STRING; compiled_classes_only: BOOLEAN; a_status_bar: EB_DEVELOPMENT_WINDOW_STATUS_BAR) is
26 -- Replace in all compiled classes in the system all class name
27 -- `a_search_string' occurrences of `a_search_string' with `a_replace_string'.
28 -- Outputted messages are performed via `a_status_bar'.
29 require
30 a_search_string_not_void: a_search_string /= Void
31 a_replace_string_not_void: a_replace_string /= Void
32 local
33 cl: DS_HASH_SET [CLASS_I]
34 l_changed_count: INTEGER
35 l_ctm: CLASS_TEXT_MODIFIER
36 l_index: INTEGER
37 l_class: CLASS_I
38 do
39 cl := eiffel_universe.all_classes
40 a_status_bar.reset_progress_bar_with_range (0 |..| cl.count)
41
42 from
43 cl.start
44 l_index := 0
45 until
46 cl.after
47 loop
48 l_class := cl.item_for_iteration
49 a_status_bar.display_progress_value (l_index)
50 if not l_class.is_read_only and then (not compiled_classes_only or else l_class.compiled) then
51 l_ctm := search_replace_modifier (l_class, a_search_string, a_replace_string)
52 if l_ctm /= Void then
53 l_ctm.commit_modification
54 a_status_bar.display_message (l_class.name_in_upper + " updated, continuing search and replace")
55 l_changed_count := l_changed_count + 1
56 end
57 end
58 l_index := l_index + 1
59 cl.forth
60 process_events_and_idle
61 end
62 a_status_bar.reset_progress_bar_with_range (0 |..| 100)
63 if l_changed_count > 1 then
64 a_status_bar.display_message (l_changed_count.out + " classes updated")
65 elseif l_changed_count = 1 then
66 a_status_bar.display_message (l_changed_count.out + " class updated")
67 else
68 a_status_bar.display_message ("0 classes updated")
69 end
70 end
71
72 feature -- Status report
73
74 valid_new_class_name (a_name: STRING): BOOLEAN is
75 -- Is `a_name' valid for a new class name or generic?
76 require
77 a_name_not_void: a_name /= Void
78 do
79 Result := (create {IDENTIFIER_CHECKER}).is_valid (a_name)
80 --| FIXME May not be a formal generic in any of the classes involved.
81 end
82
83 class_name_in_use (a_name: STRING): BOOLEAN is
84 -- Is `a_name' already used in the system?
85 do
86 Result := class_i_by_name (a_name) /= Void
87 end
88
89 feature {NONE} -- Implementation
90
91 search_replace_modifier (a_class: CLASS_I; a_search_string, a_replace_string: STRING): CLASS_TEXT_MODIFIER is
92 -- Replace in `a_class' all class name occurrences of
93 -- `a_search_string' with `a_replace_string'.
94 -- Call 'commit_modification' on `Result' to update class text.
95 -- If result is Void then no text has to be modified.
96 local
97 ctm: CLASS_TEXT_MODIFIER
98 click_list: CLICK_LIST
99 click_item: CLICK_AST
100 class_as: CLASS_AS
101 cl_type_as: CLASS_TYPE_AS
102 s: STRING
103 cur_disp, disp: INTEGER
104 is_occurrence_found: BOOLEAN
105 pr_type_as: PRECURSOR_AS
106 st, en: INTEGER
107 l_es_class: ES_CLASS
108 l_classes: ARRAYED_LIST [ES_CLASS]
109 do
110 -- Even though we could have more than one development window open with a diagram in it,
111 -- we assume there is actually only one doing the diagraming. If there were more than one,
112 -- and that `a_class' is in the two window, then the undo/redo might not work properly
113 -- since we would have 2 CLASS_TEXT_MODIFIER instance.
114 if window_manager.a_development_window /= Void then
115 l_classes := window_manager.a_development_window.tools.diagram_tool.world.model.class_from_interface (a_class)
116 if not l_classes.is_empty then
117 l_es_class := l_classes.first
118 end
119 end
120 if l_es_class /= Void then
121 ctm := l_es_class.code_generator
122 else
123 create ctm.make (a_class)
124 end
125 ctm.prepare_for_modification
126 if ctm.valid_syntax then
127 click_list := ctm.class_as.click_list
128 disp := a_search_string.count - a_replace_string.count
129
130 from
131 click_list.start
132 until
133 click_list.after
134 loop
135 click_item := click_list.item
136 s := Void
137 if click_item.node.is_class then
138 cl_type_as ?= click_item.node
139 if cl_type_as /= Void then
140 s := cl_type_as.class_name
141 else
142 class_as ?= click_item.node
143 if class_as /= Void then
144 s := class_as.class_name
145 end
146 end
147 if s /= Void and then s.is_equal (a_search_string) then
148 ctm.replace_code (a_replace_string, click_item.start_position + cur_disp, click_item.end_position + cur_disp)
149 cur_disp := cur_disp - disp
150 is_occurrence_found := True
151 end
152 elseif click_item.node.is_precursor then
153 pr_type_as ?= click_item.node
154 if pr_type_as /= Void then
155 st := ctm.index_of ('{', click_item.start_position + cur_disp)
156 if st > 0 then
157 en := ctm.index_of ('}', st)
158 if en > 0 then
159 s := ctm.code (st + 1, en - 1)
160 if s.is_equal (a_search_string) then
161 ctm.replace_code (a_replace_string, st + 1, en - 1)
162 cur_disp := cur_disp - disp
163 is_occurrence_found := True
164 end
165 end
166 end
167 end
168 end
169
170 click_list.forth
171 end
172 if is_occurrence_found then
173 Result := ctm
174 end
175 end
176 end
177
178 indexing
179 copyright: "Copyright (c) 1984-2006, Eiffel Software"
180 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
181 licensing_options: "http://www.eiffel.com/licensing"
182 copying: "[
183 This file is part of Eiffel Software's Eiffel Development Environment.
184
185 Eiffel Software's Eiffel Development Environment is free
186 software; you can redistribute it and/or modify it under
187 the terms of the GNU General Public License as published
188 by the Free Software Foundation, version 2 of the License
189 (available at the URL listed under "license" above).
190
191 Eiffel Software's Eiffel Development Environment is
192 distributed in the hope that it will be useful, but
193 WITHOUT ANY WARRANTY; without even the implied warranty
194 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
195 See the GNU General Public License for more details.
196
197 You should have received a copy of the GNU General Public
198 License along with Eiffel Software's Eiffel Development
199 Environment; if not, write to the Free Software Foundation,
200 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
201 ]"
202 source: "[
203 Eiffel Software
204 356 Storke Road, Goleta, CA 93117 USA
205 Telephone 805-685-1006, Fax 805-685-6869
206 Website http://www.eiffel.com
207 Customer support http://support.eiffel.com
208 ]"
209
210 end -- class CLASS_NAME_REPLACER

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23