Changeset 8936 in josm
- Timestamp:
- 2015-10-23T23:34:29+02:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r8846 r8936 234 234 final MultiMap<String, TagCheck> checks = new MultiMap<>(); 235 235 236 static class TagCheck implements Predicate<OsmPrimitive> { 236 /** 237 * Result of {@link TagCheck#readMapCSS} 238 * @since 8936 239 */ 240 public static class ParseResult { 241 /** Checks successfully parsed */ 242 public final List<TagCheck> parseChecks; 243 /** Errors that occured during parsing */ 244 public final Collection<Throwable> parseErrors; 245 246 /** 247 * Constructs a new {@code ParseResult}. 248 * @param parseChecks Checks successfully parsed 249 * @param parseErrors Errors that occured during parsing 250 */ 251 public ParseResult(List<TagCheck> parseChecks, Collection<Throwable> parseErrors) { 252 this.parseChecks = parseChecks; 253 this.parseErrors = parseErrors; 254 } 255 } 256 257 public static class TagCheck implements Predicate<OsmPrimitive> { 237 258 protected final GroupedMapCSSRule rule; 238 259 protected final List<FixCommand> fixCommands = new ArrayList<>(); … … 320 341 } 321 342 322 static List<TagCheck>readMapCSS(Reader css) throws ParseException {343 static ParseResult readMapCSS(Reader css) throws ParseException { 323 344 CheckParameterUtil.ensureParameterNotNull(css, "css"); 324 345 … … 329 350 final MapCSSParser parser = new MapCSSParser(css, MapCSSParser.LexicalState.DEFAULT); 330 351 parser.sheet(source); 331 assert source.getErrors().isEmpty(); 352 Collection<Throwable> parseErrors = source.getErrors(); 353 assert parseErrors.isEmpty(); 332 354 // Ignore "meta" rule(s) from external rules of JOSM wiki 333 355 removeMetaRules(source); … … 343 365 } 344 366 } 345 List<TagCheck> result= new ArrayList<>();367 List<TagCheck> parseChecks = new ArrayList<>(); 346 368 for (Map.Entry<Declaration, List<Selector>> map : g.entrySet()) { 347 369 try { 348 result.add(TagCheck.ofMapCSSRule(370 parseChecks.add(TagCheck.ofMapCSSRule( 349 371 new GroupedMapCSSRule(map.getValue(), map.getKey()))); 350 372 } catch (IllegalDataException e) { 351 373 Main.error("Cannot add MapCss rule: "+e.getMessage()); 352 } 353 } 354 return result; 374 parseErrors.add(e); 375 } 376 } 377 return new ParseResult(parseChecks, parseErrors); 355 378 } 356 379 … … 669 692 * Adds a new MapCSS config file from the given URL. 670 693 * @param url The unique URL of the MapCSS config file 694 * @return List of tag checks and parsing errors, or null 671 695 * @throws ParseException if the config file does not match MapCSS syntax 672 696 * @throws IOException if any I/O error occurs 673 697 * @since 7275 674 698 */ 675 public synchronized voidaddMapCSS(String url) throws ParseException, IOException {699 public synchronized ParseResult addMapCSS(String url) throws ParseException, IOException { 676 700 CheckParameterUtil.ensureParameterNotNull(url, "url"); 677 701 CachedFile cache = new CachedFile(url); 678 702 InputStream zip = cache.findZipEntryInputStream("validator.mapcss", ""); 703 ParseResult result; 679 704 try (InputStream s = zip != null ? zip : cache.getInputStream()) { 680 List<TagCheck> tagchecks= TagCheck.readMapCSS(new BufferedReader(UTFInputStreamReader.create(s)));705 result = TagCheck.readMapCSS(new BufferedReader(UTFInputStreamReader.create(s))); 681 706 checks.remove(url); 682 checks.putAll(url, tagchecks);707 checks.putAll(url, result.parseChecks); 683 708 // Check assertions, useful for development of local files 684 709 if (Main.pref.getBoolean("validator.check_assert_local_rules", false) && Utils.isLocalUrl(url)) { 685 for (String msg : checkAsserts( tagchecks)) {710 for (String msg : checkAsserts(result.parseChecks)) { 686 711 Main.warn(msg); 687 712 } 688 713 } 689 714 } 715 return result; 690 716 } 691 717 -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r8870 r8936 447 447 /** 448 448 * Synchronously loads available sources and returns the parsed list. 449 * @return list of available sources 449 450 */ 450 Collection<ExtendedSourceEntry> loadAndGetAvailableSources() {451 public final Collection<ExtendedSourceEntry> loadAndGetAvailableSources() { 451 452 try { 452 453 final SourceLoader loader = new SourceLoader(availableSourcesUrl, sourceProviders); … … 466 467 } 467 468 469 /** 470 * Performs the initial loading of source providers. Does nothing if already done. 471 */ 468 472 public void initiallyLoadAvailableSources() { 469 473 if (!sourcesInitiallyLoaded) { -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java
r8857 r8936 28 28 import org.openstreetmap.josm.data.validation.Severity; 29 29 import org.openstreetmap.josm.data.validation.TestError; 30 import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.ParseResult; 30 31 import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.TagCheck; 31 32 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException; … … 46 47 static MapCSSTagChecker buildTagChecker(String css) throws ParseException { 47 48 final MapCSSTagChecker test = new MapCSSTagChecker(); 48 test.checks.putAll("test", TagCheck.readMapCSS(new StringReader(css)) );49 test.checks.putAll("test", TagCheck.readMapCSS(new StringReader(css)).parseChecks); 49 50 return test; 50 51 } … … 52 53 @Test 53 54 public void testNaturalMarsh() throws Exception { 54 final List<MapCSSTagChecker.TagCheck> checks= MapCSSTagChecker.TagCheck.readMapCSS(new StringReader("" +55 ParseResult result = MapCSSTagChecker.TagCheck.readMapCSS(new StringReader("" + 55 56 "*[natural=marsh] {\n" + 56 57 " throwWarning: tr(\"{0}={1} is deprecated\", \"{0.key}\", tag(\"natural\"));\n" + … … 59 60 " fixAdd: \"wetland=marsh\";\n" + 60 61 "}")); 62 final List<MapCSSTagChecker.TagCheck> checks = result.parseChecks; 61 63 assertEquals(1, checks.size()); 64 assertTrue(result.parseErrors.isEmpty()); 62 65 final MapCSSTagChecker.TagCheck check = checks.get(0); 63 66 assertNotNull(check); … … 87 90 "fixChangeKey: \"highway => construction\";\n" + 88 91 "fixAdd: \"highway=construction\";\n" + 89 "}")). get(0);92 "}")).parseChecks.get(0); 90 93 final Command command = check.fixPrimitive(p); 91 94 assertTrue(command instanceof SequenceCommand);
Note:
See TracChangeset
for help on using the changeset viewer.