Changeset 1603 in josm for trunk/src/org/openstreetmap/josm/actions/search
- Timestamp:
- 2009-05-19T19:01:13+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions/search
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r1516 r1603 94 94 + "<li>"+tr("<b>incomplete</b> - all incomplete objects")+"</li>" 95 95 + "<li>"+tr("<b>untagged</b> - all untagged objects")+"</li>" 96 + "<li>"+tr("<b>child <i>expr</i></b> - all children of objects matching the expression")+"</li>" 97 + "<li>"+tr("<b>parent <i>expr</i></b> - all parents of objects matching the expression")+"</li>" 96 98 + "<li>"+tr("Use <b>|</b> or <b>OR</b> to combine with logical or")+"</li>" 97 99 + "<li>"+tr("Use <b>\"</b> to quote operators (e.g. if key contains :)")+"</li>" -
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r1499 r1603 12 12 import java.util.regex.PatternSyntaxException; 13 13 14 import org.openstreetmap.josm.Main; 14 15 import org.openstreetmap.josm.data.osm.Node; 15 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 17 import org.openstreetmap.josm.data.osm.Relation; 18 import org.openstreetmap.josm.data.osm.RelationMember; 17 19 import org.openstreetmap.josm.data.osm.User; 18 20 import org.openstreetmap.josm.data.osm.Way; 21 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 19 22 import org.openstreetmap.josm.tools.DateUtils; 20 23 … … 320 323 @Override public String toString() {return "untagged";} 321 324 } 325 326 private static class Parent extends Match { 327 private Match child; 328 public Parent(Match m) { child = m; } 329 @Override public boolean match(OsmPrimitive osm) throws ParseError { 330 boolean isParent = false; 331 332 // "parent" (null) should mean the same as "parent()" 333 // (Always). I.e. match everything 334 if (child == null) 335 child = new Always(); 336 337 if (osm instanceof Way) { 338 for (Node n : ((Way)osm).nodes) 339 isParent |= child.match(n); 340 } else if (osm instanceof Relation) { 341 for (RelationMember member : ((Relation)osm).members) { 342 if (member.member != null) 343 isParent |= child.match(member.member); 344 } 345 } 346 return isParent; 347 } 348 @Override public String toString() {return "parent(" + child + ")";} 349 } 350 351 private static class Child extends Match { 352 private Match parent; 353 public Child(Match m) { parent = m; } 354 @Override public boolean match(OsmPrimitive osm) throws ParseError { 355 // "child" (null) should mean the same as "child()" 356 // (Always). I.e. match everything 357 if (parent == null) 358 parent = new Always(); 359 360 boolean isChild = false; 361 CollectBackReferencesVisitor backRefs = new CollectBackReferencesVisitor(Main.ds); 362 osm.visit(backRefs); 363 for (OsmPrimitive p : backRefs.data) { 364 isChild |= parent.match(p); 365 } 366 return isChild; 367 } 368 @Override public String toString() {return "child(" + parent + ")";} 369 } 322 370 323 371 public static class ParseError extends Exception { … … 388 436 } 389 437 390 private Match parsePat() {438 private Match parsePat() throws ParseError { 391 439 String tok = tokenizer.readText(); 392 440 … … 408 456 } else if (tok.equals("selected")) { 409 457 return new Selected(); 458 } else if (tok.equals("child")) { 459 return new Child(parseParens()); 460 } else if (tok.equals("parent")) { 461 return new Parent(parseParens()); 410 462 } else { 411 463 return new Any(tok);
Note:
See TracChangeset
for help on using the changeset viewer.