Changeset 8775 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r8540 r8775 16 16 import java.util.Collections; 17 17 import java.util.List; 18 import java.util.TreeSet; 18 19 import java.util.regex.Matcher; 19 20 import java.util.regex.Pattern; … … 31 32 import org.openstreetmap.josm.gui.util.RotationAngle; 32 33 import org.openstreetmap.josm.io.XmlWriter; 34 import org.openstreetmap.josm.tools.AlphanumComparator; 33 35 import org.openstreetmap.josm.tools.ColorHelper; 34 36 import org.openstreetmap.josm.tools.Geometry; … … 375 377 376 378 /** 379 * Joins a list of {@code values} into a single string with fields separated by {@code separator}. 380 * @param separator the separator 381 * @param values collection of objects 382 * @return assembled string 383 * @see Utils#join 384 */ 385 public static String join_list(final String separator, final List<String> values) { 386 return Utils.join(separator, values); 387 } 388 389 /** 377 390 * Returns the value of the property {@code key}, e.g., {@code prop("width")}. 378 391 * @param env the environment … … 444 457 } 445 458 return env.parent.get(key); 459 } 460 461 /** 462 * Gets a list of all non-null values of the key {@code key} from the object's parent(s). 463 * 464 * The values are sorted according to {@link AlphanumComparator}. 465 * @param env the environment 466 * @param key the OSM key 467 * @return a list of non-null values of the key {@code key} from the object's parent(s) 468 */ 469 public static List<String> parent_tags(final Environment env, String key) { 470 if (env.parent == null) { 471 if (env.osm != null) { 472 final Collection<String> tags = new TreeSet<>(AlphanumComparator.getInstance()); 473 // we don't have a matched parent, so just search all referrers 474 for (OsmPrimitive parent : env.osm.getReferrers()) { 475 String value = parent.get(key); 476 if (value != null) { 477 tags.add(value); 478 } 479 } 480 return new ArrayList<>(tags); 481 } 482 return Collections.emptyList(); 483 } 484 return Collections.singletonList(env.parent.get(key)); 446 485 } 447 486 -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy
r8657 r8775 322 322 323 323 @Test 324 public void testParentTags() throws Exception { 325 def ds = new DataSet() 326 def n = new org.openstreetmap.josm.data.osm.Node(new LatLon(1, 2)) 327 n.put("foo", "bar") 328 def w1 = new Way() 329 w1.put("ref", "x10") 330 def w2 = new Way() 331 w2.put("ref", "x2") 332 def w3 = new Way() 333 ds.addPrimitive(n) 334 ds.addPrimitive(w1) 335 ds.addPrimitive(w2) 336 ds.addPrimitive(w3) 337 w1.addNode(n) 338 w2.addNode(n) 339 w3.addNode(n) 340 341 MapCSSStyleSource source = new MapCSSStyleSource("node[foo=bar] {refs: join_list(\";\", parent_tags(\"ref\"));}") 342 source.loadStyleSource() 343 assert source.rules.size() == 1 344 def e = new Environment(n, new MultiCascade(), Environment.DEFAULT_LAYER, null) 345 assert source.rules.get(0).selector.matches(e) 346 source.rules.get(0).declaration.execute(e) 347 assert e.getCascade(Environment.DEFAULT_LAYER).get("refs", null, String.class) == "x2;x10" 348 } 349 350 @Test 324 351 public void testSiblingSelectorInterpolation() throws Exception { 325 352 def s1 = (Selector.ChildOrParentSelector) getParser(
Note:
See TracChangeset
for help on using the changeset viewer.