Changeset 15071 in josm for trunk/src


Ignore:
Timestamp:
2019-05-11T21:15:10+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #17709 - make TurnrestrictionTest aware of conditional restrictions

Location:
trunk/src/org/openstreetmap/josm/data/validation/tests
Files:
2 edited

Legend:

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

    r14879 r15071  
    3838            /*,"hov","emergency","hazmat","disabled"*/));
    3939
     40    private static final Pattern CONDITIONAL_PATTERN;
     41    static {
     42        final String part = Pattern.compile("([^@\\p{Space}][^@]*?)"
     43                + "\\s*@\\s*" + "(\\([^)\\p{Space}][^)]+?\\)|[^();\\p{Space}][^();]*?)\\s*").toString();
     44        CONDITIONAL_PATTERN = Pattern.compile('(' + part + ")(;\\s*" + part + ")*");
     45    }
     46
    4047    /**
    4148     * Constructs a new {@code ConditionalKeys}.
     
    164171            // <restriction-value> @ <condition>[;<restriction-value> @ <condition>]
    165172            final List<ConditionalValue> r = new ArrayList<>();
    166             final String part = Pattern.compile("([^@\\p{Space}][^@]*?)"
    167                     + "\\s*@\\s*" + "(\\([^)\\p{Space}][^)]+?\\)|[^();\\p{Space}][^();]*?)\\s*").toString();
    168             final Matcher m = Pattern.compile('(' + part + ")(;\\s*" + part + ")*").matcher(value);
     173            final Matcher m = CONDITIONAL_PATTERN.matcher(value);
    169174            if (!m.matches()) {
    170175                throw new ConditionalParsingException(tr("Does not match pattern ''restriction value @ condition''"));
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java

    r15019 r15071  
    1616import org.openstreetmap.josm.data.validation.Test;
    1717import org.openstreetmap.josm.data.validation.TestError;
     18import org.openstreetmap.josm.data.validation.tests.ConditionalKeys.ConditionalParsingException;
     19import org.openstreetmap.josm.data.validation.tests.ConditionalKeys.ConditionalValue;
     20import org.openstreetmap.josm.tools.Logging;
    1821
    1922/**
     
    5659    }
    5760
     61    private static boolean hasSupportedRestrictionTag(Relation r) {
     62        if (r.hasTag("restriction", SUPPORTED_RESTRICTIONS))
     63            return true;
     64        String conditionalValue = r.get("restriction:conditional");
     65        if (conditionalValue != null) {
     66            try {
     67                List<ConditionalValue> values = ConditionalValue.parse(conditionalValue);
     68                return !values.isEmpty() && SUPPORTED_RESTRICTIONS.contains(values.get(0).restrictionValue);
     69            } catch (ConditionalParsingException e) {
     70                Logging.trace(e);
     71            }
     72        }
     73        return false;
     74    }
     75
    5876    @Override
    5977    public void visit(Relation r) {
     
    6179            return;
    6280
    63         if (!r.hasTag("restriction", SUPPORTED_RESTRICTIONS)) {
     81        if (!hasSupportedRestrictionTag(r)) {
    6482            errors.add(TestError.builder(this, Severity.ERROR, UNKNOWN_RESTRICTION)
    6583                    .message(tr("Unknown turn restriction"))
Note: See TracChangeset for help on using the changeset viewer.