Changeset 8266 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2015-04-25T19:13:12+02:00 (9 years ago)
Author:
simon04
Message:

fix #9782 fix #10859 - MapCSS validator: evaluate real key and value for KeyConditions

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r8265 r8266  
    147147        /**
    148148         * Creates the fixing {@link Command} for the given primitive. The {@code matchingSelector} is used to
    149          * evaluate placeholders (cf. {@link org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.TagCheck#insertArguments(Selector, String)}).
     149         * evaluate placeholders (cf. {@link org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.TagCheck#insertArguments(Selector, String, OsmPrimitive)}).
    150150         */
    151151        abstract Command createCommand(final OsmPrimitive p, final Selector matchingSelector);
     
    167167                return null;
    168168            }
    169             return TagCheck.insertArguments(matchingSelector, s);
     169            return TagCheck.insertArguments(matchingSelector, s, p);
    170170        }
    171171
     
    386386         * {@link org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector}.
    387387         */
    388         static String determineArgument(Selector.GeneralSelector matchingSelector, int index, String type) {
     388        static String determineArgument(Selector.GeneralSelector matchingSelector, int index, String type, OsmPrimitive p) {
    389389            try {
    390390                final Condition c = matchingSelector.getConditions().get(index);
    391391                final Tag tag = c instanceof Condition.KeyCondition
    392                         ? ((Condition.KeyCondition) c).asTag()
     392                        ? ((Condition.KeyCondition) c).asTag(p)
    393393                        : c instanceof Condition.SimpleKeyValueCondition
    394394                        ? ((Condition.SimpleKeyValueCondition) c).asTag()
     
    417417         * key/value/tag of the {@code index}-th {@link Condition} of {@code matchingSelector}.
    418418         */
    419         static String insertArguments(Selector matchingSelector, String s) {
     419        static String insertArguments(Selector matchingSelector, String s, OsmPrimitive p) {
    420420            if (s != null && matchingSelector instanceof Selector.ChildOrParentSelector) {
    421                 return  insertArguments(((Selector.ChildOrParentSelector)matchingSelector).right, s);
     421                return insertArguments(((Selector.ChildOrParentSelector)matchingSelector).right, s, p);
    422422            } else if (s == null || !(matchingSelector instanceof GeneralSelector)) {
    423423                return s;
     
    426426            final StringBuffer sb = new StringBuffer();
    427427            while (m.find()) {
    428                 final String argument = determineArgument((Selector.GeneralSelector) matchingSelector, Integer.parseInt(m.group(1)), m.group(2));
     428                final String argument = determineArgument((Selector.GeneralSelector) matchingSelector, Integer.parseInt(m.group(1)), m.group(2), p);
    429429                try {
    430430                    // Perform replacement with null-safe + regex-safe handling
     
    501501         */
    502502        String getDescriptionForMatchingSelector(OsmPrimitive p, Selector matchingSelector) {
    503             return insertArguments(matchingSelector, getDescription(p));
     503            return insertArguments(matchingSelector, getDescription(p), p);
    504504        }
    505505
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r8252 r8266  
    44import java.text.MessageFormat;
    55import java.util.Arrays;
     6import java.util.Collection;
    67import java.util.EnumSet;
    78import java.util.Objects;
     
    340341        }
    341342
    342         public Tag asTag() {
    343             return new Tag(label);
     343        public Tag asTag(OsmPrimitive p) {
     344            String key = label;
     345            if (KeyMatchType.REGEX.equals(matchType)) {
     346                final Collection<String> matchingKeys = Utils.filter(p.keySet(), containsPattern);
     347                if (!matchingKeys.isEmpty()) {
     348                    key = matchingKeys.iterator().next();
     349                }
     350            }
     351            return new Tag(key, p.get(key));
    344352        }
    345353
Note: See TracChangeset for help on using the changeset viewer.