Changeset 14490 in josm for trunk/src


Ignore:
Timestamp:
2018-12-02T16:04:34+01:00 (5 years ago)
Author:
GerdP
Message:

fix #17055 17055-v2.patch with one empty line removed

File:
1 edited

Legend:

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

    r13923 r14490  
    1212import java.util.Arrays;
    1313import java.util.Collection;
     14import java.util.Collections;
    1415import java.util.HashMap;
    1516import java.util.List;
     
    257258                        okValue = line.substring(1);
    258259                    } else if (line.charAt(0) == '-' && okValue != null) {
    259                         harmonizedKeys.put(harmonizeKey(line.substring(1)), okValue);
     260                        String hk = harmonizeKey(line.substring(1));
     261                        if (!okValue.equals(hk)) {
     262                            if (harmonizedKeys.put(hk, okValue) != null) {
     263                                Logging.debug(tr("Line was ignored: {0}", line));
     264                            }
     265                        }
    260266                    } else {
    261267                        Logging.error(tr("Invalid spellcheck line: {0}", line));
     
    313319
    314320    private static void addPresetValue(KeyedItem ky) {
    315         Collection<String> values = ky.getValues();
    316         if (ky.key != null && values != null) {
    317             harmonizedKeys.put(harmonizeKey(ky.key), ky.key);
     321        if (ky.key != null && ky.getValues() != null) {
     322            String hk = harmonizeKey(ky.key);
     323            if (!ky.key.equals(hk)) {
     324                harmonizedKeys.put(hk, ky.key);
     325            }
    318326        }
    319327    }
     
    415423    @Override
    416424    public void check(OsmPrimitive p) {
     425        if (!p.isTagged())
     426            return;
     427
    417428        // Just a collection to know if a primitive has been already marked with error
    418429        MultiMap<OsmPrimitive, String> withErrors = new MultiMap<>();
     
    502513                if (!isKeyInPresets(key)) {
    503514                    String prettifiedKey = harmonizeKey(key);
    504                     String fixedKey = harmonizedKeys.get(prettifiedKey);
     515                    String fixedKey = isKeyInPresets(prettifiedKey) ? prettifiedKey : harmonizedKeys.get(prettifiedKey);
    505516                    if (fixedKey != null && !"".equals(fixedKey) && !fixedKey.equals(key)) {
    506517                        // misspelled preset key
     
    525536                    String fixedValue = harmonizeValue(prop.getValue());
    526537                    Map<String, String> possibleValues = getPossibleValues(getPresetValues(key));
     538                    List<String> fixVals = new ArrayList<>();
     539                    if (!possibleValues.containsKey(fixedValue)) {
     540                        int minDist = 2;
     541                        String closest = null;
     542                        for (String possibleVal : possibleValues.keySet()) {
     543                            int dist = Utils.getLevenshteinDistance(possibleVal, fixedValue);
     544                            if (dist < minDist) {
     545                                closest = possibleVal;
     546                                minDist = dist;
     547                                fixVals.clear();
     548                                fixVals.add(possibleVal);
     549                            } else if (dist == minDist) {
     550                                fixVals.add(possibleVal);
     551                            }
     552                        }
     553                        if (minDist <= 1) {
     554                            if (fixVals.size() < 2) {
     555                                fixedValue = closest;
     556                            } else {
     557                                Collections.sort(fixVals);
     558                                // misspelled preset value with multiple good alternatives
     559                                errors.add(TestError.builder(this, Severity.WARNING, MISSPELLED_VALUE)
     560                                        .message(tr("Misspelled property value"),
     561                                                marktr("Value ''{0}'' for key ''{1}'' looks like one of {2}."), prop.getValue(), key, fixVals)
     562                                        .primitives(p)
     563                                        .build());
     564                                withErrors.put(p, "WPV");
     565                                continue;
     566                            }
     567                        }
     568                    }
    527569                    if (possibleValues.containsKey(fixedValue)) {
    528570                        final String newValue = possibleValues.get(fixedValue);
     
    596638        }
    597639
    598         checkComplex = Config.getPref().getBoolean(PREF_CHECK_COMPLEX, true);
     640        checkComplex = Config.getPref().getBoolean(PREF_CHECK_COMPLEX, true) && !checkerData.isEmpty();
    599641        if (isBeforeUpload) {
    600642            checkComplex = checkComplex && Config.getPref().getBoolean(PREF_CHECK_COMPLEX_BEFORE_UPLOAD, true);
Note: See TracChangeset for help on using the changeset viewer.