- Timestamp:
- 2014-12-24T15:30:06+01:00 (10 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
r7879 r7881 14 14 import java.util.Collections; 15 15 import java.util.HashMap; 16 import java.util.HashSet; 16 17 import java.util.Iterator; 17 18 import java.util.LinkedHashMap; … … 42 43 import org.openstreetmap.josm.gui.mappaint.MultiCascade; 43 44 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition; 45 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.ClassCondition; 44 46 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression; 45 47 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction; … … 48 50 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 49 51 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector; 52 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.AbstractSelector; 50 53 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector; 51 54 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser; … … 147 150 protected final Map<Instruction.AssignmentInstruction, Severity> errors = new HashMap<>(); 148 151 protected final Map<String, Boolean> assertions = new HashMap<>(); 152 protected final Set<String> setClassExpressions = new HashSet<>(); 149 153 protected boolean deletion = false; 150 154 … … 207 211 static TagCheck ofMapCSSRule(final GroupedMapCSSRule rule) throws IllegalDataException { 208 212 final TagCheck check = new TagCheck(rule); 209 boolean containsSetClassExpression = false;210 213 for (Instruction i : rule.declaration.instructions) { 211 214 if (i instanceof Instruction.AssignmentInstruction) { 212 215 final Instruction.AssignmentInstruction ai = (Instruction.AssignmentInstruction) i; 213 216 if (ai.isSetInstruction) { 214 c ontainsSetClassExpression= true;217 check.setClassExpressions.add(ai.key); 215 218 continue; 216 219 } … … 263 266 } 264 267 } 265 if (check.errors.isEmpty() && !containsSetClassExpression) { 266 throw new IllegalDataException("No "+POSSIBLE_THROWS+" given! You should specify a validation error message for " + rule.selectors); 268 if (check.errors.isEmpty() && check.setClassExpressions.isEmpty()) { 269 throw new IllegalDataException( 270 "No "+POSSIBLE_THROWS+" given! You should specify a validation error message for " + rule.selectors); 267 271 } else if (check.errors.size() > 1) { 268 throw new IllegalDataException("More than one "+POSSIBLE_THROWS+" given! You should specify a single validation error message for " + rule.selectors); 272 throw new IllegalDataException( 273 "More than one "+POSSIBLE_THROWS+" given! You should specify a single validation error message for " 274 + rule.selectors); 269 275 } 270 276 return check; … … 506 512 return null; 507 513 } 514 } 515 516 /** 517 * Returns the set of tagchecks on which this check depends on. 518 * @param schecks the collection of tagcheks to search in 519 * @return the set of tagchecks on which this check depends on 520 * @since 7881 521 */ 522 public Set<TagCheck> getTagCheckDependencies(Collection<TagCheck> schecks) { 523 Set<TagCheck> result = new HashSet<MapCSSTagChecker.TagCheck>(); 524 Set<String> classes = getClassesIds(); 525 if (schecks != null && !classes.isEmpty()) { 526 for (TagCheck tc : schecks) { 527 if (this.equals(tc)) { 528 continue; 529 } 530 for (String id : tc.setClassExpressions) { 531 if (classes.contains(id)) { 532 result.add(tc); 533 break; 534 } 535 } 536 } 537 } 538 return result; 539 } 540 541 /** 542 * Returns the list of ids of all MapCSS classes referenced in the rule selectors. 543 * @return the list of ids of all MapCSS classes referenced in the rule selectors 544 * @since 7881 545 */ 546 public Set<String> getClassesIds() { 547 Set<String> result = new HashSet<>(); 548 for (Selector s : rule.selectors) { 549 if (s instanceof AbstractSelector) { 550 for (Condition c : ((AbstractSelector)s).getConditions()) { 551 if (c instanceof ClassCondition) { 552 result.add(((ClassCondition) c).id); 553 } 554 } 555 } 556 } 557 return result; 508 558 } 509 559 } … … 654 704 } 655 705 final OsmPrimitive p = OsmUtils.createPrimitive(i.getKey()); 706 // Build minimal ordered list of checks to run to test the assertion 707 List<Set<TagCheck>> checksToRun = new ArrayList<Set<TagCheck>>(); 708 Set<TagCheck> checkDependencies = check.getTagCheckDependencies(schecks); 709 if (!checkDependencies.isEmpty()) { 710 checksToRun.add(checkDependencies); 711 } 712 checksToRun.add(Collections.singleton(check)); 656 713 // Add primitive to dataset to avoid DataIntegrityProblemException when evaluating selectors 657 714 ds.addPrimitive(p); 658 final Collection<TestError> pErrors = getErrorsForPrimitive(p, true, 659 Collections.singleton(Collections.singleton(check))); 715 final Collection<TestError> pErrors = getErrorsForPrimitive(p, true, checksToRun); 660 716 if (Main.isDebugEnabled()) { 661 717 Main.debug("- Errors: "+pErrors); -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java
r7397 r7881 87 87 @Override 88 88 public String toString() { 89 return key + ": " + (val instanceof float[] ? Arrays.toString((float[]) val) : val instanceof String ? "String<"+val+">" : val) + ';'; 89 return key + ": " + (val instanceof float[] ? Arrays.toString((float[]) val) : 90 val instanceof String ? "String<"+val+">" : val) + ';'; 90 91 } 91 92 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r7864 r7881 428 428 } 429 429 430 /** 431 * Returns the list of conditions. 432 * @return the list of conditions 433 */ 430 434 public List<Condition> getConditions() { 431 435 if (conds == null) {
Note:
See TracChangeset
for help on using the changeset viewer.