Ticket #13805: 13805-grouped.2.patch
File 13805-grouped.2.patch, 8.4 KB (added by , 4 years ago) |
---|
-
src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
17 17 import java.util.LinkedList; 18 18 import java.util.List; 19 19 import java.util.Map; 20 import java.util.Map.Entry; 20 21 import java.util.Objects; 21 22 import java.util.Optional; 22 23 import java.util.Set; … … 66 67 import org.openstreetmap.josm.tools.I18n; 67 68 import org.openstreetmap.josm.tools.Logging; 68 69 import org.openstreetmap.josm.tools.MultiMap; 70 import org.openstreetmap.josm.tools.Stopwatch; 69 71 import org.openstreetmap.josm.tools.Utils; 70 72 71 73 /** … … 75 77 public class MapCSSTagChecker extends Test.TagTest { 76 78 private MapCSSStyleIndex indexData; 77 79 final Map<MapCSSRule, MapCSSTagCheckerAndRule> ruleToCheckMap = new HashMap<>(); 78 private final Set<OsmPrimitive> tested = new HashSet<>();79 80 private static final Map<IPrimitive, Area> mpAreaCache = new HashMap<>(); 80 81 static final boolean ALL_TESTS = true; 81 82 static final boolean ONLY_SELECTED_TESTS = false; … … 203 204 204 205 final MultiMap<String, TagCheck> checks = new MultiMap<>(); 205 206 207 /** maps the source URL for a test to the title shown in the dialog where known */ 208 private final Map<String, String> urlTitles = new HashMap<>(); 209 206 210 /** 207 211 * Result of {@link TagCheck#readMapCSS} 208 212 * @since 8936 … … 617 621 618 622 @Override 619 623 public String getSource() { 620 return tr("URL / File: {0}", source);624 return source; 621 625 } 622 626 } 623 627 … … 661 665 // rule.selectors might be different due to MapCSSStyleIndex, however, the declarations are the same object 662 666 .filter(c -> c.rule.declaration == rule.declaration) 663 667 .findFirst() 664 .map(c -> new MapCSSTagCheckerAndRule(c, e.getKey()))668 .map(c -> new MapCSSTagCheckerAndRule(c, getTitle(e.getKey()))) 665 669 .orElse(null)) 666 670 .filter(Objects::nonNull) 667 671 .findFirst() … … 680 684 return res; 681 685 } 682 686 687 private String getTitle(String url) { 688 return urlTitles.getOrDefault(url, tr("unknown")); 689 } 690 683 691 /** 684 692 * See #12627 685 693 * Add error to given list if list doesn't already contain a similar error. … … 749 757 for (TestError e : getErrorsForPrimitive(p, ValidatorPrefHelper.PREF_OTHER.get())) { 750 758 addIfNotSimilar(e, errors); 751 759 } 752 if (partialSelection) {753 tested.add(p);754 }755 760 } 756 761 757 762 /** … … 787 792 result = TagCheck.readMapCSS(reader, assertionConsumer); 788 793 checks.remove(url); 789 794 checks.putAll(url, result.parseChecks); 795 for (SourceEntry source : new ValidatorPrefHelper().get()) { 796 if (url.equals(source.url)) { 797 urlTitles.put(url, source.title); 798 break; 799 } 800 } 790 801 indexData = null; 791 802 } 792 803 return result; … … 795 806 @Override 796 807 public synchronized void initialize() throws Exception { 797 808 checks.clear(); 809 urlTitles.clear(); 798 810 indexData = null; 799 811 for (SourceEntry source : new ValidatorPrefHelper().get()) { 800 812 if (!source.active) { … … 842 854 public synchronized void startTest(ProgressMonitor progressMonitor) { 843 855 super.startTest(progressMonitor); 844 856 super.setShowElements(true); 845 if (indexData == null) { 846 indexData = createMapCSSTagCheckerIndex(checks, includeOtherSeverityChecks(), ALL_TESTS); 857 } 858 859 @Override 860 public synchronized void endTest() { 861 // no need to keep the index, it is quickly build and doubles the memory needs 862 indexData = null; 863 // always clear the cache to make sure that we catch changes in geometry 864 mpAreaCache.clear(); 865 super.endTest(); 866 } 867 868 @Override 869 public void visit(Collection<OsmPrimitive> selection) { 870 if (progressMonitor != null) { 871 progressMonitor.setTicksCount(selection.size() * checks.size()); 847 872 } 848 tested.clear(); 873 849 874 mpAreaCache.clear(); 875 876 Set<OsmPrimitive> surrounding = new HashSet<>(); 877 for (Entry<String, Set<TagCheck>> entry : checks.entrySet()) { 878 if (isCanceled()) { 879 break; 880 } 881 visit(entry.getKey(), entry.getValue(), selection, surrounding); 882 } 850 883 } 851 884 852 @Override 853 public synchronized void endTest() { 885 /** 886 * Perform the checks for one check url 887 * @param url the url for the checks 888 * @param checksForUrl the checks to perform 889 * @param selection collection primitives 890 * @param surrounding surrounding primitives, evtl. filled by this routine 891 */ 892 private void visit(String url, Set<TagCheck> checksForUrl, Collection<OsmPrimitive> selection, 893 Set<OsmPrimitive> surrounding) { 894 MultiMap<String, TagCheck> currentCheck = new MultiMap<>(); 895 currentCheck.putAll(url, checksForUrl); 896 indexData = createMapCSSTagCheckerIndex(currentCheck, includeOtherSeverityChecks(), ALL_TESTS); 897 Set<OsmPrimitive> tested = new HashSet<>(); 898 899 900 String title = getTitle(url); 901 if (progressMonitor != null) { 902 progressMonitor.setExtraText(tr(" {0}", title)); 903 } 904 long cnt = 0; 905 Stopwatch stopwatch = Stopwatch.createStarted(); 906 for (OsmPrimitive p : selection) { 907 if (isCanceled()) { 908 break; 909 } 910 if (isPrimitiveUsable(p)) { 911 check(p); 912 if (partialSelection) { 913 tested.add(p); 914 } 915 } 916 if (progressMonitor != null) { 917 progressMonitor.worked(1); 918 cnt++; 919 // add frequently changing info to progress monitor so that it 920 // doesn't seem to hang when test takes longer than 0.5 seconds 921 if (cnt % 10000 == 0 && stopwatch.elapsed() >= 500) { 922 progressMonitor.setExtraText(tr(" {0}: {1} of {2} elements done", title, cnt, selection.size())); 923 } 924 } 925 } 926 854 927 if (partialSelection && !tested.isEmpty()) { 855 928 // #14287: see https://josm.openstreetmap.de/ticket/14287#comment:15 856 929 // execute tests for objects which might contain or cross previously tested elements … … 857 930 858 931 // rebuild index with a reduced set of rules (those that use ChildOrParentSelector) and thus may have left selectors 859 932 // matching the previously tested elements 860 indexData = createMapCSSTagCheckerIndex(c hecks, includeOtherSeverityChecks(), ONLY_SELECTED_TESTS);933 indexData = createMapCSSTagCheckerIndex(currentCheck, includeOtherSeverityChecks(), ONLY_SELECTED_TESTS); 861 934 862 Set<OsmPrimitive> surrounding = new HashSet<>(); 863 for (OsmPrimitive p : tested) { 864 if (p.getDataSet() != null) { 865 surrounding.addAll(p.getDataSet().searchWays(p.getBBox())); 866 surrounding.addAll(p.getDataSet().searchRelations(p.getBBox())); 935 if (surrounding.isEmpty()) { 936 for (OsmPrimitive p : tested) { 937 if (p.getDataSet() != null) { 938 surrounding.addAll(p.getDataSet().searchWays(p.getBBox())); 939 surrounding.addAll(p.getDataSet().searchRelations(p.getBBox())); 940 } 867 941 } 868 942 } 943 869 944 final boolean includeOtherSeverity = includeOtherSeverityChecks(); 870 945 for (OsmPrimitive p : surrounding) { 871 946 if (tested.contains(p)) … … 876 951 addIfNotSimilar(e, errors); 877 952 } 878 953 } 879 tested.clear();880 954 } 881 // no need to keep the index, it is quickly build and doubles the memory needs882 indexData = null;883 // always clear the cache to make sure that we catch changes in geometry884 mpAreaCache.clear();885 super.endTest();886 955 } 956 887 957 }