Ticket #4646: 4646.patch
| File 4646.patch, 6.8 KB (added by , 15 years ago) |
|---|
-
src/org/openstreetmap/josm/data/validation/tests/UntaggedNode.java
diff --git a/src/org/openstreetmap/josm/data/validation/tests/UntaggedNode.java b/src/org/openstreetmap/josm/data/validation/tests/UntaggedNode.java index d6eb236..0ee9003 100644
a b import static org.openstreetmap.josm.tools.I18n.marktr; 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 7 import java.util.Collection; 8 import java.util.HashMap; 9 import java.util.LinkedList; 8 10 import java.util.Map; 9 11 10 12 import org.openstreetmap.josm.Main; … … import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 17 import org.openstreetmap.josm.data.validation.Severity; 16 18 import org.openstreetmap.josm.data.validation.Test; 17 19 import org.openstreetmap.josm.data.validation.TestError; 18 import org.openstreetmap.josm.gui.progress.ProgressMonitor;19 20 20 21 /** 21 22 * Checks for nodes with uninteresting tags that are in no way … … public class UntaggedNode extends Test { 41 42 } 42 43 43 44 @Override 44 public void startTest(ProgressMonitor monitor) {45 super.startTest(monitor);46 }47 48 @Override49 45 public void visit(Collection<OsmPrimitive> selection) { 50 46 for (OsmPrimitive p : selection) { 51 47 if (p.isUsable() && p instanceof Node) { … … public class UntaggedNode extends Test { 54 50 } 55 51 } 56 52 53 Map<Integer,TestError> fixableErrors = new HashMap<Integer, TestError>(); 54 57 55 @Override 58 56 public void visit(Node n) { 59 if(n.isUsable() && !n.isTagged() && n.getReferrers().isEmpty()) { 57 if (n.isUsable() && !n.isTagged() && n.getReferrers().isEmpty() 58 && Main.main.getCurrentDataSet().getDataSourceArea().contains(n.getCoor())) { 60 59 if (!n.hasKeys()) { 61 String msg = marktr("No tags"); 62 errors.add(new TestError(this, Severity.WARNING, tr("Unconnected nodes without physical tags"), tr(msg), msg, UNTAGGED_NODE_BLANK, n)); 60 addError(marktr("No tags"), UNTAGGED_NODE_BLANK, n); 63 61 return; 64 62 } 65 63 for (Map.Entry<String, String> tag : n.getKeys().entrySet()) { … … public class UntaggedNode extends Test { 67 65 if (contains(tag, "fixme") || contains(tag, "FIXME")) { 68 66 /* translation note: don't translate quoted words */ 69 67 String msg = marktr("Has tag containing ''fixme'' or ''FIXME''"); 70 errors.add(new TestError(this, Severity.WARNING, tr("Unconnected nodes without physical tags"), 71 tr(msg), msg, UNTAGGED_NODE_FIXME, n)); 68 addError(msg, UNTAGGED_NODE_FIXME, n); 72 69 return; 73 70 } 74 71 75 String msg = null;76 int code = 0;77 72 if (key.startsWith("note") || key.startsWith("comment") || key.startsWith("description")) { 78 73 /* translation note: don't translate quoted words */ 79 msg = marktr("Has key ''note'' or ''comment'' or ''description''"); 80 code = UNTAGGED_NODE_NOTE; 74 String msg = marktr("Has key ''note'' or ''comment'' or ''description''"); 75 addError(msg, UNTAGGED_NODE_NOTE, n); 76 return; 81 77 } else if (key.startsWith("created_by") || key.startsWith("converted_by")) { 82 78 /* translation note: don't translate quoted words */ 83 msg = marktr("Has key ''created_by'' or ''converted_by''"); 84 code = UNTAGGED_NODE_CREATED_BY; 79 String msg = marktr("Has key ''created_by'' or ''converted_by''"); 80 addError(msg, UNTAGGED_NODE_CREATED_BY, n); 81 return; 85 82 } else if (key.startsWith("watch")) { 86 83 /* translation note: don't translate quoted words */ 87 msg = marktr("Has key ''watch''"); 88 code = UNTAGGED_NODE_WATCH; 84 String msg = marktr("Has key ''watch''"); 85 addError(msg, UNTAGGED_NODE_WATCH, n); 86 return; 89 87 } else if (key.startsWith("source")) { 90 88 /* translation note: don't translate quoted words */ 91 msg = marktr("Has key ''source''"); 92 code = UNTAGGED_NODE_SOURCE; 93 } 94 if (msg != null) { 95 errors.add(new TestError(this, Severity.WARNING, tr("Unconnected nodes without physical tags"), 96 tr(msg), msg, code, n)); 89 String msg = marktr("Has key ''source''"); 90 addError(msg, UNTAGGED_NODE_SOURCE, n); 97 91 return; 98 92 } 99 93 } 100 94 // Does not happen, but just to be sure. Maybe definition of uninteresting tags changes in future. 101 errors.add(new TestError(this, Severity.WARNING, tr("Unconnected nodes without physical tags"), 102 tr("Other"), "Other", UNTAGGED_NODE_OTHER, n)); 95 addError(tr("Other"), UNTAGGED_NODE_OTHER, n); 96 } 97 } 98 99 @SuppressWarnings("unchecked") 100 private void addError(String msg, int code, OsmPrimitive n) { 101 final String errMsg = tr("Unconnected nodes without physical tags"); 102 if (!isFixable(code)) { 103 errors.add(new TestError(this, Severity.WARNING, errMsg, tr(msg), msg, code, n)); 104 } else { 105 TestError err = fixableErrors.get(code); 106 if (err == null) { 107 err = new TestError(this, Severity.WARNING, errMsg, tr(msg), msg, 108 code, new LinkedList<OsmPrimitive>()); 109 fixableErrors.put(code, err); 110 errors.add(err); 111 } 112 ((Collection<OsmPrimitive>) err.getPrimitives()).add(n); 103 113 } 104 114 } 105 115 106 116 private boolean contains(Map.Entry<String, String> tag, String s) { 107 return tag.getKey(). indexOf(s) != -1 || tag.getValue().indexOf(s) != -1;117 return tag.getKey().contains(s) || tag.getValue().contains(s); 108 118 } 109 119 110 120 @Override … … public class UntaggedNode extends Test { 115 125 @Override 116 126 public boolean isFixable(TestError testError) { 117 127 if (testError.getTester() instanceof UntaggedNode) { 118 int code = testError.getCode(); 119 switch (code) { 128 return isFixable(testError.getCode()); 129 } 130 return false; 131 } 132 133 private boolean isFixable(int code) { 134 switch (code) { 120 135 case UNTAGGED_NODE_BLANK: 121 136 case UNTAGGED_NODE_CREATED_BY: 122 137 case UNTAGGED_NODE_WATCH: 123 138 case UNTAGGED_NODE_SOURCE: 124 139 return true; 125 } 140 default: 141 return false; 126 142 } 127 return false;128 143 } 129 144 }
