Changeset 15989 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-03-01T23:36:09+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r15988 r15989 50 50 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction; 51 51 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule; 52 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleIndex; 52 53 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 53 54 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector; … … 73 74 */ 74 75 public class MapCSSTagChecker extends Test.TagTest { 75 private MapCSS TagCheckerIndex indexData;76 private MapCSSStyleIndex indexData; 76 77 final Map<MapCSSRule, MapCSSTagCheckerAndRule> ruleToCheckMap = new HashMap<>(); 77 78 private final Set<OsmPrimitive> tested = new HashSet<>(); 78 79 private static final Map<IPrimitive, Area> mpAreaCache = new HashMap<>(); 80 static final boolean ALL_TESTS = true; 81 static final boolean ONLY_SELECTED_TESTS = false; 79 82 80 83 /** … … 622 625 } 623 626 624 static MapCSSTagCheckerIndex createMapCSSTagCheckerIndex(MultiMap<String, TagCheck> checks, boolean includeOtherSeverity, boolean allTests) { 625 final MapCSSTagCheckerIndex index = new MapCSSTagCheckerIndex(); 627 private static boolean hasSameDeclaration(MapCSSRule rule1, final MapCSSRule rule2) { 628 return Objects.equals(rule1.declaration, rule2.declaration); 629 } 630 631 static MapCSSStyleIndex createMapCSSTagCheckerIndex(MultiMap<String, TagCheck> checks, boolean includeOtherSeverity, boolean allTests) { 632 final MapCSSStyleIndex index = new MapCSSStyleIndex(); 626 633 final Stream<MapCSSRule> ruleStream = checks.values().stream() 627 634 .flatMap(Collection::stream) … … 643 650 final List<TestError> res = new ArrayList<>(); 644 651 if (indexData == null) { 645 indexData = MapCSSTagCheckerIndex.createMapCSSTagCheckerIndex(checks, includeOtherSeverity, MapCSSTagCheckerIndex.ALL_TESTS);652 indexData = createMapCSSTagCheckerIndex(checks, includeOtherSeverity, ALL_TESTS); 646 653 } 647 654 … … 850 857 super.setShowElements(true); 851 858 if (indexData == null) { 852 indexData = MapCSSTagCheckerIndex.createMapCSSTagCheckerIndex(checks, includeOtherSeverityChecks(), MapCSSTagCheckerIndex.ALL_TESTS);859 indexData = createMapCSSTagCheckerIndex(checks, includeOtherSeverityChecks(), ALL_TESTS); 853 860 } 854 861 tested.clear(); … … 864 871 // rebuild index with a reduced set of rules (those that use ChildOrParentSelector) and thus may have left selectors 865 872 // matching the previously tested elements 866 indexData = MapCSSTagCheckerIndex.createMapCSSTagCheckerIndex(checks, includeOtherSeverityChecks(), MapCSSTagCheckerIndex.ONLY_SELECTED_TESTS);873 indexData = createMapCSSTagCheckerIndex(checks, includeOtherSeverityChecks(), ONLY_SELECTED_TESTS); 867 874 868 875 Set<OsmPrimitive> surrounding = new HashSet<>(); -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleIndex.java
r15988 r15989 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm. data.validation.tests;2 package org.openstreetmap.josm.gui.mappaint.mapcss; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 6 import java.text.MessageFormat; 7 import java.util.Collection;8 import java.util.HashMap;9 7 import java.util.Iterator; 10 8 import java.util.Map; … … 17 15 import org.openstreetmap.josm.data.osm.IWay; 18 16 import org.openstreetmap.josm.data.osm.OsmUtils; 19 import org.openstreetmap.josm.data.validation.Severity;20 import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.TagCheck;21 import org.openstreetmap.josm.gui.mappaint.mapcss.Declaration;22 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;23 17 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource.MapCSSRuleIndex; 24 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;25 18 import org.openstreetmap.josm.tools.JosmRuntimeException; 26 19 import org.openstreetmap.josm.tools.Logging; 27 import org.openstreetmap.josm.tools.MultiMap;28 20 29 21 /** 30 * Helper class for {@link MapCSSTagChecker} to store indexes of rules 31 * @author Gerd 32 * 22 * Store indexes of {@link MapCSSRule}s using {@link MapCSSRuleIndex} differentiated by {@linkplain Selector#getBase() base} 33 23 */ 34 public final class MapCSSTagCheckerIndex { 35 final Map<Declaration, TagCheck> ruleToCheckMap = new HashMap<>(); 36 37 static final boolean ALL_TESTS = true; 38 static final boolean ONLY_SELECTED_TESTS = false; 24 public final class MapCSSStyleIndex { 39 25 40 26 /** … … 63 49 final MapCSSRuleIndex canvasRules = new MapCSSRuleIndex(); 64 50 65 static MapCSSTagCheckerIndex createMapCSSTagCheckerIndex(MultiMap<String, TagCheck> checks, boolean includeOtherSeverity, boolean allTests) {66 final MapCSSTagCheckerIndex index = new MapCSSTagCheckerIndex();67 final Stream<MapCSSRule> ruleStream = checks.values().stream()68 .flatMap(Collection::stream)69 // Ignore "information" level checks if not wanted, unless they also set a MapCSS class70 .filter(c -> includeOtherSeverity || Severity.OTHER != c.getSeverity() || !c.setClassExpressions.isEmpty())71 .filter(c -> allTests || c.rule.selectors.stream().anyMatch(Selector.ChildOrParentSelector.class::isInstance))72 .peek(c -> index.ruleToCheckMap.put(c.rule.declaration, c))73 .map(c -> c.rule);74 index.buildIndex(ruleStream);75 return index;76 }77 78 51 /** 79 52 * Clear the index. … … 82 55 */ 83 56 public void clear() { 84 ruleToCheckMap.clear();85 57 nodeRules.clear(); 86 58 wayRules.clear(); … … 192 164 return get(osm).getRuleCandidates(osm); 193 165 } 194 195 /**196 * return the TagCheck for which the given indexed rule was created.197 * @param rule an indexed rule198 * @return the original TagCheck199 */200 public TagCheck getCheck(MapCSSRule rule) {201 return ruleToCheckMap.get(rule.declaration);202 }203 166 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r15988 r15989 39 39 import org.openstreetmap.josm.data.osm.Tagged; 40 40 import org.openstreetmap.josm.data.preferences.sources.SourceEntry; 41 import org.openstreetmap.josm.data.validation.tests.MapCSSTagCheckerIndex;42 41 import org.openstreetmap.josm.gui.mappaint.Cascade; 43 42 import org.openstreetmap.josm.gui.mappaint.Environment; … … 86 85 * Index of rules in this style file 87 86 */ 88 private final MapCSS TagCheckerIndex ruleIndex = new MapCSSTagCheckerIndex();87 private final MapCSSStyleIndex ruleIndex = new MapCSSStyleIndex(); 89 88 90 89 private Color backgroundColorOverride;
Note:
See TracChangeset
for help on using the changeset viewer.