source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedNode.java@ 10046

Last change on this file since 10046 was 10046, checked in by Don-vip, 8 years ago

sonar - squid:S1449 - Locale should be used in String operations
sonar - squid:S2177 - Child class methods named for parent class methods should be overrides

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.validation.tests;
3
4import static org.openstreetmap.josm.tools.I18n.marktr;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.util.Locale;
8
9import org.openstreetmap.josm.command.Command;
10import org.openstreetmap.josm.data.osm.AbstractPrimitive;
11import org.openstreetmap.josm.data.osm.Node;
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.data.validation.Severity;
14import org.openstreetmap.josm.data.validation.Test;
15import org.openstreetmap.josm.data.validation.TestError;
16
17/**
18 * Checks for nodes with uninteresting tags that are in no way
19 *
20 * @author frsantos
21 */
22public class UntaggedNode extends Test implements AbstractPrimitive.KeyValueVisitor {
23
24 protected static final int UNTAGGED_NODE_BLANK = 201;
25 protected static final int UNTAGGED_NODE_FIXME = 202;
26 protected static final int UNTAGGED_NODE_NOTE = 203;
27 protected static final int UNTAGGED_NODE_CREATED_BY = 204;
28 protected static final int UNTAGGED_NODE_WATCH = 205;
29 protected static final int UNTAGGED_NODE_SOURCE = 206;
30 protected static final int UNTAGGED_NODE_OTHER = 207;
31 protected static final String ERROR_MESSAGE = tr("Unconnected nodes without physical tags");
32
33 /**
34 * Constructor
35 */
36 public UntaggedNode() {
37 super(tr("Untagged and unconnected nodes"),
38 tr("This test checks for untagged nodes that are not part of any way."));
39 }
40
41 @Override
42 public void visit(Node n) {
43 if (n.isUsable() && !n.isTagged() && n.getReferrers().isEmpty()) {
44
45 if (!n.hasKeys() && IN_DOWNLOADED_AREA.evaluate(n)) {
46 String msg = marktr("No tags");
47 errors.add(new TestError(this, Severity.WARNING, ERROR_MESSAGE, tr(msg), msg, UNTAGGED_NODE_BLANK, n));
48 return;
49 }
50 n.visitKeys(this);
51 }
52 }
53
54 @Override
55 public void visitKeyValue(AbstractPrimitive n, String key, String value) {
56 if (key.toLowerCase(Locale.ENGLISH).contains("fixme") || value.toLowerCase(Locale.ENGLISH).contains("fixme")) {
57 /* translation note: don't translate quoted words */
58 String msg = marktr("Has tag containing ''fixme'' or ''FIXME''");
59 errors.add(new TestError(this, Severity.WARNING, ERROR_MESSAGE, tr(msg), msg, UNTAGGED_NODE_FIXME, (OsmPrimitive) n));
60 return;
61 }
62
63 String msg = null;
64 int code = 0;
65 if (key.startsWith("note") || key.startsWith("comment") || key.startsWith("description")) {
66 /* translation note: don't translate quoted words */
67 msg = marktr("Has key ''note'' or ''comment'' or ''description''");
68 code = UNTAGGED_NODE_NOTE;
69 } else if (key.startsWith("created_by") || key.startsWith("converted_by")) {
70 /* translation note: don't translate quoted words */
71 msg = marktr("Has key ''created_by'' or ''converted_by''");
72 code = UNTAGGED_NODE_CREATED_BY;
73 } else if (key.startsWith("watch")) {
74 /* translation note: don't translate quoted words */
75 msg = marktr("Has key ''watch''");
76 code = UNTAGGED_NODE_WATCH;
77 } else if (key.startsWith("source")) {
78 /* translation note: don't translate quoted words */
79 msg = marktr("Has key ''source''");
80 code = UNTAGGED_NODE_SOURCE;
81 }
82 if (msg != null) {
83 errors.add(new TestError(this, Severity.WARNING, ERROR_MESSAGE, tr(msg), msg, code, (OsmPrimitive) n));
84 return;
85 }
86 // Does not happen, but just to be sure. Maybe definition of uninteresting tags changes in future.
87 errors.add(new TestError(this, Severity.WARNING, ERROR_MESSAGE, tr("Other"), "Other", UNTAGGED_NODE_OTHER, (OsmPrimitive) n));
88 }
89
90 @Override
91 public Command fixError(TestError testError) {
92 return deletePrimitivesIfNeeded(testError.getPrimitives());
93 }
94
95 @Override
96 public boolean isFixable(TestError testError) {
97 if (testError.getTester() instanceof UntaggedNode) {
98 int code = testError.getCode();
99 switch (code) {
100 case UNTAGGED_NODE_BLANK:
101 case UNTAGGED_NODE_CREATED_BY:
102 case UNTAGGED_NODE_WATCH:
103 case UNTAGGED_NODE_SOURCE:
104 return true;
105 }
106 }
107 return false;
108 }
109}
Note: See TracBrowser for help on using the repository browser.