Ticket #19053: 19053.6.patch

File 19053.6.patch, 6.7 KB (added by GerdP, 6 years ago)

never use selector to build key

  • src/org/openstreetmap/josm/data/validation/OsmValidator.java

     
    1818import java.util.EnumMap;
    1919import java.util.Enumeration;
    2020import java.util.HashMap;
     21import java.util.HashSet;
    2122import java.util.Iterator;
    2223import java.util.List;
    2324import java.util.Map;
    2425import java.util.Map.Entry;
     26import java.util.Set;
    2527import java.util.SortedMap;
    2628import java.util.TreeMap;
    2729import java.util.TreeSet;
     
    234236            } catch (SecurityException e) {
    235237                Logging.log(Logging.LEVEL_ERROR, "Unable to load ignored errors", e);
    236238            }
    237             // see #19053: remove invalid entry
    238             ignoredErrors.remove("3000");
     239            // see #19053:
     240            String legacyEntry = ignoredErrors.remove("3000");
     241            if (legacyEntry != null) {
     242                if (!legacyEntry.isEmpty()) {
     243                    addIgnoredError("3000_" + legacyEntry, legacyEntry);
     244                }
     245                saveIgnoredErrors();
     246            }
     247
    239248        }
    240249    }
    241250
     
    265274     *  Make sure that we don't keep single entries for a "group ignore".
    266275     */
    267276    static void cleanupIgnoredErrors() {
     277        cleanup3000();
    268278        if (ignoredErrors.size() > 1) {
    269279            List<String> toRemove = new ArrayList<>();
    270280
     
    288298        }
    289299    }
    290300
     301    private static void cleanup3000() {
     302        // see #19053
     303        if (ignoredErrors.size() > 1) {
     304            Set<String> toRemove = new HashSet<>();
     305            for (Entry<String, String> entry : ignoredErrors.entrySet()) {
     306                if (entry.getKey().equals("3000_" + entry.getValue()))
     307                    toRemove.add(entry.getValue());
     308            }
     309            ignoredErrors.entrySet()
     310                    .removeIf(e -> toRemove.contains(e.getValue()) && !e.getKey().equals("3000_" + e.getValue()));
     311
     312        }
     313    }
     314
    291315    private static boolean sameCode(String key1, String key2) {
    292316        return extractCodeFromIgnoreKey(key1).equals(extractCodeFromIgnoreKey(key2));
    293317    }
  • src/org/openstreetmap/josm/data/validation/TestError.java

     
    338338     * @return The ignore sub group
    339339     */
    340340    public String getIgnoreSubGroup() {
     341        if (code == 3000) {
     342            // see #19053
     343            return "3000_" + (description == null ? message : description);
     344        }
    341345        String ignorestring = getIgnoreGroup();
    342346        if (descriptionEn != null) {
    343347            ignorestring += '_' + descriptionEn;
     
    351355     * @see TestError#getIgnoreSubGroup()
    352356     */
    353357    public String getIgnoreGroup() {
     358        if (code == 3000) {
     359            // see #19053
     360            return "3000_" + getMessage();
     361        }
    354362        return Integer.toString(code);
    355363    }
    356364
     
    524532    public String toString() {
    525533        return "TestError [tester=" + tester + ", code=" + code + ", message=" + message + ']';
    526534    }
     535
    527536}
  • src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

     
    410410
    411411        lastSelectedNode = node;
    412412        if (node != null) {
    413             final Set<String> codes = new HashSet<>();
    414413            ValidatorTreePanel.visitTestErrors(node, error -> {
    415                 codes.add(error.getIgnoreSubGroup()); // see #19053
    416414                error.setSelected(true);
    417415
    418416                hasFixes.set(hasFixes.get() || error.isFixable());
     
    424422            });
    425423            selectAction.setEnabled(true);
    426424            if (ignoreAction != null) {
    427                 ignoreAction.setEnabled(!(node.getUserObject() instanceof Severity) && codes.size() <= 1);
     425                ignoreAction.setEnabled(!(node.getUserObject() instanceof Severity));
    428426            }
    429427        }
    430428
  • test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

     
    144144        final Collection<TestError> errors = test.getErrorsForPrimitive(p, false);
    145145        assertEquals(1, errors.size());
    146146        assertEquals("has alt_name but not name", errors.iterator().next().getMessage());
    147         assertEquals("3000_*[.+_name][!name]", errors.iterator().next().getIgnoreSubGroup());
     147        assertEquals("3000_has alt_name but not name", errors.iterator().next().getIgnoreSubGroup());
    148148    }
    149149
    150150    /**
     
    159159        final Collection<TestError> errors = test.getErrorsForPrimitive(p, false);
    160160        assertEquals(1, errors.size());
    161161        assertEquals("footway used with foot=no", errors.iterator().next().getMessage());
    162         assertEquals("3000_way[highway=footway][foot]", errors.iterator().next().getIgnoreSubGroup());
     162        assertEquals("3000_footway used with foot=no", errors.iterator().next().getIgnoreSubGroup());
    163163    }
    164164
    165165    /**
     
    413413        }
    414414    }
    415415
     416    /**
     417     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/19053">Bug #19053</a>.
     418     * Mapcss rule with group.
     419     * @throws ParseException if a parsing error occurs
     420     */
     421    @Test
     422    public void testTicket19053() throws ParseException {
     423        final MapCSSTagChecker test = buildTagChecker(
     424                "*[ele][ele =~ /^-?[0-9]+\\.[0-9][0-9][0-9]+$/] {"
     425                        + "throwWarning: tr(\"{0}\",\"{0.tag}\");"
     426                        + "group: tr(\"Unnecessary amount of decimal places\");" + "}");
     427        final OsmPrimitive p = OsmUtils.createPrimitive("node ele=12.123456");
     428        final Collection<TestError> errors = test.getErrorsForPrimitive(p, false);
     429        assertEquals(1, errors.size());
     430        assertEquals("Unnecessary amount of decimal places", errors.iterator().next().getMessage());
     431        assertEquals("3000_ele=12.123456", errors.iterator().next().getIgnoreSubGroup());
     432        assertEquals("3000_Unnecessary amount of decimal places", errors.iterator().next().getIgnoreGroup());
     433    }
     434
    416435}