Ticket #21423: 21423.patch
| File 21423.patch, 48.8 KB (added by , 3 years ago) |
|---|
-
src/org/openstreetmap/josm/data/validation/OsmValidator.java
163 163 public static void addTest(Class<? extends Test> testClass) { 164 164 allTests.add(testClass); 165 165 try { 166 allTestsMap.put(testClass.getName(), testClass.getConstructor().newInstance()); 166 Test test = testClass.getConstructor().newInstance(); 167 verifyErrorCodes(test); 168 allTestsMap.put(testClass.getName(), test); 167 169 } catch (ReflectiveOperationException e) { 168 170 Logging.error(e); 169 171 } … … 170 172 } 171 173 172 174 /** 175 * Verify that test codes do not overlap 176 * @param test The test to check 177 */ 178 private static void verifyErrorCodes(Test test) { 179 int[] codeRange = test.errorCodes(); 180 if (Arrays.stream(codeRange).distinct().count() != codeRange.length) { 181 // This should eventually become an exception on or after 2023-01-01. 182 Logging.error("Duplicate test codes in {0}", test.getName()); 183 } 184 for (Test other : allTestsMap.values()) { 185 int[] otherCodeRange = other.errorCodes(); 186 int[] duplicates = Arrays.stream(codeRange) 187 .filter(code -> Arrays.stream(otherCodeRange).anyMatch(otherCode -> otherCode == code)).toArray(); 188 if (duplicates.length > 0) { 189 // This should eventually become an exception on or after 2023-01-01. 190 Logging.error("Conflicting test codes: {0} and {1} have {2}", 191 test.getName(), other.getName(), Arrays.toString(duplicates)); 192 } 193 } 194 } 195 196 /** 173 197 * Removes a test from the list of available tests. This will not remove 174 198 * core tests. 175 199 * -
src/org/openstreetmap/josm/data/validation/Test.java
39 39 * 40 40 * @author frsantos 41 41 */ 42 public class Test implements OsmPrimitiveVisitor {42 public abstract class Test implements OsmPrimitiveVisitor { 43 43 44 44 protected static final Predicate<OsmPrimitive> IN_DOWNLOADED_AREA = new NotOutsideDataSourceArea(); 45 45 protected static final Predicate<OsmPrimitive> IN_DOWNLOADED_AREA_STRICT = new InDataSourceArea(true); … … 383 383 public Object getSource() { 384 384 return "Java: " + this.getClass().getName(); 385 385 } 386 387 /** 388 * Get the error codes for this check. Used to ensure that this test does not conflict with other tests. 389 * See #21423. 390 * @return The error codes for this check. This array should never be modified. This is a candidate for frozen arrays. 391 * @since xxx (not yet mandatory) 392 */ 393 protected int[] errorCodes() { 394 return new int[0]; 395 } 386 396 } -
src/org/openstreetmap/josm/data/validation/tests/Addresses.java
54 54 protected static final int HOUSE_NUMBER_TOO_FAR = 2605; 55 55 protected static final int OBSOLETE_RELATION = 2606; 56 56 57 private static final int[] ERROR_CODES = { 58 HOUSE_NUMBER_WITHOUT_STREET, 59 DUPLICATE_HOUSE_NUMBER, 60 MULTIPLE_STREET_NAMES, 61 MULTIPLE_STREET_RELATIONS, 62 HOUSE_NUMBER_TOO_FAR, 63 OBSOLETE_RELATION 64 }; 65 57 66 protected static final DoubleProperty MAX_DUPLICATE_DISTANCE = new DoubleProperty("validator.addresses.max_duplicate_distance", 200.0); 58 67 protected static final DoubleProperty MAX_STREET_DISTANCE = new DoubleProperty("validator.addresses.max_street_distance", 200.0); 59 68 … … 522 531 return testError.getCode() == OBSOLETE_RELATION; 523 532 } 524 533 534 @Override 535 protected int[] errorCodes() { 536 return ERROR_CODES; 537 } 538 525 539 } -
src/org/openstreetmap/josm/data/validation/tests/ApiCapabilitiesTest.java
55 55 .build()); 56 56 } 57 57 } 58 59 @Override 60 protected int[] errorCodes() { 61 return new int[] {MAX_WAY_NODES_ERROR}; 62 } 58 63 } -
src/org/openstreetmap/josm/data/validation/tests/BarriersEntrances.java
39 39 .build()); 40 40 } 41 41 } 42 43 @Override 44 protected int[] errorCodes() { 45 return new int[] {BARRIER_ENTRANCE_WITHOUT_BARRIER}; 46 } 42 47 } -
src/org/openstreetmap/josm/data/validation/tests/Coastlines.java
38 38 protected static final int UNCONNECTED_COASTLINE = 903; 39 39 protected static final int WRONG_ORDER_COASTLINE = 904; 40 40 41 private static final int[] ERROR_CODES = {UNORDERED_COASTLINE, REVERSED_COASTLINE, UNCONNECTED_COASTLINE, WRONG_ORDER_COASTLINE}; 42 41 43 private List<Way> coastlineWays; 42 44 43 45 /** … … 277 279 278 280 return false; 279 281 } 282 283 @Override 284 protected int[] errorCodes() { 285 return ERROR_CODES; 286 } 280 287 } -
src/org/openstreetmap/josm/data/validation/tests/ConditionalKeys.java
24 24 */ 25 25 public class ConditionalKeys extends Test.TagTest { 26 26 27 private static final int ERROR_WRONG_SYNTAX = 3201; 28 private static final int ERROR_SYNTAX_ERROR = 3202; 29 private static final int[] ERROR_CODES = {ERROR_WRONG_SYNTAX, ERROR_SYNTAX_ERROR}; 30 27 31 private final OpeningHourTest openingHourTest = new OpeningHourTest(); 28 32 private static final Set<String> RESTRICTION_TYPES = new HashSet<>(Arrays.asList("oneway", "toll", "noexit", "maxspeed", "minspeed", 29 33 "maxstay", "maxweight", "maxaxleload", "maxheight", "maxwidth", "maxlength", "overtaking", "maxgcweight", "maxgcweightrating", … … 56 60 openingHourTest.initialize(); 57 61 } 58 62 63 @Override 64 protected int[] errorCodes() { 65 return ERROR_CODES; 66 } 67 59 68 /** 60 69 * Check if the key is a key for an access restriction 61 70 * @param part The key (or the restriction part of it, e.g. for lanes) … … 228 237 return; 229 238 } 230 239 if (!isKeyValid(key)) { 231 errors.add(TestError.builder(this, Severity.WARNING, 3201)240 errors.add(TestError.builder(this, Severity.WARNING, ERROR_WRONG_SYNTAX) 232 241 .message(tr("Wrong syntax in {0} key", key)) 233 242 .primitives(p) 234 243 .build()); … … 236 245 } 237 246 final String error = validateValue(key, value); 238 247 if (error != null) { 239 errors.add(TestError.builder(this, Severity.WARNING, 3202)248 errors.add(TestError.builder(this, Severity.WARNING, ERROR_SYNTAX_ERROR) 240 249 .message(tr("Error in {0} value: {1}", key, error)) 241 250 .primitives(p) 242 251 .build()); -
src/org/openstreetmap/josm/data/validation/tests/ConnectivityRelations.java
50 50 51 51 protected static final int CONNECTIVITY_IMPLIED = 3908; 52 52 53 private static final int[] ERROR_CODES = { 54 INCONSISTENT_LANE_COUNT, 55 UNKNOWN_CONNECTIVITY_ROLE, 56 NO_CONNECTIVITY_TAG, 57 MALFORMED_CONNECTIVITY_TAG, 58 MISSING_COMMA_CONNECTIVITY_TAG, 59 TOO_MANY_ROLES, 60 MISSING_ROLE, 61 MEMBER_MISSING_LANES, 62 CONNECTIVITY_IMPLIED 63 }; 64 53 65 private static final String CONNECTIVITY_TAG = "connectivity"; 54 66 private static final String VIA = "via"; 55 67 private static final String TO = "to"; … … 140 152 } 141 153 } 142 154 155 @Override 156 protected int[] errorCodes() { 157 return ERROR_CODES; 158 } 159 143 160 /** 144 161 * Compare lane tags of members to values in the {@code connectivity} tag of the relation 145 162 * -
src/org/openstreetmap/josm/data/validation/tests/CrossingWays.java
111 111 } 112 112 113 113 @Override 114 protected int[] errorCodes() { 115 return new int[] {CROSSING_WAYS}; 116 } 117 118 @Override 114 119 boolean ignoreWaySegmentCombination(Way w1, Way w2) { 115 120 if (w1 == w2) 116 121 return true; … … 261 266 visit(w); 262 267 } 263 268 } 269 270 @Override 271 protected int[] errorCodes() { 272 return new int[] {CROSSING_BOUNDARIES}; 273 } 264 274 } 265 275 266 276 /** … … 281 291 boolean ignoreWaySegmentCombination(Way w1, Way w2) { 282 292 return false; // we should not get here 283 293 } 294 295 @Override 296 protected int[] errorCodes() { 297 return new int[] {CROSSING_SELF}; 298 } 284 299 } 285 300 286 301 /** -
src/org/openstreetmap/josm/data/validation/tests/DirectionNodes.java
27 27 private static final int NO_WAY_CODE = 4002; 28 28 private static final int NO_SUITABLE_WAY = 4003; 29 29 30 private static final int[] ERROR_CODES = { 31 MULTIPLE_WAYS_CODE, 32 END_NODE_CODE, 33 NO_WAY_CODE, 34 NO_SUITABLE_WAY 35 }; 36 30 37 private static final String INVALID_USE_MSG = tr("Invalid usage of direction on node"); 31 38 private static final String DISPUTED_USE_MSG = tr("Disputed usage of direction on node"); 32 39 … … 49 56 } 50 57 } 51 58 59 @Override 60 protected int[] errorCodes() { 61 return ERROR_CODES; 62 } 63 52 64 private static boolean isSuitableParentWay(Way w) { 53 65 return w.hasKey("highway", "railway", "waterway") || w.hasTag("man_made", "pipeline"); 54 66 } -
src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java
101 101 protected static final int DUPLICATE_NODE_RAILWAY = 16; 102 102 protected static final int DUPLICATE_NODE_WATERWAY = 17; 103 103 104 private static final int[] ERROR_CODES = { 105 DUPLICATE_NODE, 106 DUPLICATE_NODE_MIXED, 107 DUPLICATE_NODE_OTHER, 108 DUPLICATE_NODE_BUILDING, 109 DUPLICATE_NODE_BOUNDARY, 110 DUPLICATE_NODE_HIGHWAY, 111 DUPLICATE_NODE_LANDUSE, 112 DUPLICATE_NODE_NATURAL, 113 DUPLICATE_NODE_POWER, 114 DUPLICATE_NODE_RAILWAY, 115 DUPLICATE_NODE_WATERWAY 116 }; 117 104 118 private static final String[] TYPES = { 105 119 "none", HIGHWAY, RAILWAY, WATERWAY, "boundary", "power", "natural", "landuse", "building"}; 106 120 … … 305 319 && Command.checkOutlyingOrIncompleteOperation(testError.getPrimitives(), null) == Command.IS_OK; 306 320 // everything else is ok to merge 307 321 } 322 323 @Override 324 protected int[] errorCodes() { 325 return ERROR_CODES; 326 } 308 327 } -
src/org/openstreetmap/josm/data/validation/tests/DuplicateRelation.java
175 175 /** Code number of relation with same members error */ 176 176 protected static final int SAME_RELATION = 1902; 177 177 178 private static final int[] ERROR_CODES = {DUPLICATE_RELATION, SAME_RELATION}; 179 178 180 /** MultiMap of all relations */ 179 181 private MultiMap<RelationPair, OsmPrimitive> relations; 180 182 … … 315 317 .limit(2) 316 318 .count() <= 1; 317 319 } 320 321 @Override 322 protected int[] errorCodes() { 323 return ERROR_CODES; 324 } 318 325 } -
src/org/openstreetmap/josm/data/validation/tests/DuplicateWay.java
95 95 /** Test identification for identical ways (coordinates only). */ 96 96 protected static final int SAME_WAY = 1402; 97 97 98 private static final int[] ERROR_CODES = {DUPLICATE_WAY, SAME_WAY}; 99 98 100 /** Bag of all ways */ 99 101 private MultiMap<WayPair, OsmPrimitive> ways; 100 102 … … 318 320 .count(); 319 321 return waysWithRelations <= 1; 320 322 } 323 324 @Override 325 protected int[] errorCodes() { 326 return ERROR_CODES; 327 } 321 328 } -
src/org/openstreetmap/josm/data/validation/tests/DuplicatedWayNodes.java
81 81 public boolean isFixable(TestError testError) { 82 82 return testError.getTester() instanceof DuplicatedWayNodes; 83 83 } 84 85 @Override 86 protected int[] errorCodes() { 87 return new int[] {DUPLICATE_WAY_NODE}; 88 } 84 89 } -
src/org/openstreetmap/josm/data/validation/tests/Highways.java
38 38 protected static final int SOURCE_MAXSPEED_CONTEXT_MISMATCH_VS_MAXSPEED = 2705; 39 39 protected static final int SOURCE_MAXSPEED_CONTEXT_MISMATCH_VS_HIGHWAY = 2706; 40 40 protected static final int SOURCE_WRONG_LINK = 2707; 41 private static final int[] ERROR_CODES = { 42 WRONG_ROUNDABOUT_HIGHWAY, 43 MISSING_PEDESTRIAN_CROSSING, 44 SOURCE_MAXSPEED_UNKNOWN_COUNTRY_CODE, 45 SOURCE_MAXSPEED_UNKNOWN_CONTEXT, 46 SOURCE_MAXSPEED_CONTEXT_MISMATCH_VS_MAXSPEED, 47 SOURCE_MAXSPEED_CONTEXT_MISMATCH_VS_HIGHWAY, 48 SOURCE_WRONG_LINK 49 }; 41 50 42 51 protected static final String SOURCE_MAXSPEED = "source:maxspeed"; 43 52 … … 109 118 } 110 119 } 111 120 121 @Override 122 protected int[] errorCodes() { 123 return ERROR_CODES; 124 } 125 112 126 private void testWrongRoundabout(Way w) { 113 127 Map<String, List<Way>> map = new HashMap<>(); 114 128 // Count all highways (per type) connected to this roundabout, except correct links -
src/org/openstreetmap/josm/data/validation/tests/InternetTags.java
28 28 public static final int INVALID_URL = 3301; 29 29 /** Error code for an invalid e-mail */ 30 30 public static final int INVALID_EMAIL = 3302; 31 private static final int[] ERROR_CODES = {INVALID_URL, INVALID_EMAIL}; 31 32 32 33 /** 33 34 * List of keys subject to URL validation. … … 129 130 } 130 131 }); 131 132 } 133 134 @Override 135 protected int[] errorCodes() { 136 return ERROR_CODES; 137 } 132 138 } -
src/org/openstreetmap/josm/data/validation/tests/Lanes.java
20 20 * @since 6592 21 21 */ 22 22 public class Lanes extends Test.TagTest { 23 private static final int ERROR_LANE_COUNT_MISMATCH = 3100; 24 private static final int ERROR_LANE_COUNT_MISMATCH_FORWARD_BACKWARD = 3101; 25 private static final int[] ERROR_CODES = {ERROR_LANE_COUNT_MISMATCH, ERROR_LANE_COUNT_MISMATCH_FORWARD_BACKWARD}; 23 26 24 27 private static final String[] BLACKLIST = { 25 28 "source:lanes", … … 50 53 51 54 if (lanesCount.size() > 1) { 52 55 // if not all numbers are the same 53 errors.add(TestError.builder(this, Severity.WARNING, 3100)56 errors.add(TestError.builder(this, Severity.WARNING, ERROR_LANE_COUNT_MISMATCH) 54 57 .message(message) 55 58 .primitives(p) 56 59 .build()); … … 58 61 // ensure that lanes <= *:lanes 59 62 try { 60 63 if (Integer.parseInt(p.get(lanesKey)) > lanesCount.iterator().next()) { 61 errors.add(TestError.builder(this, Severity.WARNING, 3100)64 errors.add(TestError.builder(this, Severity.WARNING, ERROR_LANE_COUNT_MISMATCH) 62 65 .message(tr("Number of {0} greater than {1}", lanesKey, "*:" + lanesKey)) 63 66 .primitives(p) 64 67 .build()); … … 76 79 final String backward = Utils.firstNonNull(p.get("lanes:backward"), "0"); 77 80 try { 78 81 if (Integer.parseInt(lanes) < Integer.parseInt(forward) + Integer.parseInt(backward)) { 79 errors.add(TestError.builder(this, Severity.WARNING, 3101)82 errors.add(TestError.builder(this, Severity.WARNING, ERROR_LANE_COUNT_MISMATCH_FORWARD_BACKWARD) 80 83 .message(tr("Number of {0} greater than {1}", tr("{0}+{1}", "lanes:forward", "lanes:backward"), "lanes")) 81 84 .primitives(p) 82 85 .build()); … … 98 101 public boolean isPrimitiveUsable(OsmPrimitive p) { 99 102 return p.isTagged() && p instanceof Way && p.hasTag("highway") && super.isPrimitiveUsable(p); 100 103 } 104 105 @Override 106 protected int[] errorCodes() { 107 return ERROR_CODES; 108 } 101 109 } -
src/org/openstreetmap/josm/data/validation/tests/LongSegment.java
78 78 testWay(w); 79 79 } 80 80 81 @Override 82 protected int[] errorCodes() { 83 return new int[] {LONG_SEGMENT}; 84 } 85 81 86 private void testWay(Way w) { 82 87 for (int i = 0; i < w.getNodesCount() - 1; i++) { 83 88 visitWaySegment(w, i); -
src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
64 64 static final boolean ALL_TESTS = true; 65 65 static final boolean ONLY_SELECTED_TESTS = false; 66 66 67 static final int ERROR_MAPCSS = 3000; 68 67 69 /** 68 70 * Cached version of {@link ValidatorPrefHelper#PREF_OTHER}, see #20745. 69 71 */ … … 384 386 visit(selection, null); 385 387 } 386 388 389 @Override 390 protected int[] errorCodes() { 391 return new int[] {ERROR_MAPCSS}; 392 } 393 387 394 /** 388 395 * Execute the rules from the URLs matching the given predicate. 389 396 * @param selection collection of primitives -
src/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerRule.java
388 388 final String description1 = group == null ? description : group; 389 389 final String description2 = group == null ? null : description; 390 390 final String selector = matchingSelector.toString(); 391 TestError.Builder errorBuilder = TestError.builder(tester, getSeverity(), 3000)391 TestError.Builder errorBuilder = TestError.builder(tester, getSeverity(), MapCSSTagChecker.ERROR_MAPCSS) 392 392 .messageWithManuallyTranslatedDescription(description1, description2, selector); 393 393 if (fix != null) { 394 394 errorBuilder.fix(() -> fix); … … 398 398 } else if (env.children != null) { 399 399 for (IPrimitive c : env.children) { 400 400 if (c instanceof OsmPrimitive) { 401 errorBuilder = TestError.builder(tester, getSeverity(), 3000)401 errorBuilder = TestError.builder(tester, getSeverity(), MapCSSTagChecker.ERROR_MAPCSS) 402 402 .messageWithManuallyTranslatedDescription(description1, description2, selector); 403 403 if (fix != null) { 404 404 errorBuilder.fix(() -> fix); -
src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
77 77 /** Incomplete multipolygon was modified */ 78 78 public static final int MODIFIED_INCOMPLETE = 1618; 79 79 80 private static final int[] ERROR_CODES = { 81 WRONG_MEMBER_TYPE, 82 WRONG_MEMBER_ROLE, 83 NON_CLOSED_WAY, 84 INNER_WAY_OUTSIDE, 85 CROSSING_WAYS, 86 OUTER_STYLE_MISMATCH, 87 INNER_STYLE_MISMATCH, 88 NO_STYLE, 89 OUTER_STYLE, 90 REPEATED_MEMBER_SAME_ROLE, 91 REPEATED_MEMBER_DIFF_ROLE, 92 EQUAL_RINGS, 93 RINGS_SHARE_NODES, 94 MODIFIED_INCOMPLETE 95 }; 96 80 97 private static final int FOUND_INSIDE = 1; 81 98 private static final int FOUND_OUTSIDE = 2; 82 99 … … 769 786 return testError.getCode() == REPEATED_MEMBER_SAME_ROLE; 770 787 } 771 788 789 @Override 790 protected int[] errorCodes() { 791 return ERROR_CODES; 792 } 793 772 794 /** 773 795 * Find nesting levels of polygons. Logic taken from class MultipolygonBuilder, uses different structures. 774 796 */ -
src/org/openstreetmap/josm/data/validation/tests/NameMismatch.java
35 35 public class NameMismatch extends Test.TagTest { 36 36 protected static final int NAME_MISSING = 1501; 37 37 protected static final int NAME_TRANSLATION_MISSING = 1502; 38 private static final int[] ERROR_CODES = {NAME_MISSING, NAME_TRANSLATION_MISSING}; 38 39 private static final Pattern NAME_SPLIT_PATTERN = Pattern.compile(" - "); 39 40 40 41 private static final List<String> EXCLUSIONS = Arrays.asList( … … 121 122 return p.isTagged() && super.isPrimitiveUsable(p); 122 123 } 123 124 125 @Override 126 protected int[] errorCodes() { 127 return ERROR_CODES; 128 } 129 124 130 } -
src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java
39 39 */ 40 40 public class OpeningHourTest extends TagTest { 41 41 42 private static final int ERROR_OPENING_HOURS_SYNTAX = 2901; 42 43 private static final Collection<String> KEYS_TO_CHECK = Arrays.asList("opening_hours", "collection_times", "service_times"); 43 44 private static final BooleanProperty PREF_STRICT_MODE = 44 45 new BooleanProperty(ValidatorPrefHelper.PREFIX + "." + OpeningHourTest.class.getSimpleName() + "." + "strict", false); … … 63 64 * @return The real test error given to JOSM validator. Can be fixable or not if a prettified values has been determined. 64 65 */ 65 66 private TestError createTestError(Severity severity, String message, String key, String value, String prettifiedValue, OsmPrimitive p) { 66 final TestError.Builder error = TestError.builder(this, severity, 2901)67 final TestError.Builder error = TestError.builder(this, severity, ERROR_OPENING_HOURS_SYNTAX) 67 68 .message(tr("Opening hours syntax"), message) // todo obtain English message for ignore functionality 68 69 .primitives(p != null ? new OsmPrimitive[] {p} : new OsmPrimitive[] {}); 69 70 if (p == null || prettifiedValue == null || prettifiedValue.equals(value)) { … … 161 162 PREF_STRICT_MODE.put(checkboxStrictMode.isSelected()); 162 163 return false; 163 164 } 165 166 @Override 167 protected int[] errorCodes() { 168 return new int[] {ERROR_OPENING_HOURS_SYNTAX}; 169 } 164 170 } -
src/org/openstreetmap/josm/data/validation/tests/OverlappingWays.java
63 63 protected static final int OVERLAPPING_HIGHWAY_LINEAR_WAY = 131; 64 64 protected static final int OVERLAPPING_RAILWAY_LINEAR_WAY = 132; 65 65 protected static final int OVERLAPPING_WATERWAY_LINEAR_WAY = 133; 66 private static final int[] ERROR_CODES = { 67 OVERLAPPING_HIGHWAY, 68 OVERLAPPING_RAILWAY, 69 OVERLAPPING_WAY, 70 OVERLAPPING_WATERWAY, 71 OVERLAPPING_HIGHWAY_AREA, 72 OVERLAPPING_RAILWAY_AREA, 73 OVERLAPPING_WAY_AREA, 74 OVERLAPPING_WATERWAY_AREA, 75 DUPLICATE_WAY_SEGMENT, 76 OVERLAPPING_HIGHWAY_LINEAR_WAY, 77 OVERLAPPING_RAILWAY_LINEAR_WAY, 78 OVERLAPPING_WATERWAY_LINEAR_WAY 79 }; 66 80 67 81 protected static final ListProperty IGNORED_KEYS = new ListProperty( 68 82 "overlapping-ways.ignored-keys", Arrays.asList( … … 285 299 lastN = n; 286 300 } 287 301 } 302 303 @Override 304 protected int[] errorCodes() { 305 return ERROR_CODES; 306 } 288 307 } -
src/org/openstreetmap/josm/data/validation/tests/PowerLines.java
33 33 /** Test identifier */ 34 34 protected static final int POWER_LINES = 2501; 35 35 protected static final int POWER_CONNECTION = 2502; 36 private static final int[] ERROR_CODES = {POWER_LINES, POWER_CONNECTION}; 36 37 37 38 /** Values for {@code power} key interpreted as power lines */ 38 39 static final Collection<String> POWER_LINE_TAGS = Arrays.asList("line", "minor_line"); … … 111 112 } 112 113 113 114 @Override 115 protected int[] errorCodes() { 116 return ERROR_CODES; 117 } 118 119 @Override 114 120 public void startTest(ProgressMonitor progressMonitor) { 115 121 super.startTest(progressMonitor); 116 122 clearCollections(); -
src/org/openstreetmap/josm/data/validation/tests/PublicTransportRouteTest.java
22 22 * Tests for <a href="https://wiki.openstreetmap.org/wiki/Proposed_features/Public_Transport">public transport routes</a>. 23 23 */ 24 24 public class PublicTransportRouteTest extends Test { 25 private static final int ERROR_BAD_ROLE = 3601; 26 private static final int ERROR_GAP = 3602; 27 private static final int ERROR_STOP_NOT_IN_ROUTE = 3603; 28 private static final int[] ERROR_CODES = {ERROR_BAD_ROLE, ERROR_GAP, ERROR_STOP_NOT_IN_ROUTE}; 25 29 26 30 private final WayConnectionTypeCalculator connectionTypeCalculator = new WayConnectionTypeCalculator(); 27 31 … … 46 50 final Set<Node> routeNodes = new HashSet<>(); 47 51 for (RelationMember member : r.getMembers()) { 48 52 if (member.hasRole("forward", "backward", "alternate")) { 49 errors.add(TestError.builder(this, Severity.ERROR, 3601)53 errors.add(TestError.builder(this, Severity.ERROR, ERROR_BAD_ROLE) 50 54 .message(tr("Route relation contains a ''{0}'' role", "forward/backward/alternate")) 51 55 .primitives(r) 52 56 .build()); … … 68 72 || link.direction == null 69 73 || WayConnectionType.Direction.NONE == link.direction; 70 74 if (hasError) { 71 errors.add(TestError.builder(this, Severity.WARNING, 3602)75 errors.add(TestError.builder(this, Severity.WARNING, ERROR_GAP) 72 76 .message(tr("Route relation contains a gap")) 73 77 .primitives(r) 74 78 .build()); … … 80 84 if (member.hasRole("stop", "stop_exit_only", "stop_entry_only") 81 85 && OsmPrimitiveType.NODE == member.getType() 82 86 && !routeNodes.contains(member.getNode())) { 83 errors.add(TestError.builder(this, Severity.WARNING, 3603)87 errors.add(TestError.builder(this, Severity.WARNING, ERROR_STOP_NOT_IN_ROUTE) 84 88 .message(tr("Stop position not part of route")) 85 89 .primitives(member.getMember(), r) 86 90 .build()); … … 93 97 connectionTypeCalculator.clear(); 94 98 super.clear(); 95 99 } 100 101 @Override 102 protected int[] errorCodes() { 103 return ERROR_CODES; 104 } 96 105 } -
src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java
68 68 public static final int RELATION_LOOP = 1710; 69 69 /** Relation is empty */ 70 70 public static final int RELATION_EMPTY = 1711; // was 1708 up to r18505 71 private static final int[] ERROR_CODES = { 72 ROLE_UNKNOWN, 73 ROLE_EMPTY, 74 HIGH_COUNT, 75 LOW_COUNT, 76 ROLE_MISSING, 77 RELATION_UNKNOWN, 78 WRONG_ROLE, 79 WRONG_TYPE, 80 RELATION_LOOP, 81 RELATION_EMPTY 82 }; 71 83 // CHECKSTYLE.ON: SingleSpaceSeparator 72 84 73 85 // see 19312 comment:17 … … 401 413 } 402 414 403 415 @Override 416 protected int[] errorCodes() { 417 return ERROR_CODES; 418 } 419 420 @Override 404 421 public void taggingPresetsModified() { 405 422 relationpresets.clear(); 406 423 initializePresets(); -
src/org/openstreetmap/josm/data/validation/tests/RightAngleBuildingTest.java
21 21 * @since 13670 22 22 */ 23 23 public class RightAngleBuildingTest extends Test { 24 private static final int ERROR_ALMOST_SQUARE_ANGLE = 3701; 24 25 25 26 /** Maximum angle difference from right angle that is considered as invalid. */ 26 27 protected double maxAngleDelta; … … 43 44 List<Pair<Double, Node>> angles = w.getAngles(); 44 45 for (Pair<Double, Node> pair: angles) { 45 46 if (checkAngle(pair.a)) { 46 TestError.Builder builder = TestError.builder(this, Severity.OTHER, 3701)47 TestError.Builder builder = TestError.builder(this, Severity.OTHER, ERROR_ALMOST_SQUARE_ANGLE) 47 48 .message(tr("Building with an almost square angle")) 48 49 .primitives(w) 49 50 .highlight(pair.b); … … 54 55 } 55 56 56 57 @Override 58 protected int[] errorCodes() { 59 return new int[]{ERROR_ALMOST_SQUARE_ANGLE}; 60 } 61 62 @Override 57 63 public void startTest(ProgressMonitor monitor) { 58 64 super.startTest(monitor); 59 65 maxAngleDelta = Config.getPref().getDouble("validator.RightAngleBuilding.maximumDelta", 10.0); -
src/org/openstreetmap/josm/data/validation/tests/SelfIntersectingWay.java
63 63 } 64 64 } 65 65 66 @Override 67 protected int[] errorCodes() { 68 return new int[]{SELF_INTERSECT}; 69 } 70 66 71 /** 67 72 * Check if the given way is self-intersecting 68 73 * @param way the way to check -
src/org/openstreetmap/josm/data/validation/tests/SharpAngles.java
55 55 } 56 56 } 57 57 58 @Override 59 protected int[] errorCodes() { 60 return new int[]{SHARP_ANGLES}; 61 } 62 58 63 /** 59 64 * Check whether or not a way should be checked for sharp angles 60 65 * @param way The way that needs to be checked -
src/org/openstreetmap/josm/data/validation/tests/SimilarNamedWays.java
109 109 } 110 110 } 111 111 112 @Override 113 protected int[] errorCodes() { 114 return new int[]{SIMILAR_NAMED}; 115 } 116 112 117 /** 113 118 * Add a regular expression rule. 114 119 * @param regExpr the regular expression to search for -
src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
211 211 protected static final int MULTIPOLYGON_MAYBE_NO_AREA = 1220; 212 212 protected static final int MULTIPOLYGON_SAME_TAG_ON_OUTER = 1221; 213 213 // CHECKSTYLE.ON: SingleSpaceSeparator 214 private static final int[] ERROR_CODES = { 215 EMPTY_VALUES, 216 INVALID_KEY, 217 INVALID_VALUE, 218 FIXME, 219 INVALID_SPACE, 220 INVALID_KEY_SPACE, 221 INVALID_HTML, 222 LONG_VALUE, 223 LONG_KEY, 224 LOW_CHAR_VALUE, 225 LOW_CHAR_KEY, 226 MISSPELLED_VALUE, 227 MISSPELLED_KEY, 228 MULTIPLE_SPACES, 229 MISSPELLED_VALUE_NO_FIX, 230 UNUSUAL_UNICODE_CHAR_VALUE, 231 INVALID_PRESETS_TYPE, 232 MULTIPOLYGON_NO_AREA, 233 MULTIPOLYGON_INCOMPLETE, 234 MULTIPOLYGON_MAYBE_NO_AREA, 235 MULTIPOLYGON_SAME_TAG_ON_OUTER 236 }; 214 237 215 238 protected EditableList sourcesList; 216 239 … … 1256 1279 } 1257 1280 1258 1281 @Override 1282 protected int[] errorCodes() { 1283 return ERROR_CODES; 1284 } 1285 1286 @Override 1259 1287 public void taggingPresetsModified() { 1260 1288 try { 1261 1289 initializeData(); -
src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java
44 44 protected static final int UNKNOWN_RESTRICTION = 1817; 45 45 protected static final int TO_CLOSED_WAY = 1818; 46 46 protected static final int FROM_CLOSED_WAY = 1819; 47 private static final int[] ERROR_CODES = { 48 NO_VIA, 49 NO_FROM, 50 NO_TO, 51 MORE_VIA, 52 MORE_FROM, 53 MORE_TO, 54 UNEXPECTED_ROLE, 55 UNEXPECTED_TYPE, 56 FROM_VIA_NODE, 57 TO_VIA_NODE, 58 FROM_VIA_WAY, 59 TO_VIA_WAY, 60 MIX_VIA, 61 UNCONNECTED_VIA, 62 SUPERFLUOUS, 63 FROM_EQUALS_TO, 64 UNKNOWN_RESTRICTION, 65 TO_CLOSED_WAY, 66 FROM_CLOSED_WAY 67 }; 47 68 48 69 private static final List<String> SUPPORTED_RESTRICTIONS = Arrays.asList( 49 70 "no_right_turn", "no_left_turn", "no_u_turn", "no_straight_on", … … 303 324 } 304 325 } 305 326 327 @Override 328 protected int[] errorCodes() { 329 return ERROR_CODES; 330 } 331 306 332 private static boolean isFullOneway(Way w) { 307 333 return w.isOneway() != 0 && !w.hasTag("oneway:bicycle", "no"); 308 334 } -
src/org/openstreetmap/josm/data/validation/tests/UnclosedWays.java
140 140 } 141 141 } 142 142 143 private static final int CODE_NATURAL = 1101; 144 private static final int CODE_LANDUSE = 1102; 145 private static final int CODE_AMENITY = 1103; 146 private static final int CODE_SPORT = 1104; 147 private static final int CODE_TOURISM = 1105; 148 private static final int CODE_SHOP = 1106; 149 private static final int CODE_LEISURE = 1107; 150 private static final int CODE_WATERWAY = 1108; 151 private static final int CODE_BOUNDARY = 1109; 152 private static final int CODE_AREA_HIGHWAY = 1110; 153 private static final int CODE_PLACE = 1111; 154 private static final int CODE_BUILDING = 1120; 155 private static final int CODE_AREA = 1130; 156 private static final int CODE_AREA_OTHER = 1131; 157 private static final int[] ERROR_CODES = { 158 CODE_NATURAL, 159 CODE_LANDUSE, 160 CODE_AMENITY, 161 CODE_SPORT, 162 CODE_TOURISM, 163 CODE_SHOP, 164 CODE_LEISURE, 165 CODE_WATERWAY, 166 CODE_BOUNDARY, 167 CODE_AREA_HIGHWAY, 168 CODE_PLACE, 169 CODE_BUILDING, 170 CODE_AREA, 171 CODE_AREA_OTHER 172 }; 173 143 174 private static final UnclosedWaysCheck[] checks = { 144 175 // CHECKSTYLE.OFF: SingleSpaceSeparator 145 176 // list contains natural tag allowed on unclosed ways as well as those only allowed on nodes to avoid 146 177 // duplicate warnings 147 new UnclosedWaysCheck( 1101, "natural", marktr("natural type {0}"),178 new UnclosedWaysCheck(CODE_NATURAL, "natural", marktr("natural type {0}"), 148 179 new HashSet<>(Arrays.asList("arete", "bay", "cave", "cliff", "coastline", "earth_bank", "gorge", "gully", 149 180 "mountain_range", "peak", "ridge", "saddle", "strait", "tree", "tree_row", "valley", "volcano"))), 150 181 151 new UnclosedWaysCheck( 1102, "landuse", marktr("landuse type {0}")),152 new UnclosedWaysCheck( 1103, "amenity", marktr("amenity type {0}"),182 new UnclosedWaysCheck(CODE_LANDUSE, "landuse", marktr("landuse type {0}")), 183 new UnclosedWaysCheck(CODE_AMENITY, "amenity", marktr("amenity type {0}"), 153 184 new HashSet<>(Arrays.asList("bench", "bicycle_parking", "weighbridge"))), 154 new UnclosedWaysCheck( 1104, "sport", marktr("sport type {0}"),185 new UnclosedWaysCheck(CODE_SPORT, "sport", marktr("sport type {0}"), 155 186 new HashSet<>(Arrays.asList("water_slide", "climbing", "skiing", "toboggan", "bobsleigh", "karting", "motor", "motocross", 156 187 "cycling", "running"))), 157 new UnclosedWaysCheck( 1105, "tourism", marktr("tourism type {0}"),188 new UnclosedWaysCheck(CODE_TOURISM, "tourism", marktr("tourism type {0}"), 158 189 new HashSet<>(Arrays.asList("attraction", "artwork"))), 159 new UnclosedWaysCheck( 1106, "shop", marktr("shop type {0}")),160 new UnclosedWaysCheck( 1107, "leisure", marktr("leisure type {0}"),190 new UnclosedWaysCheck(CODE_SHOP, "shop", marktr("shop type {0}")), 191 new UnclosedWaysCheck(CODE_LEISURE, "leisure", marktr("leisure type {0}"), 161 192 new HashSet<>(Arrays.asList("track", "slipway", "barefoot"))), 162 new UnclosedWaysCheck( 1108, "waterway", marktr("waterway type {0}"),163 new HashSet<>( Arrays.asList("riverbank")), false),164 new UnclosedWaysCheck( 1109, "boundary", marktr("boundary type {0}")),165 new UnclosedWaysCheck( 1110, "area:highway", marktr("area:highway type {0}")),166 new UnclosedWaysCheck( 1111, "place", marktr("place type {0}")),167 new UnclosedWaysBooleanCheck( 1120, "building", marktr("building")),168 new UnclosedWaysBooleanCheck( 1130, "area", marktr("area")),193 new UnclosedWaysCheck(CODE_WATERWAY, "waterway", marktr("waterway type {0}"), 194 new HashSet<>(Collections.singleton("riverbank")), false), 195 new UnclosedWaysCheck(CODE_BOUNDARY, "boundary", marktr("boundary type {0}")), 196 new UnclosedWaysCheck(CODE_AREA_HIGHWAY, "area:highway", marktr("area:highway type {0}")), 197 new UnclosedWaysCheck(CODE_PLACE, "place", marktr("place type {0}")), 198 new UnclosedWaysBooleanCheck(CODE_BUILDING, "building", marktr("building")), 199 new UnclosedWaysBooleanCheck(CODE_AREA, "area", marktr("area")), 169 200 // 1131: Area style way is not closed 170 201 // CHECKSTYLE.ON: SingleSpaceSeparator 171 202 }; … … 196 227 } 197 228 // code 1131: other area style ways 198 229 if (ElemStyles.hasOnlyAreaElements(w) && !w.getNodes().isEmpty()) { 199 errors.add(TestError.builder(this, Severity.WARNING, 1131)230 errors.add(TestError.builder(this, Severity.WARNING, CODE_AREA_OTHER) 200 231 .message(tr("Unclosed way"), marktr("Area style way is not closed"), new Object()) 201 232 .primitives(w) 202 233 .highlight(Arrays.asList(w.firstNode(), w.lastNode())) … … 203 234 .build()); 204 235 } 205 236 } 237 238 @Override 239 protected int[] errorCodes() { 240 return ERROR_CODES; 241 } 206 242 } -
src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
635 635 } 636 636 } 637 637 638 @Override 639 protected int[] errorCodes() { 640 return new int[] {this.code}; 641 } 642 638 643 private void addNode(Node n, Set<Node> s) { 639 644 boolean m = middlenodes.contains(n); 640 645 boolean e = endnodes.contains(n); -
src/org/openstreetmap/josm/data/validation/tests/UntaggedNode.java
29 29 protected static final int UNTAGGED_NODE_WATCH = 205; 30 30 protected static final int UNTAGGED_NODE_SOURCE = 206; 31 31 protected static final int UNTAGGED_NODE_OTHER = 207; 32 private static final int[] ERROR_CODES = { 33 UNTAGGED_NODE_BLANK, 34 UNTAGGED_NODE_FIXME, 35 UNTAGGED_NODE_NOTE, 36 UNTAGGED_NODE_CREATED_BY, 37 UNTAGGED_NODE_WATCH, 38 UNTAGGED_NODE_SOURCE, 39 UNTAGGED_NODE_OTHER 40 }; 32 41 protected static final String ERROR_MESSAGE = tr("Unconnected nodes without physical tags"); 33 42 34 43 /** … … 121 130 } 122 131 return false; 123 132 } 133 134 @Override 135 protected int[] errorCodes() { 136 return ERROR_CODES; 137 } 124 138 } -
src/org/openstreetmap/josm/data/validation/tests/UntaggedWay.java
41 41 protected static final int UNNAMED_JUNCTION = 305; 42 42 /** Untagged, but commented way error */ 43 43 protected static final int COMMENTED_WAY = 306; 44 45 private static final int[] ERROR_CODES = { 46 EMPTY_WAY, 47 UNTAGGED_WAY, 48 UNNAMED_WAY, 49 ONE_NODE_WAY, 50 UNNAMED_JUNCTION, 51 COMMENTED_WAY 52 }; 44 53 // CHECKSTYLE.ON: SingleSpaceSeparator 45 54 46 55 private Set<Way> waysUsedInRelations; … … 177 186 } 178 187 179 188 @Override 189 protected int[] errorCodes() { 190 return ERROR_CODES; 191 } 192 193 @Override 180 194 public Command fixError(TestError testError) { 181 195 return deletePrimitivesIfNeeded(testError.getPrimitives()); 182 196 } -
src/org/openstreetmap/josm/data/validation/tests/WayConnectedToArea.java
20 20 * @since 4682 21 21 */ 22 22 public class WayConnectedToArea extends Test { 23 private static final int ERROR_WAY_TERMINATES_ON_AREA = 2301; 23 24 24 25 /** 25 26 * Constructs a new {@code WayConnectedToArea} test. … … 50 51 } 51 52 } 52 53 54 @Override 55 protected int[] errorCodes() { 56 return new int[] {ERROR_WAY_TERMINATES_ON_AREA}; 57 } 58 53 59 private void testForError(Way w, Node wayNode, OsmPrimitive p) { 54 60 if (wayNode.isOutsideDownloadArea() 55 61 || wayNode.getReferrers().stream().anyMatch(p1 -> p1.hasTag("route", "ferry"))) { … … 77 83 // Avoid "legal" case (see #17036) 78 84 return; 79 85 } 80 errors.add(TestError.builder(this, Severity.WARNING, 2301)86 errors.add(TestError.builder(this, Severity.WARNING, ERROR_WAY_TERMINATES_ON_AREA) 81 87 .message(tr("Way terminates on Area")) 82 88 .primitives(w, p) 83 89 .highlight(wayNode) -
src/org/openstreetmap/josm/data/validation/tests/WronglyOrderedWays.java
20 20 protected static final int WRONGLY_ORDERED_COAST = 1001; 21 21 protected static final int WRONGLY_ORDERED_LAND = 1003; 22 22 // CHECKSTYLE.ON: SingleSpaceSeparator 23 private static final int[] ERROR_CODES = {WRONGLY_ORDERED_COAST, WRONGLY_ORDERED_LAND}; 23 24 24 25 /** 25 26 * Constructor … … 45 46 } 46 47 } 47 48 49 @Override 50 protected int[] errorCodes() { 51 return ERROR_CODES; 52 } 53 48 54 private void reportError(Way w, String msg, int type) { 49 55 errors.add(TestError.builder(this, Severity.WARNING, type) 50 56 .message(msg)
