Révision 1309
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/NormalizeKeys.java (revision 1309) | ||
---|---|---|
28 | 28 |
/** |
29 | 29 |
* Keys matching this REGEX will be preserved. |
30 | 30 |
*/ |
31 |
public static String preserve = "^(common_|error_|info_).*$"; |
|
31 |
public static String preserve = "^(common_|error_|info_|RESULT_TYPE).*$";
|
|
32 | 32 |
|
33 | 33 |
/** |
34 |
* Java keywords that can not be used as variable name. |
|
35 |
* Also can not start by a number |
|
36 |
*/ |
|
37 |
public static String illegalJavaStartingStr = "^([0-9]|abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|extends|false|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|native|new|null|package|private|protected|public|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|transient|true|try|void|volatile|while).*$"; |
|
38 |
|
|
39 |
/** |
|
34 | 40 |
* |
35 | 41 |
* @param debug show lot of debug messages |
36 | 42 |
*/ |
... | ... | |
127 | 133 |
return n; |
128 | 134 |
} |
129 | 135 |
|
130 |
// /** |
|
131 |
// * Normalizes the keys of the specified messages map. |
|
132 |
// * @param messages |
|
133 |
// * @return |
|
134 |
// */ |
|
135 |
// public BiHashMap<String, String> normalize(BiHashMap<String, String> messages) { |
|
136 |
// |
|
137 |
// for (String key : messages.getKeys()) { |
|
138 |
// String value = messages.get(key); |
|
139 |
// |
|
140 |
// // already formatted message |
|
141 |
// if(key.matches(preserve)) { |
|
142 |
// System.err.println("NormalizeKeys.normalize(): warning: skipped: " + key + "=" + value); |
|
143 |
// continue; |
|
144 |
// } |
|
145 |
// // empty message |
|
146 |
// else if(value.length() == 0) { |
|
147 |
// System.err.println("NormalizeKeys.normalize(): warning: empty string for key: " + key); |
|
148 |
// continue; |
|
149 |
// } |
|
150 |
// |
|
151 |
// messages.put(normalize(messages.get(key)), messages.get(key)); |
|
152 |
// //messages.removeByKey(key); |
|
153 |
// } |
|
154 |
// |
|
155 |
// return messages; |
|
156 |
// } |
|
157 |
// |
|
158 |
|
|
159 | 136 |
/** |
160 | 137 |
* Normalizes the specified string. |
161 | 138 |
* @param str |
... | ... | |
169 | 146 |
|
170 | 147 |
str = str.trim(); |
171 | 148 |
|
149 |
// replace the parameters binding |
|
150 |
str = str.replaceAll("(\\{[0-9]})", "P$1"); |
|
151 |
|
|
172 | 152 |
// special replacements |
173 | 153 |
str = str.replaceAll("%", "percent"); |
174 | 154 |
|
... | ... | |
178 | 158 |
// empty string |
179 | 159 |
if(str.length() == 0) { |
180 | 160 |
System.err.println("NormalizeKeys.normalize(): warning: empty string."); |
161 |
str = "_"; |
|
181 | 162 |
} |
182 | 163 |
else { |
183 | 164 |
|
... | ... | |
213 | 194 |
str = tmpString; |
214 | 195 |
} |
215 | 196 |
|
197 |
// java variable can not start by a number |
|
198 |
if(str.matches(illegalJavaStartingStr)) { |
|
199 |
str = "_" + str; |
|
200 |
} |
|
201 |
|
|
216 | 202 |
// log |
217 | 203 |
if(debug) { |
218 | 204 |
System.out.println(" => " + str); |
... | ... | |
282 | 268 |
// System.out.println("Done: no change."); |
283 | 269 |
// } |
284 | 270 |
|
285 |
WorkspaceMessagesManager wmm = new WorkspaceMessagesManager(false); |
|
271 |
// WorkspaceMessagesManager wmm = new WorkspaceMessagesManager(false); |
|
272 |
// |
|
273 |
// for (PluginMessagesManager pmManager : wmm.getPluginMessages().values()) { |
|
274 |
// File projectFile = pmManager.getProjectDirectory(); |
|
275 |
// if (!projectFile.getName().equals("org.txm.ahc.core")) continue; |
|
276 |
// |
|
277 |
// keysNormalizer.normalize(pmManager); |
|
278 |
// |
|
279 |
// pmManager.saveChanges(true); // mode homme |
|
280 |
// //pmManager.saveChanges(false); |
|
281 |
// } |
|
282 |
// |
|
283 |
// wmm.saveKeyModificationsInSources(); |
|
286 | 284 |
|
287 |
for (PluginMessagesManager pmManager : wmm.getPluginMessages().values()) { |
|
288 |
File projectFile = pmManager.getProjectDirectory(); |
|
289 |
if (!projectFile.getName().equals("org.txm.ahc.core")) continue; |
|
285 |
//File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.core"); |
|
286 |
File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.cooccurrence.core"); |
|
287 |
PluginMessagesManager pmManager = new PluginMessagesManager(projectFile, true); |
|
288 |
keysNormalizer.normalize(pmManager); |
|
290 | 289 |
|
291 | 290 |
keysNormalizer.normalize(pmManager); |
292 | 291 |
|
... | ... | |
294 | 293 |
//pmManager.saveChanges(false); |
295 | 294 |
} |
296 | 295 |
|
297 |
wmm.saveKeyModificationsInSources(); |
|
298 |
|
|
299 |
} |
|
300 | 296 |
} |
Formats disponibles : Unified diff