Changeset 22043 in osm for applications
- Timestamp:
- 2010-06-27T22:22:36+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UntaggedNode.java
r22004 r22043 2 2 package org.openstreetmap.josm.plugins.validator.tests; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 7 import java.text.MessageFormat; 6 8 import java.util.ArrayList; 7 9 import java.util.Collection; 8 10 import java.util.List; 11 import java.util.Map; 9 12 10 13 import org.openstreetmap.josm.Main; … … 19 22 20 23 /** 21 * Checks for untagged nodes that are in no way24 * Checks for nodes with uninteresting tags that are in no way 22 25 * 23 26 * @author frsantos … … 25 28 public class UntaggedNode extends Test 26 29 { 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; 32 37 33 38 /** … … 44 49 { 45 50 super.startTest(monitor); 46 emptyNodes = new ArrayList<Node>();47 51 } 48 52 … … 60 64 public void visit(Node n) 61 65 { 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 } 64 107 } 65 108 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; 78 111 } 79 112 … … 85 118 86 119 @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; 90 132 } 91 133 }
Note:
See TracChangeset
for help on using the changeset viewer.