Changeset 6601 in josm for trunk/src/org
- Timestamp:
- 2014-01-02T23:58:58+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r6591 r6601 23 23 import org.openstreetmap.josm.command.Command; 24 24 import org.openstreetmap.josm.command.SequenceCommand; 25 import org.openstreetmap.josm.data.osm.Node;26 25 import org.openstreetmap.josm.data.osm.OsmPrimitive; 27 import org.openstreetmap.josm.data.osm.Relation;28 26 import org.openstreetmap.josm.data.osm.Tag; 29 import org.openstreetmap.josm.data.osm.Way;30 27 import org.openstreetmap.josm.data.preferences.CollectionProperty; 31 28 import org.openstreetmap.josm.data.validation.FixableTestError; … … 34 31 import org.openstreetmap.josm.data.validation.TestError; 35 32 import org.openstreetmap.josm.gui.mappaint.Environment; 33 import org.openstreetmap.josm.gui.mappaint.MultiCascade; 36 34 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition; 37 35 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression; … … 68 66 69 67 static class TagCheck implements Predicate<OsmPrimitive> { 70 protected final List<Selector> selector;68 protected final MapCSSRule rule; 71 69 protected final List<PrimitiveToTag> change = new ArrayList<PrimitiveToTag>(); 72 70 protected final Map<String, String> keyChange = new LinkedHashMap<String, String>(); … … 75 73 protected final Map<String, Boolean> assertions = new HashMap<String, Boolean>(); 76 74 77 TagCheck( List<Selector> selector) {78 this. selector = selector;75 TagCheck(MapCSSRule rule) { 76 this.rule = rule; 79 77 } 80 78 … … 113 111 114 112 static TagCheck ofMapCSSRule(final MapCSSRule rule) { 115 final TagCheck check = new TagCheck(rule.selectors); 113 final TagCheck check = new TagCheck(rule); 114 boolean containsSetClassExpression = false; 116 115 for (Instruction i : rule.declaration) { 117 116 if (i instanceof Instruction.AssignmentInstruction) { … … 142 141 } else if ("assertNoMatch".equals(ai.key) && val != null) { 143 142 check.assertions.put(val, false); 143 } else if (ai.val instanceof Boolean && ((Boolean) ai.val)) { 144 containsSetClassExpression = true; 144 145 } else { 145 146 throw new RuntimeException("Cannot add instruction " + ai.key + ": " + ai.val + "!"); … … 147 148 } 148 149 } 149 if (check.errors.isEmpty() ) {150 if (check.errors.isEmpty() && !containsSetClassExpression) { 150 151 throw new RuntimeException("No throwError/throwWarning/throwOther given! You should specify a validation error message for " + rule.selectors); 151 152 } else if (check.errors.size() > 1) { … … 183 184 * @param primitive the primitive to test 184 185 * @return true when the primitive contains a deprecated tag 185 */ 186 * @deprecated since it does not handle MapCSS-classes 187 */ 188 @Deprecated 186 189 boolean matchesPrimitive(OsmPrimitive primitive) { 187 190 return whichSelectorMatchesPrimitive(primitive) != null; … … 189 192 190 193 Selector whichSelectorMatchesPrimitive(OsmPrimitive primitive) { 191 final Environment env = new Environment().withPrimitive(primitive); 192 for (Selector i : selector) { 194 return whichSelectorMatchesEnvironment(new Environment().withPrimitive(primitive)); 195 } 196 197 Selector whichSelectorMatchesEnvironment(Environment env) { 198 for (Selector i : rule.selectors) { 199 env.clearSelectorMatchingInformation(); 193 200 if (i.matches(env)) { 194 201 return i; … … 318 325 */ 319 326 TestError getErrorForPrimitive(OsmPrimitive p) { 320 final Selector matchingSelector = whichSelectorMatchesPrimitive(p); 321 if (matchingSelector != null) { 327 return getErrorForPrimitive(p, whichSelectorMatchesPrimitive(p)); 328 } 329 330 TestError getErrorForPrimitive(OsmPrimitive p, Selector matchingSelector) { 331 if (matchingSelector != null && !errors.isEmpty()) { 322 332 final Command fix = fixPrimitive(p); 323 333 final String description = getDescriptionForMatchingSelector(matchingSelector); … … 331 341 } 332 342 } 343 } 344 345 static class MapCSSTagCheckerAndRule extends MapCSSTagChecker { 346 public final MapCSSRule rule; 347 348 MapCSSTagCheckerAndRule(MapCSSRule rule) { 349 this.rule = rule; 350 } 351 352 @Override 353 public boolean equals(Object obj) { 354 return super.equals(obj) 355 || (obj instanceof TagCheck && rule.equals(((TagCheck) obj).rule)) 356 || (obj instanceof MapCSSRule && rule.equals(obj)); 357 } 358 } 359 360 /** 361 * Obtains all {@link TestError}s for the {@link OsmPrimitive} {@code p}. 362 */ 363 public Collection<TestError> getErrorsForPrimitive(OsmPrimitive p) { 364 final ArrayList<TestError> r = new ArrayList<TestError>(); 365 final Environment env = new Environment(p, new MultiCascade(), Environment.DEFAULT_LAYER, null); 366 for (TagCheck check : checks) { 367 final Selector selector = check.whichSelectorMatchesEnvironment(env); 368 if (selector != null) { 369 check.rule.execute(env); 370 final TestError error = check.getErrorForPrimitive(p, selector); 371 if (error != null) { 372 error.setTester(new MapCSSTagCheckerAndRule(check.rule)); 373 r.add(error); 374 } 375 } 376 } 377 return r; 333 378 } 334 379 … … 340 385 @Override 341 386 public void check(OsmPrimitive p) { 342 for (TagCheck check : checks) { 343 final TestError error = check.getErrorForPrimitive(p); 344 if (error != null) { 345 error.setTester(this); 346 errors.add(error); 347 } 348 } 387 errors.addAll(getErrorsForPrimitive(p)); 349 388 } 350 389 -
trunk/src/org/openstreetmap/josm/gui/mappaint/Environment.java
r6175 r6601 21 21 public StyleSource source; 22 22 private Context context = Context.PRIMITIVE; 23 public static final String DEFAULT_LAYER = "default"; 23 24 24 25 /** -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
r6579 r6601 291 291 @Override 292 292 public boolean applies(Environment env) { 293 return not ^ env.mc.getCascade(env.layer).containsKey(id);293 return env != null && env.mc != null && env.mc.getCascade(env.layer) != null && not ^ env.mc.getCascade(env.layer).containsKey(id); 294 294 } 295 295
Note:
See TracChangeset
for help on using the changeset viewer.