Ignore:
Timestamp:
2010-06-27T22:22:36+02:00 (14 years ago)
Author:
bastik
Message:

see josm bug 5174 (adds more categories for unconnected nodes with no physical tags)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UntaggedNode.java

    r22004 r22043  
    22package org.openstreetmap.josm.plugins.validator.tests;
    33
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56
     7import java.text.MessageFormat;
    68import java.util.ArrayList;
    79import java.util.Collection;
    810import java.util.List;
     11import java.util.Map;
    912
    1013import org.openstreetmap.josm.Main;
     
    1922
    2023/**
    21  * Checks for untagged nodes that are in no way
     24 * Checks for nodes with uninteresting tags that are in no way
    2225 *
    2326 * @author frsantos
     
    2528public class UntaggedNode extends Test
    2629{
    27     protected static int UNTAGGED_NODE = 201;
    28     protected static int COMMENT_NODE = 202;
    29 
    30     /** Bag of all nodes */
    31     List<Node> emptyNodes;
     30    protected static final int UNTAGGED_NODE_BLANK = 201;
     31    protected static final int UNTAGGED_NODE_FIXME = 202;
     32    protected static final int UNTAGGED_NODE_NOTE = 203;
     33    protected static final int UNTAGGED_NODE_CREATED_BY = 204;
     34    protected static final int UNTAGGED_NODE_WATCH = 205;
     35    protected static final int UNTAGGED_NODE_SOURCE = 206;
     36    protected static final int UNTAGGED_NODE_OTHER = 207;
    3237
    3338    /**
     
    4449    {
    4550        super.startTest(monitor);
    46         emptyNodes = new ArrayList<Node>();
    4751    }
    4852
     
    6064    public void visit(Node n)
    6165    {
    62         if(n.isUsable() && !n.isTagged() && n.getReferrers().isEmpty())
    63             emptyNodes.add(n);
     66        if(n.isUsable() && !n.isTagged() && n.getReferrers().isEmpty()) {
     67            if (!n.hasKeys()) {
     68                String msg = marktr("No tags");
     69                errors.add(new TestError(this, Severity.OTHER, tr("Unconnected nodes without physical tags"), tr(msg), msg, UNTAGGED_NODE_BLANK, n));
     70                return;
     71            }
     72            for (Map.Entry<String, String> tag : n.getKeys().entrySet()) {
     73                String key = tag.getKey();
     74                String value = tag.getValue();
     75                if (contains(tag, "fixme") || contains(tag, "FIXME")) {
     76                    String msg = marktr("Has tag containing ''fixme'' or ''FIXME''"); // translation note: don't translate quoted words
     77                    errors.add(new TestError(this, Severity.OTHER, tr("Unconnected nodes without physical tags"),
     78                                tr(msg), msg, UNTAGGED_NODE_FIXME, n));
     79                    return;
     80                }
     81
     82                String msg = null;
     83                int code = 0;
     84                if (key.startsWith("note") || key.startsWith("comment") || key.startsWith("description")) {
     85                    msg = marktr("Has key ''note'' or ''comment'' or ''description''"); // translation note: don't translate quoted words
     86                    code = UNTAGGED_NODE_NOTE;
     87                } else if (key.startsWith("created_by") || key.startsWith("converted_by")) {
     88                    msg = marktr("Has key ''created_by'' or ''converted_by''"); // translation note: don't translate quoted words
     89                    code = UNTAGGED_NODE_CREATED_BY;
     90                } else if (key.startsWith("watch")) {
     91                    msg = marktr("Has key ''watch''"); // translation note: don't translate quoted words
     92                    code = UNTAGGED_NODE_WATCH;
     93                } else if (key.startsWith("source")) {
     94                    msg = marktr("Has key ''source''"); // translation note: don't translate quoted words
     95                    code = UNTAGGED_NODE_SOURCE;
     96                }
     97                if (msg != null) {
     98                    errors.add(new TestError(this, Severity.OTHER, tr("Unconnected nodes without physical tags"),
     99                                tr(msg), msg, code, n));
     100                    return;
     101                }
     102            }
     103            // Does not happen, but just to be sure. Maybe definition of uninteresting tags changes in future.
     104            errors.add(new TestError(this, Severity.OTHER, tr("Unconnected nodes without physical tags"),
     105                        tr("Other"), "Other", UNTAGGED_NODE_OTHER, n));
     106        }
    64107    }
    65108
    66     @Override
    67     public void endTest()
    68     {
    69         for(Node node : emptyNodes)
    70         {
    71             if(node.hasKeys())
    72                 errors.add( new TestError(this, Severity.OTHER, tr("Untagged and unconnected nodes (commented)"), COMMENT_NODE, node) );
    73             else
    74                 errors.add( new TestError(this, Severity.OTHER, tr("Untagged and unconnected nodes"), UNTAGGED_NODE, node) );
    75         }
    76         emptyNodes = null;
    77         super.endTest();
     109    private boolean contains(Map.Entry<String, String> tag, String s) {
     110        return tag.getKey().indexOf(s) != -1 || tag.getValue().indexOf(s) != -1;
    78111    }
    79112
     
    85118
    86119    @Override
    87     public boolean isFixable(TestError testError)
    88     {
    89         return (testError.getTester() instanceof UntaggedNode);
     120    public boolean isFixable(TestError testError) {
     121        if (testError.getTester() instanceof UntaggedNode) {
     122            int code = testError.getCode();
     123            switch (code) {
     124                case UNTAGGED_NODE_BLANK:
     125                case UNTAGGED_NODE_CREATED_BY:
     126                case UNTAGGED_NODE_WATCH:
     127                case UNTAGGED_NODE_SOURCE:
     128                    return true;
     129            }
     130        }
     131        return false;
    90132    }
    91133}
Note: See TracChangeset for help on using the changeset viewer.