- Timestamp:
- 2013-12-10T20:40:41+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/DeprecatedTags.java
r6459 r6465 5 5 6 6 import java.util.Collection; 7 import java.util.LinkedHashMap; 7 8 import java.util.LinkedList; 8 9 import java.util.List; 10 import java.util.Map; 9 11 10 12 import org.openstreetmap.josm.command.ChangePropertyCommand; … … 137 139 checks.add(new DeprecationCheck(2129). 138 140 test("monitoring:river_level"). 139 alternative("monitoring:water_level"));141 changeKey("monitoring:river_level", "monitoring:water_level")); 140 142 // see #9365 - Useless tag layer=0 141 143 checks.add(new UnnecessaryTagCheck(2130). … … 170 172 } 171 173 174 /** 175 * Represents on deprecation check consisting of a series of {@code test}s, 176 * automatic {@code change}s/{@code keyChange}s (fixes for the deprecated tag), 177 * or a suggestion of tagging {@code alternatives}. 178 */ 172 179 private static class DeprecationCheck { 173 180 … … 175 182 protected final List<Tag> test = new LinkedList<Tag>(); 176 183 protected final List<Tag> change = new LinkedList<Tag>(); 184 protected final Map<String, String> keyChange = new LinkedHashMap<String, String>(); 177 185 protected final List<Tag> alternatives = new LinkedList<Tag>(); 178 186 187 /** 188 * Creates a new {@code DeprecationCheck}. 189 * @param code {@link TestError#code} 190 */ 179 191 public DeprecationCheck(int code) { 180 192 this.code = code; 181 193 } 182 194 195 /** 196 * Adds a test criterion which matches primitives with tag {@code key=value}. 197 * @return {@code this} 198 */ 183 199 DeprecationCheck test(String key, String value) { 184 200 test.add(new Tag(key, value)); … … 186 202 } 187 203 204 /** 205 * Adds a test criterion which matches primitives with key {@code key}. 206 * @return {@code this} 207 */ 188 208 DeprecationCheck test(String key) { 189 209 return test(key, null); 190 210 } 191 211 212 /** 213 * Adds an automatic fix which sets/adds the tag {@code key=value}. 214 * @return {@code this} 215 * @see #alternative(String, String) 216 * @see #alternative(String) 217 */ 192 218 DeprecationCheck add(String key, String value) { 193 219 change.add(new Tag(key, value)); … … 195 221 } 196 222 223 /** 224 * Adds an automatic fix which removes the key {@code key}. 225 * @return {@code this} 226 */ 197 227 DeprecationCheck remove(String key) { 198 228 change.add(new Tag(key)); … … 200 230 } 201 231 232 /** 233 * Adds an automatic fix which changes the key {@code oldKey} to {@code newKey}. 234 * @return {@code this} 235 */ 236 DeprecationCheck changeKey(String oldKey, String newKey) { 237 keyChange.put(oldKey, newKey); 238 return this; 239 } 240 241 /** 242 * Adds a test criterion which matches primitives with tag {@code key=value}, 243 * and an automatic fix which removes the key {@code key}. 244 * Equivalent to {@link #test(String, String)} plus {@link #remove(String)}. 245 * @return {@code this} 246 */ 202 247 DeprecationCheck testAndRemove(String key, String value) { 203 248 return test(key, value).remove(key); 204 249 } 205 250 251 /** 252 * Adds a suggestion to use an alternative tag {@code key=value} instead of the deprecated tag. 253 * This is used for cases where no automatic fix is sensible. 254 * @return {@code this} 255 */ 206 256 DeprecationCheck alternative(String key, String value) { 207 257 alternatives.add(new Tag(key, value)); … … 209 259 } 210 260 261 /** 262 * Adds a suggestion to use an alternative key {@code key} instead of the deprecated tag. 263 * This is used for cases where no automatic fix is sensible. 264 * @return {@code this} 265 */ 211 266 DeprecationCheck alternative(String key) { 212 267 return alternative(key, null); 213 268 } 214 269 270 /** 271 * Tests whether the {@link OsmPrimitive} contains a deprecated tag which is represented by this {@code DeprecationCheck}. 272 * @param p the primitive to test 273 * @return true when the primitive contains a deprecated tag 274 */ 215 275 boolean matchesPrimitive(OsmPrimitive p) { 216 276 for (Tag tag : test) { … … 225 285 } 226 286 287 /** 288 * Constructs a fix in terms of a {@link Command} for the {@link OsmPrimitive}. 289 * @param p the primitive to construct the fix for 290 * @return the fix 291 */ 227 292 Command fixPrimitive(OsmPrimitive p) { 228 293 Collection<Command> cmds = new LinkedList<Command>(); … … 230 295 cmds.add(new ChangePropertyCommand(p, tag.getKey(), tag.getValue())); 231 296 } 232 if (test.size() == 1 && alternatives.size() == 1) {233 cmds.add(new ChangePropertyKeyCommand(p, test.get(0).getKey(), alternatives.get(0).getKey()));297 for (Map.Entry<String, String> i : keyChange.entrySet()) { 298 cmds.add(new ChangePropertyKeyCommand(p, i.getKey(), i.getValue())); 234 299 } 235 300 return new SequenceCommand(tr("Deprecation fix of {0}", Utils.join(", ", test)), cmds); 236 301 } 237 302 303 /** 304 * Constructs a localized description for this deprecation check. 305 * @return a localized description 306 */ 238 307 String getDescription() { 239 308 if (alternatives.isEmpty()) … … 269 338 @Override 270 339 public boolean isFixable() { 271 return !check.change.isEmpty() || (check.test.size() == 1 && check.alternatives.size() == 1);340 return !check.change.isEmpty() || !check.keyChange.isEmpty(); 272 341 } 273 342
Note:
See TracChangeset
for help on using the changeset viewer.