Changeset 6677 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r6675 r6677 74 74 protected final Map<String, String> keyChange = new LinkedHashMap<String, String>(); 75 75 protected final List<String> alternatives = new ArrayList<String>(); 76 protected final Map< String, Severity> errors = new HashMap<String, Severity>();76 protected final Map<Instruction.AssignmentInstruction, Severity> errors = new HashMap<Instruction.AssignmentInstruction, Severity>(); 77 77 protected final Map<String, Boolean> assertions = new HashMap<String, Boolean>(); 78 78 … … 131 131 if (ai.key.startsWith("throw")) { 132 132 final Severity severity = Severity.valueOf(ai.key.substring("throw".length()).toUpperCase()); 133 check.errors.put( val, severity);133 check.errors.put(ai, severity); 134 134 } else if ("fixAdd".equals(ai.key)) { 135 135 final PrimitiveToTag toTag = PrimitiveToTag.ofMapCSSObject(ai.val, false); … … 296 296 cmds.add(new ChangePropertyKeyCommand(p, oldKey, newKey)); 297 297 } 298 return new SequenceCommand(tr("Fix of {0}", getDescriptionForMatchingSelector( matchingSelector)), cmds);298 return new SequenceCommand(tr("Fix of {0}", getDescriptionForMatchingSelector(p, matchingSelector)), cmds); 299 299 } 300 300 … … 304 304 * @return a message 305 305 */ 306 String getMessage() { 307 return errors.isEmpty() ? null : errors.keySet().iterator().next(); 306 String getMessage(OsmPrimitive p) { 307 if (errors.isEmpty()) { 308 return null; 309 } else { 310 final Object val = errors.keySet().iterator().next().val; 311 return String.valueOf( 312 val instanceof Expression 313 ? ((Expression) val).evaluate(new Environment().withPrimitive(p)) 314 : val 315 ); 316 } 308 317 } 309 318 … … 312 321 * 313 322 * @return a description (possibly with alternative suggestions) 314 * @see #getDescriptionForMatchingSelector (Selector)315 */ 316 String getDescription( ) {323 * @see #getDescriptionForMatchingSelector 324 */ 325 String getDescription(OsmPrimitive p) { 317 326 if (alternatives.isEmpty()) { 318 return getMessage( );327 return getMessage(p); 319 328 } else { 320 329 /* I18N: {0} is the test error message and {1} is an alternative */ 321 return tr("{0}, use {1} instead", getMessage( ), Utils.join(tr(" or "), alternatives));330 return tr("{0}, use {1} instead", getMessage(p), Utils.join(tr(" or "), alternatives)); 322 331 } 323 332 } … … 329 338 * @return a description (possibly with alternative suggestions) 330 339 */ 331 String getDescriptionForMatchingSelector( Selector matchingSelector) {332 return insertArguments(matchingSelector, getDescription( ));340 String getDescriptionForMatchingSelector(OsmPrimitive p, Selector matchingSelector) { 341 return insertArguments(matchingSelector, getDescription(p)); 333 342 } 334 343 … … 339 348 @Override 340 349 public String toString() { 341 return getDescription( );350 return getDescription(null); 342 351 } 343 352 … … 355 364 if (matchingSelector != null && !errors.isEmpty()) { 356 365 final Command fix = fixPrimitive(p); 357 final String description = getDescriptionForMatchingSelector( matchingSelector);366 final String description = getDescriptionForMatchingSelector(p, matchingSelector); 358 367 if (fix != null) { 359 368 return new FixableTestError(null, getSeverity(), description, null, matchingSelector.toString(), 3000, p, fix); -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r6615 r6677 468 468 * and the subsequent arguments are parameters for the string indicated by {@code {0}}, {@code {1}}, … 469 469 */ 470 @NullableArguments 470 471 public static String tr(String... args) { 471 472 final String text = args[0]; -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java
r6636 r6677 38 38 final List<MapCSSTagChecker.TagCheck> checks = MapCSSTagChecker.TagCheck.readMapCSS(new StringReader("" + 39 39 "*[natural=marsh] {\n" + 40 " throwWarning: tr(\"{0} is deprecated\", \"{0.tag}\");\n" +40 " throwWarning: tr(\"{0}={1} is deprecated\", \"{0.key}\", tag(\"natural\"));\n" + 41 41 " fixRemove: \"{0.key}\";\n" + 42 42 " fixAdd: \"natural=wetland\";\n" + … … 46 46 final MapCSSTagChecker.TagCheck check = checks.get(0); 47 47 assertThat(check, notNullValue()); 48 assertThat(check.getDescription( ), is("{0.tag}is deprecated"));48 assertThat(check.getDescription(null), is("{0.key}=null is deprecated")); 49 49 assertThat(check.change.get(0).apply(null), is(new Tag("{0.key}"))); 50 50 assertThat(check.change.get(1).apply(null), is(new Tag("natural", "wetland"))); … … 83 83 if (isError != i.getValue()) { 84 84 final String error = MessageFormat.format("Expecting test ''{0}'' (i.e., {1}) to {2} {3} (i.e., {4})", 85 check.getMessage( ), check.rule.selectors, i.getValue() ? "match" : "not match", i.getKey(), p.getKeys());85 check.getMessage(p), check.rule.selectors, i.getValue() ? "match" : "not match", i.getKey(), p.getKeys()); 86 86 System.err.println(error); 87 87 assertionErrors.add(error);
Note:
See TracChangeset
for help on using the changeset viewer.