Ticket #24280: PATCH_no_entry_validator.diff

File PATCH_no_entry_validator.diff, 8.1 KB (added by osm-utf-8, 11 months ago)
  • src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java

     
    2121
    2222/**
    2323 * Checks if turn restrictions are valid
     24 *
    2425 * @since 3669
    2526 */
    2627public class TurnrestrictionTest extends Test {
     
    8687            return;
    8788        }
    8889
    89         Way fromWay = null;
     90        List<Way> fromWays = new ArrayList<>();
    9091        Way toWay = null;
    9192        List<OsmPrimitive> via = new ArrayList<>();
    9293
    93         boolean morefrom = false;
    9494        boolean moreto = false;
    9595        boolean morevia = false;
    9696        boolean mixvia = false;
     
    111111
    112112                switch (m.getRole()) {
    113113                case "from":
    114                     if (fromWay != null) {
    115                         morefrom = true;
    116                     } else {
    117                         fromWay = w;
    118                     }
     114                    fromWays.add(w);
    119115                    break;
    120116                case "to":
    121117                    if (toWay != null) {
     
    128124                    if (!via.isEmpty() && via.get(0) instanceof Node) {
    129125                        mixvia = true;
    130126                    } else {
    131                         via.add(w);
     127                        via.add(w);                       
    132128                    }
    133129                    break;
    134130                default:
     
    165161                        .build());
    166162            }
    167163        }
    168         if (morefrom) {
    169             errors.add(TestError.builder(this, Severity.ERROR, MORE_FROM)
    170                     .message(tr("More than one \"from\" way found"))
    171                     .primitives(r)
    172                     .build());
    173             return;
     164        if (fromWays.size() > 1) {
     165            if (!r.hasTag("restriction", "no_entry")) {
     166
     167                errors.add(TestError.builder(this, Severity.ERROR, MORE_FROM)
     168                        .message(tr("More than one \"from\" way found"))
     169                        .primitives(r)
     170                        .build());
     171                return;
     172            }
    174173        }
    175174        if (moreto) {
    176175            errors.add(TestError.builder(this, Severity.ERROR, MORE_TO)
     
    194193            return;
    195194        }
    196195
    197         if (fromWay == null) {
     196        if (fromWays.isEmpty()) {
    198197            errors.add(TestError.builder(this, Severity.ERROR, NO_FROM)
    199198                    .message(tr("No \"from\" way found"))
    200199                    .primitives(r)
    201200                    .build());
    202201            return;
    203         } else if (fromWay.isClosed()) {
    204             errors.add(TestError.builder(this, Severity.ERROR, FROM_CLOSED_WAY)
    205                     .message(tr("\"from\" way is a closed way"))
    206                     .primitives(r)
    207                     .highlight(fromWay)
    208                     .build());
    209             return;
    210         }
     202        } else
    211203
     204            for (Way fromWay : fromWays) {
     205                if (fromWay.isClosed()) {
     206                    errors.add(TestError.builder(this, Severity.ERROR, FROM_CLOSED_WAY)
     207                            .message(tr("\"from\" way is a closed way"))
     208                            .primitives(r)
     209                            .highlight(fromWay)
     210                            .build());
     211                    return;
     212                }
     213            }
     214
    212215        if (toWay == null) {
    213216            errors.add(TestError.builder(this, Severity.ERROR, NO_TO)
    214217                    .message(tr("No \"to\" way found"))
     
    223226                    .build());
    224227            return;
    225228        }
    226         if (fromWay.equals(toWay)) {
    227             Severity severity = r.hasTag("restriction", "no_u_turn") ? Severity.OTHER : Severity.WARNING;
    228             errors.add(TestError.builder(this, severity, FROM_EQUALS_TO)
    229                     .message(tr("\"from\" way equals \"to\" way"))
    230                     .primitives(r)
    231                     .build());
     229        for (Way fromWay : fromWays) {
     230
     231            if (fromWay.equals(toWay)) {
     232                Severity severity = r.hasTag("restriction", "no_u_turn") ? Severity.OTHER : Severity.WARNING;
     233                errors.add(TestError.builder(this, severity, FROM_EQUALS_TO)
     234                        .message(tr("\"from\" way equals \"to\" way"))
     235                        .primitives(r)
     236                        .build());
     237            }
    232238        }
    233239        if (via.isEmpty()) {
    234240            errors.add(TestError.builder(this, Severity.ERROR, NO_VIA)
     
    248254                        .build());
    249255                return;
    250256            }
    251             if (isFullOneway(fromWay) && viaNode.equals(fromWay.firstNode(true))) {
    252                 errors.add(TestError.builder(this, Severity.WARNING, SUPERFLUOUS)
     257            if (fromWays.size() == 1){
     258                Way fromWay = fromWays.get(0);
     259                if (isFullOneway(fromWay) && viaNode.equals(fromWay.firstNode(true))) {
     260                    errors.add(TestError.builder(this, Severity.WARNING, SUPERFLUOUS)
    253261                        .message(tr("Superfluous turn restriction as \"from\" way is oneway"))
    254262                        .primitives(r)
    255263                        .highlight(fromWay)
    256264                        .build());
    257                 return;
     265                    return;
     266                }
    258267            }
    259             if (!fromWay.isFirstLastNode(viaNode)) {
    260                 errors.add(TestError.builder(this, Severity.WARNING, FROM_VIA_NODE)
    261                         .message(tr("The \"from\" way does not start or end at a \"via\" node."))
    262                         .primitives(r, fromWay, viaNode)
    263                         .highlight(fromWay, viaNode)
    264                         .build());
     268
     269            for (Way fromWay : fromWays) {
     270 
     271                if (!fromWay.isFirstLastNode(viaNode)) {
     272                    errors.add(TestError.builder(this, Severity.WARNING, FROM_VIA_NODE)
     273                            .message(tr("The \"from\" way does not start or end at a \"via\" node."))
     274                            .primitives(r, fromWay, viaNode)
     275                            .highlight(fromWay, viaNode)
     276                            .build());
     277                }
    265278            }
    266279            if (!toWay.isFirstLastNode(viaNode)) {
    267280                errors.add(TestError.builder(this, Severity.WARNING, TO_VIA_NODE)
     
    279292                        .build());
    280293                return;
    281294            }
    282             if (isFullOneway(fromWay) && ((Way) via.get(0)).isFirstLastNode(fromWay.firstNode(true))) {
    283                 errors.add(TestError.builder(this, Severity.WARNING, SUPERFLUOUS)
    284                         .message(tr("Superfluous turn restriction as \"from\" way is oneway"))
    285                         .primitives(r)
    286                         .highlight(fromWay)
    287                         .build());
    288                 return;
     295            if (fromWays.size() == 1) {
     296                Way fromWay = fromWays.get(0);
     297                if (isFullOneway(fromWay) && ((Way) via.get(0)).isFirstLastNode(fromWay.firstNode(true))) {
     298                    errors.add(TestError.builder(this, Severity.WARNING, SUPERFLUOUS)
     299                            .message(tr("Superfluous turn restriction as \"from\" way is oneway"))
     300                            .primitives(r)
     301                            .highlight(fromWay)
     302                            .build());
     303                    return;
     304                }
    289305            }
    290306            // check if consecutive ways are connected: from/via[0], via[i-1]/via[i], via[last]/to
    291             checkIfConnected(r, fromWay, (Way) via.get(0),
    292                     tr("The \"from\" and the first \"via\" way are not connected."), FROM_VIA_WAY);
     307            for (Way fromWay : fromWays) {
     308                checkIfConnected(r, fromWay, (Way) via.get(0),
     309                        tr("The \"from\" and the first \"via\" way are not connected."), FROM_VIA_WAY);
     310            }
    293311            if (via.size() > 1) {
    294312                for (int i = 1; i < via.size(); i++) {
    295313                    Way previous = (Way) via.get(i - 1);