Ticket #17561: 17561.diff

File 17561.diff, 4.5 KB (added by GerdP, 5 years ago)
  • src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java

     
    185185
    186186        if (via.get(0) instanceof Node) {
    187187            final Node viaNode = (Node) via.get(0);
    188             final Way viaPseudoWay = new Way();
    189             viaPseudoWay.addNode(viaNode);
    190             checkIfConnected(fromWay, viaPseudoWay,
    191                     tr("The \"from\" way does not start or end at a \"via\" node."), FROM_VIA_NODE);
    192             if (toWay.isOneway() != 0 && viaNode.equals(toWay.lastNode(true))) {
     188            if (isFullOneway(toWay) && viaNode.equals(toWay.lastNode(true))) {
    193189                errors.add(TestError.builder(this, Severity.WARNING, SUPERFLUOUS)
    194190                        .message(tr("Superfluous turnrestriction as \"to\" way is oneway"))
    195191                        .primitives(r)
     192                        .highlight(toWay)
    196193                        .build());
    197194                return;
    198195            }
    199             checkIfConnected(viaPseudoWay, toWay,
     196            if (isFullOneway(fromWay) && viaNode.equals(fromWay.firstNode(true))) {
     197                errors.add(TestError.builder(this, Severity.WARNING, SUPERFLUOUS)
     198                        .message(tr("Superfluous turnrestriction as \"from\" way is oneway"))
     199                        .primitives(r)
     200                        .highlight(fromWay)
     201                        .build());
     202                return;
     203            }
     204            final Way viaPseudoWay = new Way();
     205            viaPseudoWay.addNode(viaNode);
     206            checkIfConnected(r, fromWay, viaPseudoWay,
     207                    tr("The \"from\" way does not start or end at a \"via\" node."), FROM_VIA_NODE);
     208            checkIfConnected(r, viaPseudoWay, toWay,
    200209                    tr("The \"to\" way does not start or end at a \"via\" node."), TO_VIA_NODE);
    201210        } else {
    202211            // check if consecutive ways are connected: from/via[0], via[i-1]/via[i], via[last]/to
    203             checkIfConnected(fromWay, (Way) via.get(0),
     212            checkIfConnected(r, fromWay, (Way) via.get(0),
    204213                    tr("The \"from\" and the first \"via\" way are not connected."), FROM_VIA_WAY);
    205214            if (via.size() > 1) {
    206215                for (int i = 1; i < via.size(); i++) {
    207216                    Way previous = (Way) via.get(i - 1);
    208217                    Way current = (Way) via.get(i);
    209                     checkIfConnected(previous, current,
     218                    checkIfConnected(r, previous, current,
    210219                            tr("The \"via\" ways are not connected."), UNCONNECTED_VIA);
    211220                }
    212221            }
     
    217226                        .build());
    218227                return;
    219228            }
    220             checkIfConnected((Way) via.get(via.size() - 1), toWay,
     229            checkIfConnected(r, (Way) via.get(via.size() - 1), toWay,
    221230                    tr("The last \"via\" and the \"to\" way are not connected."), TO_VIA_WAY);
    222231        }
    223232    }
     
    226235        return w.isOneway() != 0 && !w.hasTag("oneway:bicycle", "no");
    227236    }
    228237
    229     private void checkIfConnected(Way previous, Way current, String msg, int code) {
     238    private void checkIfConnected(Relation r, Way previous, Way current, String msg, int code) {
    230239        boolean c;
    231240        if (isFullOneway(previous) && isFullOneway(current)) {
    232241            // both oneways: end/start node must be equal
     
    242251            c = current.isFirstLastNode(previous.firstNode()) || current.isFirstLastNode(previous.lastNode());
    243252        }
    244253        if (!c) {
     254            List<OsmPrimitive> hilite = new ArrayList<>();
     255            if (previous.getNodesCount() == 1 && previous.isNew())
     256                hilite.add(previous.firstNode());
     257            else
     258                hilite.add(previous);
     259            if (current.getNodesCount() == 1 && current.isNew())
     260                hilite.add(current.firstNode());
     261            else
     262                hilite.add(current);
     263            List<OsmPrimitive> primitives = new ArrayList<>();
     264            primitives.add(r);
     265            primitives.addAll(hilite);
    245266            errors.add(TestError.builder(this, Severity.ERROR, code)
    246267                    .message(msg)
    247                     .primitives(previous, current)
     268                    .primitives(primitives)
     269                    .highlight(hilite)
    248270                    .build());
    249271        }
    250272    }