Changeset 17619 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2021-03-21T13:56:21+01:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/validation/tests
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r17499 r17619 10 10 import java.io.InputStream; 11 11 import java.io.Reader; 12 import java.io.StringReader;13 12 import java.util.ArrayList; 14 13 import java.util.Collection; … … 20 19 import java.util.Map.Entry; 21 20 import java.util.Objects; 22 import java.util.Optional;23 21 import java.util.Set; 24 22 import java.util.function.Consumer; 25 import java.util.function.Predicate;26 import java.util.regex.Matcher;27 import java.util.regex.Pattern;28 import java.util.stream.Collectors;29 23 import java.util.stream.Stream; 30 24 … … 32 26 import org.openstreetmap.josm.command.ChangePropertyKeyCommand; 33 27 import org.openstreetmap.josm.command.Command; 34 import org.openstreetmap.josm.command.DeleteCommand;35 import org.openstreetmap.josm.command.SequenceCommand;36 28 import org.openstreetmap.josm.data.osm.IPrimitive; 37 29 import org.openstreetmap.josm.data.osm.OsmPrimitive; 38 30 import org.openstreetmap.josm.data.osm.Tag; 39 import org.openstreetmap.josm.data.osm.Way;40 import org.openstreetmap.josm.data.osm.WaySegment;41 31 import org.openstreetmap.josm.data.preferences.sources.SourceEntry; 42 32 import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper; … … 46 36 import org.openstreetmap.josm.data.validation.TestError; 47 37 import org.openstreetmap.josm.gui.mappaint.Environment; 48 import org.openstreetmap.josm.gui.mappaint.Keyword;49 38 import org.openstreetmap.josm.gui.mappaint.MultiCascade; 50 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition;51 39 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression; 52 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;53 40 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule; 54 41 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleIndex; 55 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;56 42 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector; 57 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector;58 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser;59 43 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException; 60 44 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.TokenMgrError; … … 62 46 import org.openstreetmap.josm.io.CachedFile; 63 47 import org.openstreetmap.josm.io.FileWatcher; 64 import org.openstreetmap.josm.io.IllegalDataException;65 48 import org.openstreetmap.josm.io.UTFInputStreamReader; 66 49 import org.openstreetmap.josm.spi.preferences.Config; … … 103 86 /** 104 87 * Creates the fixing {@link Command} for the given primitive. The {@code matchingSelector} is used to evaluate placeholders 105 * (cf. {@link MapCSSTagChecker .TagCheck#insertArguments(Selector, String, OsmPrimitive)}).88 * (cf. {@link MapCSSTagCheckerRule#insertArguments(Selector, String, OsmPrimitive)}). 106 89 * @param p OSM primitive 107 90 * @param matchingSelector matching selector … … 136 119 return null; 137 120 } 138 return TagCheck.insertArguments(matchingSelector, s, p);121 return MapCSSTagCheckerRule.insertArguments(matchingSelector, s, p); 139 122 } 140 123 … … 192 175 public Command createCommand(OsmPrimitive p, Selector matchingSelector) { 193 176 return new ChangePropertyKeyCommand(p, 194 TagCheck.insertArguments(matchingSelector, oldKey, p),195 TagCheck.insertArguments(matchingSelector, newKey, p));177 MapCSSTagCheckerRule.insertArguments(matchingSelector, oldKey, p), 178 MapCSSTagCheckerRule.insertArguments(matchingSelector, newKey, p)); 196 179 } 197 180 … … 204 187 } 205 188 206 final MultiMap<String, TagCheck> checks = new MultiMap<>();189 final MultiMap<String, MapCSSTagCheckerRule> checks = new MultiMap<>(); 207 190 208 191 /** maps the source URL for a test to the title shown in the dialog where known */ … … 210 193 211 194 /** 212 * Result of {@link TagCheck#readMapCSS}195 * Result of {@link MapCSSTagCheckerRule#readMapCSS} 213 196 * @since 8936 214 197 */ 215 198 public static class ParseResult { 216 199 /** Checks successfully parsed */ 217 public final List< TagCheck> parseChecks;200 public final List<MapCSSTagCheckerRule> parseChecks; 218 201 /** Errors that occurred during parsing */ 219 202 public final Collection<Throwable> parseErrors; … … 224 207 * @param parseErrors Errors that occurred during parsing 225 208 */ 226 public ParseResult(List< TagCheck> parseChecks, Collection<Throwable> parseErrors) {209 public ParseResult(List<MapCSSTagCheckerRule> parseChecks, Collection<Throwable> parseErrors) { 227 210 this.parseChecks = parseChecks; 228 211 this.parseErrors = parseErrors; … … 230 213 } 231 214 232 /**233 * Tag check.234 */235 public static class TagCheck implements Predicate<OsmPrimitive> {236 /** The selector of this {@code TagCheck} */237 protected final MapCSSRule rule;238 /** Commands to apply in order to fix a matching primitive */239 protected final List<FixCommand> fixCommands;240 /** Tags (or arbitrary strings) of alternatives to be presented to the user */241 protected final List<String> alternatives;242 /** An {@link org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.AssignmentInstruction}-{@link Severity} pair.243 * Is evaluated on the matching primitive to give the error message. Map is checked to contain exactly one element. */244 protected final Map<Instruction.AssignmentInstruction, Severity> errors;245 /** MapCSS Classes to set on matching primitives */246 protected final Collection<String> setClassExpressions;247 /** Denotes whether the object should be deleted for fixing it */248 protected boolean deletion;249 /** A string used to group similar tests */250 protected String group;251 252 TagCheck(MapCSSRule rule) {253 this.rule = rule;254 this.fixCommands = new ArrayList<>();255 this.alternatives = new ArrayList<>();256 this.errors = new HashMap<>();257 this.setClassExpressions = new HashSet<>();258 }259 260 TagCheck(TagCheck check) {261 this.rule = check.rule;262 this.fixCommands = Utils.toUnmodifiableList(check.fixCommands);263 this.alternatives = Utils.toUnmodifiableList(check.alternatives);264 this.errors = Utils.toUnmodifiableMap(check.errors);265 this.setClassExpressions = Utils.toUnmodifiableList(check.setClassExpressions);266 this.deletion = check.deletion;267 this.group = check.group;268 }269 270 TagCheck toImmutable() {271 return new TagCheck(this);272 }273 274 private static final String POSSIBLE_THROWS = "throwError/throwWarning/throwOther";275 276 static TagCheck ofMapCSSRule(final MapCSSRule rule, AssertionConsumer assertionConsumer) throws IllegalDataException {277 final TagCheck check = new TagCheck(rule);278 final Map<String, Boolean> assertions = new HashMap<>();279 for (Instruction i : rule.declaration.instructions) {280 if (i instanceof Instruction.AssignmentInstruction) {281 final Instruction.AssignmentInstruction ai = (Instruction.AssignmentInstruction) i;282 if (ai.isSetInstruction) {283 check.setClassExpressions.add(ai.key);284 continue;285 }286 try {287 final String val = ai.val instanceof Expression288 ? Optional.ofNullable(((Expression) ai.val).evaluate(new Environment()))289 .map(Object::toString).map(String::intern).orElse(null)290 : ai.val instanceof String291 ? (String) ai.val292 : ai.val instanceof Keyword293 ? ((Keyword) ai.val).val294 : null;295 if ("throwError".equals(ai.key)) {296 check.errors.put(ai, Severity.ERROR);297 } else if ("throwWarning".equals(ai.key)) {298 check.errors.put(ai, Severity.WARNING);299 } else if ("throwOther".equals(ai.key)) {300 check.errors.put(ai, Severity.OTHER);301 } else if (ai.key.startsWith("throw")) {302 Logging.log(Logging.LEVEL_WARN,303 "Unsupported " + ai.key + " instruction. Allowed instructions are " + POSSIBLE_THROWS + '.', null);304 } else if ("fixAdd".equals(ai.key)) {305 check.fixCommands.add(FixCommand.fixAdd(ai.val));306 } else if ("fixRemove".equals(ai.key)) {307 CheckParameterUtil.ensureThat(!(ai.val instanceof String) || !(val != null && val.contains("=")),308 "Unexpected '='. Please only specify the key to remove in: " + ai);309 check.fixCommands.add(FixCommand.fixRemove(ai.val));310 } else if (val != null && "fixChangeKey".equals(ai.key)) {311 CheckParameterUtil.ensureThat(val.contains("=>"), "Separate old from new key by '=>'!");312 final String[] x = val.split("=>", 2);313 check.fixCommands.add(FixCommand.fixChangeKey(Utils.removeWhiteSpaces(x[0]), Utils.removeWhiteSpaces(x[1])));314 } else if (val != null && "fixDeleteObject".equals(ai.key)) {315 CheckParameterUtil.ensureThat("this".equals(val), "fixDeleteObject must be followed by 'this'");316 check.deletion = true;317 } else if (val != null && "suggestAlternative".equals(ai.key)) {318 check.alternatives.add(val);319 } else if (val != null && "assertMatch".equals(ai.key)) {320 assertions.put(val, Boolean.TRUE);321 } else if (val != null && "assertNoMatch".equals(ai.key)) {322 assertions.put(val, Boolean.FALSE);323 } else if (val != null && "group".equals(ai.key)) {324 check.group = val;325 } else if (ai.key.startsWith("-")) {326 Logging.debug("Ignoring extension instruction: " + ai.key + ": " + ai.val);327 } else {328 throw new IllegalDataException("Cannot add instruction " + ai.key + ": " + ai.val + '!');329 }330 } catch (IllegalArgumentException e) {331 throw new IllegalDataException(e);332 }333 }334 }335 if (check.errors.isEmpty() && check.setClassExpressions.isEmpty()) {336 throw new IllegalDataException(337 "No "+POSSIBLE_THROWS+" given! You should specify a validation error message for " + rule.selectors);338 } else if (check.errors.size() > 1) {339 throw new IllegalDataException(340 "More than one "+POSSIBLE_THROWS+" given! You should specify a single validation error message for "341 + rule.selectors);342 }343 if (assertionConsumer != null) {344 MapCSSTagCheckerAsserts.checkAsserts(check, assertions, assertionConsumer);345 }346 return check.toImmutable();347 }348 349 static ParseResult readMapCSS(Reader css) throws ParseException {350 return readMapCSS(css, null);351 }352 353 static ParseResult readMapCSS(Reader css, AssertionConsumer assertionConsumer) throws ParseException {354 CheckParameterUtil.ensureParameterNotNull(css, "css");355 356 final MapCSSStyleSource source = new MapCSSStyleSource("");357 final MapCSSParser preprocessor = new MapCSSParser(css, MapCSSParser.LexicalState.PREPROCESSOR);358 try (StringReader mapcss = new StringReader(preprocessor.pp_root(source))) {359 new MapCSSParser(mapcss, MapCSSParser.LexicalState.DEFAULT).sheet(source);360 }361 // Ignore "meta" rule(s) from external rules of JOSM wiki362 source.removeMetaRules();363 List<TagCheck> parseChecks = new ArrayList<>();364 for (MapCSSRule rule : source.rules) {365 try {366 parseChecks.add(TagCheck.ofMapCSSRule(rule, assertionConsumer));367 } catch (IllegalDataException e) {368 Logging.error("Cannot add MapCSS rule: "+e.getMessage());369 source.logError(e);370 }371 }372 return new ParseResult(parseChecks, source.getErrors());373 }374 375 @Override376 public boolean test(OsmPrimitive primitive) {377 // Tests whether the primitive contains a deprecated tag which is represented by this MapCSSTagChecker.378 return whichSelectorMatchesPrimitive(primitive) != null;379 }380 381 Selector whichSelectorMatchesPrimitive(OsmPrimitive primitive) {382 return whichSelectorMatchesEnvironment(new Environment(primitive));383 }384 385 Selector whichSelectorMatchesEnvironment(Environment env) {386 return rule.selectors.stream()387 .filter(i -> i.matches(env.clearSelectorMatchingInformation()))388 .findFirst()389 .orElse(null);390 }391 392 /**393 * Determines the {@code index}-th key/value/tag (depending on {@code type}) of the394 * {@link GeneralSelector}.395 * @param matchingSelector matching selector396 * @param index index397 * @param type selector type ("key", "value" or "tag")398 * @param p OSM primitive399 * @return argument value, can be {@code null}400 */401 static String determineArgument(GeneralSelector matchingSelector, int index, String type, OsmPrimitive p) {402 try {403 final Condition c = matchingSelector.getConditions().get(index);404 final Tag tag = c instanceof Condition.ToTagConvertable405 ? ((Condition.ToTagConvertable) c).asTag(p)406 : null;407 if (tag == null) {408 return null;409 } else if ("key".equals(type)) {410 return tag.getKey();411 } else if ("value".equals(type)) {412 return tag.getValue();413 } else if ("tag".equals(type)) {414 return tag.toString();415 }416 } catch (IndexOutOfBoundsException ignore) {417 Logging.debug(ignore);418 }419 return null;420 }421 422 /**423 * Replaces occurrences of <code>{i.key}</code>, <code>{i.value}</code>, <code>{i.tag}</code> in {@code s} by the corresponding424 * key/value/tag of the {@code index}-th {@link Condition} of {@code matchingSelector}.425 * @param matchingSelector matching selector426 * @param s any string427 * @param p OSM primitive428 * @return string with arguments inserted429 */430 static String insertArguments(Selector matchingSelector, String s, OsmPrimitive p) {431 if (s != null && matchingSelector instanceof Selector.ChildOrParentSelector) {432 return insertArguments(((Selector.ChildOrParentSelector) matchingSelector).right, s, p);433 } else if (s == null || !(matchingSelector instanceof GeneralSelector)) {434 return s;435 }436 final Matcher m = Pattern.compile("\\{(\\d+)\\.(key|value|tag)\\}").matcher(s);437 final StringBuffer sb = new StringBuffer();438 while (m.find()) {439 final String argument = determineArgument((GeneralSelector) matchingSelector,440 Integer.parseInt(m.group(1)), m.group(2), p);441 try {442 // Perform replacement with null-safe + regex-safe handling443 m.appendReplacement(sb, String.valueOf(argument).replace("^(", "").replace(")$", ""));444 } catch (IndexOutOfBoundsException | IllegalArgumentException e) {445 Logging.log(Logging.LEVEL_ERROR, tr("Unable to replace argument {0} in {1}: {2}", argument, sb, e.getMessage()), e);446 }447 }448 m.appendTail(sb);449 return sb.toString();450 }451 452 /**453 * Constructs a fix in terms of a {@link org.openstreetmap.josm.command.Command} for the {@link OsmPrimitive}454 * if the error is fixable, or {@code null} otherwise.455 *456 * @param p the primitive to construct the fix for457 * @return the fix or {@code null}458 */459 Command fixPrimitive(OsmPrimitive p) {460 if (p.getDataSet() == null || (fixCommands.isEmpty() && !deletion)) {461 return null;462 }463 try {464 final Selector matchingSelector = whichSelectorMatchesPrimitive(p);465 Collection<Command> cmds = fixCommands.stream()466 .map(fixCommand -> fixCommand.createCommand(p, matchingSelector))467 .filter(Objects::nonNull)468 .collect(Collectors.toList());469 if (deletion && !p.isDeleted()) {470 cmds.add(new DeleteCommand(p));471 }472 return cmds.isEmpty() ? null473 : new SequenceCommand(tr("Fix of {0}", getDescriptionForMatchingSelector(p, matchingSelector)), cmds);474 } catch (IllegalArgumentException e) {475 Logging.error(e);476 return null;477 }478 }479 480 /**481 * Constructs a (localized) message for this deprecation check.482 * @param p OSM primitive483 *484 * @return a message485 */486 String getMessage(OsmPrimitive p) {487 if (errors.isEmpty()) {488 // Return something to avoid NPEs489 return rule.declaration.toString();490 } else {491 final Object val = errors.keySet().iterator().next().val;492 return String.valueOf(493 val instanceof Expression494 ? ((Expression) val).evaluate(new Environment(p))495 : val496 );497 }498 }499 500 /**501 * Constructs a (localized) description for this deprecation check.502 * @param p OSM primitive503 *504 * @return a description (possibly with alternative suggestions)505 * @see #getDescriptionForMatchingSelector506 */507 String getDescription(OsmPrimitive p) {508 if (alternatives.isEmpty()) {509 return getMessage(p);510 } else {511 /* I18N: {0} is the test error message and {1} is an alternative */512 return tr("{0}, use {1} instead", getMessage(p), String.join(tr(" or "), alternatives));513 }514 }515 516 /**517 * Constructs a (localized) description for this deprecation check518 * where any placeholders are replaced by values of the matched selector.519 *520 * @param matchingSelector matching selector521 * @param p OSM primitive522 * @return a description (possibly with alternative suggestions)523 */524 String getDescriptionForMatchingSelector(OsmPrimitive p, Selector matchingSelector) {525 return insertArguments(matchingSelector, getDescription(p), p);526 }527 528 Severity getSeverity() {529 return errors.isEmpty() ? null : errors.values().iterator().next();530 }531 532 @Override533 public String toString() {534 return getDescription(null);535 }536 537 /**538 * Constructs a {@link TestError} for the given primitive, or returns null if the primitive does not give rise to an error.539 *540 * @param p the primitive to construct the error for541 * @param matchingSelector the matching selector (e.g., obtained via {@link #whichSelectorMatchesPrimitive})542 * @param env the environment543 * @param tester the tester544 * @return an instance of {@link TestError}, or returns null if the primitive does not give rise to an error.545 */546 protected List<TestError> getErrorsForPrimitive(OsmPrimitive p, Selector matchingSelector, Environment env, Test tester) {547 List<TestError> res = new ArrayList<>();548 if (matchingSelector != null && !errors.isEmpty()) {549 final Command fix = fixPrimitive(p);550 final String description = getDescriptionForMatchingSelector(p, matchingSelector);551 final String description1 = group == null ? description : group;552 final String description2 = group == null ? null : description;553 final String selector = matchingSelector.toString();554 TestError.Builder errorBuilder = TestError.builder(tester, getSeverity(), 3000)555 .messageWithManuallyTranslatedDescription(description1, description2, selector);556 if (fix != null) {557 errorBuilder.fix(() -> fix);558 }559 if (env.child instanceof OsmPrimitive) {560 res.add(errorBuilder.primitives(p, (OsmPrimitive) env.child).build());561 } else if (env.children != null) {562 for (IPrimitive c : env.children) {563 if (c instanceof OsmPrimitive) {564 errorBuilder = TestError.builder(tester, getSeverity(), 3000)565 .messageWithManuallyTranslatedDescription(description1, description2, selector);566 if (fix != null) {567 errorBuilder.fix(() -> fix);568 }569 // check if we have special information about highlighted objects */570 boolean hiliteFound = false;571 if (env.intersections != null) {572 Area is = env.intersections.get(c);573 if (is != null) {574 errorBuilder.highlight(is);575 hiliteFound = true;576 }577 }578 if (env.crossingWaysMap != null && !hiliteFound) {579 Map<List<Way>, List<WaySegment>> is = env.crossingWaysMap.get(c);580 if (is != null) {581 Set<WaySegment> toHilite = new HashSet<>();582 for (List<WaySegment> wsList : is.values()) {583 toHilite.addAll(wsList);584 }585 errorBuilder.highlightWaySegments(toHilite);586 }587 }588 res.add(errorBuilder.primitives(p, (OsmPrimitive) c).build());589 }590 }591 } else {592 res.add(errorBuilder.primitives(p).build());593 }594 }595 return res;596 }597 598 }599 600 215 static class MapCSSTagCheckerAndRule extends MapCSSTagChecker { 601 216 public final MapCSSRule rule; 602 private final TagChecktagCheck;217 private final MapCSSTagCheckerRule tagCheck; 603 218 private final String source; 604 219 … … 609 224 } 610 225 611 MapCSSTagCheckerAndRule( TagChecktagCheck, String source) {226 MapCSSTagCheckerAndRule(MapCSSTagCheckerRule tagCheck, String source) { 612 227 this.rule = tagCheck.rule; 613 228 this.tagCheck = tagCheck; … … 626 241 } 627 242 628 static MapCSSStyleIndex createMapCSSTagCheckerIndex(MultiMap<String, TagCheck> checks, boolean includeOtherSeverity, boolean allTests) { 243 static MapCSSStyleIndex createMapCSSTagCheckerIndex( 244 MultiMap<String, MapCSSTagCheckerRule> checks, boolean includeOtherSeverity, boolean allTests) { 629 245 final MapCSSStyleIndex index = new MapCSSStyleIndex(); 630 246 final Stream<MapCSSRule> ruleStream = checks.values().stream() … … 671 287 .findFirst() 672 288 .orElse(null)); 673 TagCheckcheck = test == null ? null : test.tagCheck;289 MapCSSTagCheckerRule check = test == null ? null : test.tagCheck; 674 290 if (check != null) { 675 291 r.declaration.execute(env); … … 723 339 } 724 340 725 static Collection<TestError> getErrorsForPrimitive( OsmPrimitive p, boolean includeOtherSeverity,726 Collection<Set< TagCheck>> checksCol) {341 static Collection<TestError> getErrorsForPrimitive( 342 OsmPrimitive p, boolean includeOtherSeverity, Collection<Set<MapCSSTagCheckerRule>> checksCol) { 727 343 // this variant is only used by the assertion tests 728 344 final List<TestError> r = new ArrayList<>(); 729 345 final Environment env = new Environment(p, new MultiCascade(), Environment.DEFAULT_LAYER, null); 730 346 env.mpAreaCache = mpAreaCache; 731 for (Set< TagCheck> schecks : checksCol) {732 for ( TagCheckcheck : schecks) {347 for (Set<MapCSSTagCheckerRule> schecks : checksCol) { 348 for (MapCSSTagCheckerRule check : schecks) { 733 349 boolean ignoreError = Severity.OTHER == check.getSeverity() && !includeOtherSeverity; 734 350 // Do not run "information" level checks if not wanted, unless they also set a MapCSS class … … 790 406 if (zip != null) 791 407 I18n.addTexts(cache.getFile()); 792 result = TagCheck.readMapCSS(reader, assertionConsumer);408 result = MapCSSTagCheckerRule.readMapCSS(reader, assertionConsumer); 793 409 checks.remove(url); 794 410 checks.putAll(url, result.parseChecks); … … 890 506 891 507 Set<OsmPrimitive> surrounding = new HashSet<>(); 892 for (Entry<String, Set< TagCheck>> entry : checks.entrySet()) {508 for (Entry<String, Set<MapCSSTagCheckerRule>> entry : checks.entrySet()) { 893 509 if (isCanceled()) { 894 510 break; … … 905 521 * @param surrounding surrounding primitives, evtl. filled by this routine 906 522 */ 907 private void visit(String url, Set<TagCheck> checksForUrl, Collection<OsmPrimitive> selection, 908 Set<OsmPrimitive> surrounding) { 909 MultiMap<String, TagCheck> currentCheck = new MultiMap<>(); 523 private void visit(String url, Set<MapCSSTagCheckerRule> checksForUrl, Collection<OsmPrimitive> selection, Set<OsmPrimitive> surrounding) { 524 MultiMap<String, MapCSSTagCheckerRule> currentCheck = new MultiMap<>(); 910 525 currentCheck.putAll(url, checksForUrl); 911 526 indexData = createMapCSSTagCheckerIndex(currentCheck, includeOtherSeverityChecks(), ALL_TESTS); … … 945 560 } 946 561 947 private void testPartial(MultiMap<String, TagCheck> currentCheck, Set<OsmPrimitive> tested, 948 Set<OsmPrimitive> surrounding) { 562 private void testPartial(MultiMap<String, MapCSSTagCheckerRule> currentCheck, Set<OsmPrimitive> tested, Set<OsmPrimitive> surrounding) { 949 563 950 564 // #14287: see https://josm.openstreetmap.de/ticket/14287#comment:15 … … 989 603 990 604 Set<OsmPrimitive> surrounding = new HashSet<>(); 991 for (Entry<String, Set< TagCheck>> entry : checks.entrySet()) {605 for (Entry<String, Set<MapCSSTagCheckerRule>> entry : checks.entrySet()) { 992 606 if (isCanceled()) { 993 607 break; -
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerAsserts.java
r17333 r17619 35 35 36 36 /** 37 * Utility class for checking rule assertions of {@link MapCSSTagChecker .TagCheck}.37 * Utility class for checking rule assertions of {@link MapCSSTagCheckerRule}. 38 38 */ 39 39 final class MapCSSTagCheckerAsserts { … … 43 43 } 44 44 45 private static final ArrayList<MapCSSTagChecker .TagCheck> previousChecks = new ArrayList<>();45 private static final ArrayList<MapCSSTagCheckerRule> previousChecks = new ArrayList<>(); 46 46 47 47 /** … … 51 51 * @param assertionConsumer The handler for assertion error messages 52 52 */ 53 static void checkAsserts(final MapCSSTagChecker .TagCheckcheck, final Map<String, Boolean> assertions,54 53 static void checkAsserts(final MapCSSTagCheckerRule check, final Map<String, Boolean> assertions, 54 final MapCSSTagChecker.AssertionConsumer assertionConsumer) { 55 55 final Method insideMethod = getFunctionMethod("inside"); 56 56 final DataSet ds = new DataSet(); … … 60 60 final OsmPrimitive p = OsmUtils.createPrimitive(i.getKey(), getLocation(check, insideMethod), true); 61 61 // Build minimal ordered list of checks to run to test the assertion 62 List<Set<MapCSSTagChecker .TagCheck>> checksToRun = new ArrayList<>();63 Set<MapCSSTagChecker .TagCheck> checkDependencies = getTagCheckDependencies(check, previousChecks);62 List<Set<MapCSSTagCheckerRule>> checksToRun = new ArrayList<>(); 63 Set<MapCSSTagCheckerRule> checkDependencies = getTagCheckDependencies(check, previousChecks); 64 64 if (!checkDependencies.isEmpty()) { 65 65 checksToRun.add(checkDependencies); … … 112 112 } 113 113 114 private static LatLon getLocation(MapCSSTagChecker .TagCheckcheck, Method insideMethod) {114 private static LatLon getLocation(MapCSSTagCheckerRule check, Method insideMethod) { 115 115 Optional<String> inside = getFirstInsideCountry(check, insideMethod); 116 116 if (inside.isPresent()) { … … 126 126 } 127 127 128 private static Optional<String> getFirstInsideCountry(MapCSSTagChecker .TagCheckcheck, Method insideMethod) {128 private static Optional<String> getFirstInsideCountry(MapCSSTagCheckerRule check, Method insideMethod) { 129 129 return check.rule.selectors.stream() 130 130 .filter(s -> s instanceof Selector.GeneralSelector) … … 150 150 * @since 7881 151 151 */ 152 private static Set<MapCSSTagChecker .TagCheck> getTagCheckDependencies(MapCSSTagChecker.TagCheckcheck,153 .TagCheck> schecks) {154 Set<MapCSSTagChecker .TagCheck> result = new HashSet<>();152 private static Set<MapCSSTagCheckerRule> getTagCheckDependencies(MapCSSTagCheckerRule check, 153 Collection<MapCSSTagCheckerRule> schecks) { 154 Set<MapCSSTagCheckerRule> result = new HashSet<>(); 155 155 Set<String> classes = check.rule.selectors.stream() 156 156 .filter(s -> s instanceof Selector.AbstractSelector)
Note:
See TracChangeset
for help on using the changeset viewer.