Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r8898 r8899 106 106 107 107 public class CoreSimpleMatchFactory implements SimpleMatchFactory { 108 private Collection<String> keywords = Arrays.asList("id", "version", 108 private Collection<String> keywords = Arrays.asList("id", "version", "type", "user", "role", 109 109 "changeset", "nodes", "ways", "tags", "areasize", "waylength", "modified", "selected", 110 110 "incomplete", "untagged", "closed", "new", "indownloadedarea", … … 141 141 case "version": 142 142 return new Version(tokenizer); 143 case "type": 144 return new ExactType(tokenizer.readTextOrNumber()); 145 case "user": 146 return new UserMatch(tokenizer.readTextOrNumber()); 147 case "role": 148 return new RoleMatch(tokenizer.readTextOrNumber()); 143 149 case "changeset": 144 150 return new ChangesetId(tokenizer); … … 1583 1589 1584 1590 // key:value form where value is a string (may be OSM key search) 1585 return parseKV(key, tokenizer.readTextOrNumber()); 1591 final String value = tokenizer.readTextOrNumber(); 1592 return new KeyValue(key, value != null ? value : "", regexSearch, caseSensitive); 1586 1593 } else if (tokenizer.readIfEqual(Token.QUESTION_MARK)) 1587 1594 return new BooleanMatch(key, false); … … 1610 1617 } 1611 1618 1612 private Match parseKV(String key, String value) throws ParseError {1613 if (value == null) {1614 value = "";1615 }1616 switch(key) {1617 case "type":1618 return new ExactType(value);1619 case "user":1620 return new UserMatch(value);1621 case "role":1622 return new RoleMatch(value);1623 default:1624 return new KeyValue(key, value, regexSearch, caseSensitive);1625 }1626 }1627 1628 1619 private static int regexFlags(boolean caseSensitive) { 1629 1620 int searchFlags = 0; -
trunk/test/unit/org/openstreetmap/josm/actions/search/SearchCompilerTest.java
r8859 r8899 16 16 import org.openstreetmap.josm.data.osm.Node; 17 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 18 19 import org.openstreetmap.josm.data.osm.Relation; 19 20 import org.openstreetmap.josm.data.osm.RelationData; 20 21 import org.openstreetmap.josm.data.osm.RelationMember; 22 import org.openstreetmap.josm.data.osm.User; 21 23 import org.openstreetmap.josm.data.osm.Way; 22 24 import org.openstreetmap.josm.data.osm.WayData; … … 325 327 } 326 328 } 329 330 /** 331 * Search for node objects. 332 * @throws ParseError if an error has been encountered while compiling 333 */ 334 @Test 335 public void testTypeNode() throws ParseError { 336 final SearchContext sc = new SearchContext("type:node"); 337 for (OsmPrimitive p : new OsmPrimitive[]{sc.n1, sc.n2, sc.w1, sc.w2, sc.r1, sc.r2}) { 338 sc.match(p, OsmPrimitiveType.NODE.equals(p.getType())); 339 } 340 } 341 342 /** 343 * Search for way objects. 344 * @throws ParseError if an error has been encountered while compiling 345 */ 346 @Test 347 public void testTypeWay() throws ParseError { 348 final SearchContext sc = new SearchContext("type:way"); 349 for (OsmPrimitive p : new OsmPrimitive[]{sc.n1, sc.n2, sc.w1, sc.w2, sc.r1, sc.r2}) { 350 sc.match(p, OsmPrimitiveType.WAY.equals(p.getType())); 351 } 352 } 353 354 /** 355 * Search for relation objects. 356 * @throws ParseError if an error has been encountered while compiling 357 */ 358 @Test 359 public void testTypeRelation() throws ParseError { 360 final SearchContext sc = new SearchContext("type:relation"); 361 for (OsmPrimitive p : new OsmPrimitive[]{sc.n1, sc.n2, sc.w1, sc.w2, sc.r1, sc.r2}) { 362 sc.match(p, OsmPrimitiveType.RELATION.equals(p.getType())); 363 } 364 } 365 366 /** 367 * Search for users. 368 * @throws ParseError if an error has been encountered while compiling 369 */ 370 @Test 371 public void testUser() throws ParseError { 372 final SearchContext foobar = new SearchContext("user:foobar"); 373 foobar.n1.setUser(User.createLocalUser("foobar")); 374 foobar.match(foobar.n1, true); 375 foobar.match(foobar.n2, false); 376 final SearchContext anonymous = new SearchContext("user:anonymous"); 377 anonymous.n1.setUser(User.createLocalUser("foobar")); 378 anonymous.match(anonymous.n1, false); 379 anonymous.match(anonymous.n2, true); 380 } 327 381 }
Note:
See TracChangeset
for help on using the changeset viewer.