Changeset 15989 in josm


Ignore:
Timestamp:
2020-03-01T23:36:09+01:00 (3 months ago)
Author:
simon04
Message:

see #18802 - MapCSSStyleIndex: rename/move

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  
    5050import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
    5151import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;
     52import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleIndex;
    5253import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    5354import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
     
    7374 */
    7475public class MapCSSTagChecker extends Test.TagTest {
    75     private MapCSSTagCheckerIndex indexData;
     76    private MapCSSStyleIndex indexData;
    7677    final Map<MapCSSRule, MapCSSTagCheckerAndRule> ruleToCheckMap = new HashMap<>();
    7778    private final Set<OsmPrimitive> tested = new HashSet<>();
    7879    private static final Map<IPrimitive, Area> mpAreaCache = new HashMap<>();
     80    static final boolean ALL_TESTS = true;
     81    static final boolean ONLY_SELECTED_TESTS = false;
    7982
    8083    /**
     
    622625    }
    623626
    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();
    626633        final Stream<MapCSSRule> ruleStream = checks.values().stream()
    627634                .flatMap(Collection::stream)
     
    643650        final List<TestError> res = new ArrayList<>();
    644651        if (indexData == null) {
    645             indexData = MapCSSTagCheckerIndex.createMapCSSTagCheckerIndex(checks, includeOtherSeverity, MapCSSTagCheckerIndex.ALL_TESTS);
     652            indexData = createMapCSSTagCheckerIndex(checks, includeOtherSeverity, ALL_TESTS);
    646653        }
    647654
     
    850857        super.setShowElements(true);
    851858        if (indexData == null) {
    852             indexData = MapCSSTagCheckerIndex.createMapCSSTagCheckerIndex(checks, includeOtherSeverityChecks(), MapCSSTagCheckerIndex.ALL_TESTS);
     859            indexData = createMapCSSTagCheckerIndex(checks, includeOtherSeverityChecks(), ALL_TESTS);
    853860        }
    854861        tested.clear();
     
    864871            // rebuild index with a reduced set of rules (those that use ChildOrParentSelector) and thus may have left selectors
    865872            // matching the previously tested elements
    866             indexData = MapCSSTagCheckerIndex.createMapCSSTagCheckerIndex(checks, includeOtherSeverityChecks(), MapCSSTagCheckerIndex.ONLY_SELECTED_TESTS);
     873            indexData = createMapCSSTagCheckerIndex(checks, includeOtherSeverityChecks(), ONLY_SELECTED_TESTS);
    867874
    868875            Set<OsmPrimitive> surrounding = new HashSet<>();
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleIndex.java

    r15988 r15989  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.data.validation.tests;
     2package org.openstreetmap.josm.gui.mappaint.mapcss;
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    66import java.text.MessageFormat;
    7 import java.util.Collection;
    8 import java.util.HashMap;
    97import java.util.Iterator;
    108import java.util.Map;
     
    1715import org.openstreetmap.josm.data.osm.IWay;
    1816import 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;
    2317import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource.MapCSSRuleIndex;
    24 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
    2518import org.openstreetmap.josm.tools.JosmRuntimeException;
    2619import org.openstreetmap.josm.tools.Logging;
    27 import org.openstreetmap.josm.tools.MultiMap;
    2820
    2921/**
    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}
    3323 */
    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;
     24public final class MapCSSStyleIndex {
    3925
    4026    /**
     
    6349    final MapCSSRuleIndex canvasRules = new MapCSSRuleIndex();
    6450
    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 class
    70                 .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 
    7851    /**
    7952     * Clear the index.
     
    8255     */
    8356    public void clear() {
    84         ruleToCheckMap.clear();
    8557        nodeRules.clear();
    8658        wayRules.clear();
     
    192164        return get(osm).getRuleCandidates(osm);
    193165    }
    194 
    195     /**
    196      * return the TagCheck for which the given indexed rule was created.
    197      * @param rule an indexed rule
    198      * @return the original TagCheck
    199      */
    200     public TagCheck getCheck(MapCSSRule rule) {
    201         return ruleToCheckMap.get(rule.declaration);
    202     }
    203166}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r15988 r15989  
    3939import org.openstreetmap.josm.data.osm.Tagged;
    4040import org.openstreetmap.josm.data.preferences.sources.SourceEntry;
    41 import org.openstreetmap.josm.data.validation.tests.MapCSSTagCheckerIndex;
    4241import org.openstreetmap.josm.gui.mappaint.Cascade;
    4342import org.openstreetmap.josm.gui.mappaint.Environment;
     
    8685     * Index of rules in this style file
    8786     */
    88     private final MapCSSTagCheckerIndex ruleIndex = new MapCSSTagCheckerIndex();
     87    private final MapCSSStyleIndex ruleIndex = new MapCSSStyleIndex();
    8988
    9089    private Color backgroundColorOverride;
Note: See TracChangeset for help on using the changeset viewer.