Changeset 8743 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2015-09-10T09:00:45+02:00 (9 years ago)
Author:
simon04
Message:

see #11834 - Use KeyValueVisitor in the UntaggedNode test

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

Legend:

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

    r8378 r8743  
    99
    1010import org.openstreetmap.josm.command.Command;
     11import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    1112import org.openstreetmap.josm.data.osm.Node;
    1213import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2021 * @author frsantos
    2122 */
    22 public class UntaggedNode extends Test {
     23public class UntaggedNode extends Test implements AbstractPrimitive.KeyValueVisitor {
    2324
    2425    protected static final int UNTAGGED_NODE_BLANK = 201;
     
    2930    protected static final int UNTAGGED_NODE_SOURCE = 206;
    3031    protected static final int UNTAGGED_NODE_OTHER = 207;
     32    protected static final String ERROR_MESSAGE = tr("Unconnected nodes without physical tags");
    3133
    3234    /**
     
    5052    public void visit(Node n) {
    5153        if (n.isUsable() && !n.isTagged() && n.getReferrers().isEmpty()) {
    52             String errorMessage = tr("Unconnected nodes without physical tags");
     54
    5355            if (!n.hasKeys()) {
    5456                String msg = marktr("No tags");
    55                 errors.add(new TestError(this, Severity.WARNING, errorMessage, tr(msg), msg, UNTAGGED_NODE_BLANK, n));
     57                errors.add(new TestError(this, Severity.WARNING, ERROR_MESSAGE, tr(msg), msg, UNTAGGED_NODE_BLANK, n));
    5658                return;
    5759            }
    58             for (Map.Entry<String, String> tag : n.getKeys().entrySet()) {
    59                 String key = tag.getKey();
    60                 if (contains(tag, "fixme") || contains(tag, "FIXME")) {
    61                     /* translation note: don't translate quoted words */
    62                     String msg = marktr("Has tag containing ''fixme'' or ''FIXME''");
    63                     errors.add(new TestError(this, Severity.WARNING, errorMessage, tr(msg), msg, UNTAGGED_NODE_FIXME, n));
    64                     return;
    65                 }
     60            n.visitKeys(this);
     61        }
     62    }
    6663
    67                 String msg = null;
    68                 int code = 0;
    69                 if (key.startsWith("note") || key.startsWith("comment") || key.startsWith("description")) {
    70                     /* translation note: don't translate quoted words */
    71                     msg = marktr("Has key ''note'' or ''comment'' or ''description''");
    72                     code = UNTAGGED_NODE_NOTE;
    73                 } else if (key.startsWith("created_by") || key.startsWith("converted_by")) {
    74                     /* translation note: don't translate quoted words */
    75                     msg = marktr("Has key ''created_by'' or ''converted_by''");
    76                     code = UNTAGGED_NODE_CREATED_BY;
    77                 } else if (key.startsWith("watch")) {
    78                     /* translation note: don't translate quoted words */
    79                     msg = marktr("Has key ''watch''");
    80                     code = UNTAGGED_NODE_WATCH;
    81                 } else if (key.startsWith("source")) {
    82                     /* translation note: don't translate quoted words */
    83                     msg = marktr("Has key ''source''");
    84                     code = UNTAGGED_NODE_SOURCE;
    85                 }
    86                 if (msg != null) {
    87                     errors.add(new TestError(this, Severity.WARNING, errorMessage, tr(msg), msg, code, n));
    88                     return;
    89                 }
    90             }
    91             // Does not happen, but just to be sure. Maybe definition of uninteresting tags changes in future.
    92             errors.add(new TestError(this, Severity.WARNING, errorMessage, tr("Other"), "Other", UNTAGGED_NODE_OTHER, n));
     64    @Override
     65    public void visitKeyValue(AbstractPrimitive n, String key, String value) {
     66        if (key.toLowerCase().contains("fixme") || value.toLowerCase().contains("fixme")) {
     67            /* translation note: don't translate quoted words */
     68            String msg = marktr("Has tag containing ''fixme'' or ''FIXME''");
     69            errors.add(new TestError(this, Severity.WARNING, ERROR_MESSAGE, tr(msg), msg, UNTAGGED_NODE_FIXME, (OsmPrimitive) n));
     70            return;
    9371        }
     72
     73        String msg = null;
     74        int code = 0;
     75        if (key.startsWith("note") || key.startsWith("comment") || key.startsWith("description")) {
     76            /* translation note: don't translate quoted words */
     77            msg = marktr("Has key ''note'' or ''comment'' or ''description''");
     78            code = UNTAGGED_NODE_NOTE;
     79        } else if (key.startsWith("created_by") || key.startsWith("converted_by")) {
     80            /* translation note: don't translate quoted words */
     81            msg = marktr("Has key ''created_by'' or ''converted_by''");
     82            code = UNTAGGED_NODE_CREATED_BY;
     83        } else if (key.startsWith("watch")) {
     84            /* translation note: don't translate quoted words */
     85            msg = marktr("Has key ''watch''");
     86            code = UNTAGGED_NODE_WATCH;
     87        } else if (key.startsWith("source")) {
     88            /* translation note: don't translate quoted words */
     89            msg = marktr("Has key ''source''");
     90            code = UNTAGGED_NODE_SOURCE;
     91        }
     92        if (msg != null) {
     93            errors.add(new TestError(this, Severity.WARNING, ERROR_MESSAGE, tr(msg), msg, code, (OsmPrimitive) n));
     94            return;
     95        }
     96        // Does not happen, but just to be sure. Maybe definition of uninteresting tags changes in future.
     97        errors.add(new TestError(this, Severity.WARNING, ERROR_MESSAGE, tr("Other"), "Other", UNTAGGED_NODE_OTHER, (OsmPrimitive) n));
    9498    }
    9599
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedWay.java

    r8510 r8743  
    8383                boolean isJunction = false;
    8484                boolean hasName = false;
    85                 for (String key : w.keySet()) {
     85                for (String key : tags.keySet()) {
    8686                    hasName = key.startsWith("name:") || key.endsWith("_name") || key.endsWith("_ref");
    8787                    if (hasName) {
Note: See TracChangeset for help on using the changeset viewer.