Changeset 8753 in josm for trunk/src/org
- Timestamp:
- 2015-09-13T16:36:09+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
r8510 r8753 71 71 public static final String SPELL_FILE = "resource://data/validator/words.cfg"; 72 72 73 /** The spell check key substitutions: the key should be substituted by the value */74 private static volatileMap<String, String>spellCheckKeyData;73 /** Normalized keys: the key should be substituted by the value if the key was not found in presets */ 74 private static final Map<String, String> harmonizedKeys = new HashMap<>(); 75 75 /** The spell check preset values */ 76 76 private static volatile MultiMap<String, String> presetsValueData; … … 126 126 protected static final int LOW_CHAR_KEY = 1211; 127 127 protected static final int MISSPELLED_VALUE = 1212; 128 protected static final int MISSPELLED_KEY = 1213; 128 129 /** 1250 and up is used by tagcheck */ 129 130 … … 161 162 ignoreDataEndsWith.clear(); 162 163 ignoreDataKeyPair.clear(); 163 164 spellCheckKeyData = new HashMap<>(); 164 harmonizedKeys.clear(); 165 165 166 166 String errorSources = ""; … … 229 229 okValue = line.substring(1); 230 230 } else if (line.charAt(0) == '-' && okValue != null) { 231 spellCheckKeyData.put(line.substring(1), okValue);231 harmonizedKeys.put(harmonizeKey(line.substring(1)), okValue); 232 232 } else { 233 233 Main.error(tr("Invalid spellcheck line: {0}", line)); … … 291 291 try { 292 292 presetsValueData.putAll(ky.key, values); 293 harmonizedKeys.put(harmonizeKey(ky.key), ky.key); 293 294 } catch (NullPointerException e) { 294 295 Main.error(p+": Unable to initialize "+ky); … … 360 361 withErrors.put(p, "EV"); 361 362 } 362 if (checkKeys && spellCheckKeyData.containsKey(key) && !withErrors.contains(p, "IPK")) {363 errors.add(new TestError(this, Severity.WARNING, tr("Invalid property key"),364 tr(s, key), MessageFormat.format(s, key), INVALID_KEY, p));365 withErrors.put(p, "IPK");366 }367 363 if (checkKeys && key != null && key.indexOf(' ') >= 0 && !withErrors.contains(p, "IPK")) { 368 364 errors.add(new TestError(this, Severity.WARNING, tr("Invalid white space in property key"), … … 412 408 if (!ignore) { 413 409 if (!keyInPresets) { 414 String i = marktr("Key ''{0}'' not in presets."); 415 errors.add(new TestError(this, Severity.OTHER, tr("Presets do not contain property key"), 416 tr(i, key), MessageFormat.format(i, key), INVALID_VALUE, p)); 417 withErrors.put(p, "UPK"); 410 String prettifiedKey = harmonizeKey(key); 411 String fixedKey = harmonizedKeys.get(prettifiedKey); 412 if (fixedKey != null && !"".equals(fixedKey)) { 413 // misspelled preset key 414 String i = marktr("Key ''{0}'' looks like ''{1}''."); 415 errors.add(new FixableTestError(this, Severity.WARNING, tr("Misspelled property key"), 416 tr(i, key, fixedKey), 417 MessageFormat.format(i, key, fixedKey), MISSPELLED_KEY, p, 418 new ChangePropertyKeyCommand(p, key, fixedKey))); 419 withErrors.put(p, "WPK"); 420 } else { 421 String i = marktr("Key ''{0}'' not in presets."); 422 errors.add(new TestError(this, Severity.OTHER, tr("Presets do not contain property key"), 423 tr(i, key), MessageFormat.format(i, key), INVALID_VALUE, p)); 424 withErrors.put(p, "UPK"); 425 } 418 426 } else if (!tagInPresets) { 419 427 // try to fix common typos and check again if value is still unknown 420 String fixedValue = prettifyValue(prop.getValue());428 String fixedValue = harmonizeValue(prop.getValue()); 421 429 Map<String, String> possibleValues = getPossibleValues(values); 422 430 if (possibleValues.containsKey(fixedValue)) { … … 465 473 } 466 474 467 private static String prettifyValue(String value) { 468 // convert to lower case, replace ' ' or '-' with '_' 475 private static String harmonizeKey(String key) { 476 key = key.toLowerCase(Locale.ENGLISH).replace('-', '_').replace(':', '_').replace(' ', '_'); 477 return Utils.strip(key, "-_;:,"); 478 } 479 480 private static String harmonizeValue(String value) { 469 481 value = value.toLowerCase(Locale.ENGLISH).replace('-', '_').replace(' ', '_'); 470 // remove trailing or leading special chars471 482 return Utils.strip(value, "-_;:,"); 472 483 } … … 612 623 if (!evalue.equals(value)) { 613 624 commands.add(new ChangePropertyCommand(p, key, evalue)); 614 } else {615 String replacementKey = spellCheckKeyData.get(key);616 if (replacementKey != null) {617 commands.add(new ChangePropertyKeyCommand(p, key, replacementKey));618 }619 625 } 620 626 }
Note:
See TracChangeset
for help on using the changeset viewer.