Ticket #10391: 10391_not_working.patch
| File 10391_not_working.patch, 5.4 KB (added by , 11 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
179 179 | < CARET: "^" > 180 180 | < FULLSTOP: "." > 181 181 | < ELEMENT_OF: "∈" > 182 | < NOT_ELEMENT_OF: "∉" > 182 183 | < CROSSING: "⧉" > 183 184 | < COMMENT_START: "/*" > : COMMENT 184 185 | < UNEXPECTED_CHAR : ~[] > // avoid TokenMgrErrors because they are hard to recover from … … 534 535 | 535 536 <ELEMENT_OF> { type = Selector.ChildOrParentSelectorType.ELEMENT_OF; } 536 537 | 538 <NOT_ELEMENT_OF> { type = Selector.ChildOrParentSelectorType.NOT_ELEMENT_OF; } 539 | 537 540 <CROSSING> { type = Selector.ChildOrParentSelectorType.CROSSING; } 538 541 ) 539 542 w() -
src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
25 25 26 26 /** 27 27 * MapCSS selector. 28 * 28 * 29 29 * A rule has two parts, a selector and a declaration block 30 30 * e.g. 31 31 * <pre> 32 * way[highway=residential] 33 * { width: 10; color: blue; } 32 * way[highway=residential] 33 * { width: 10; color: blue; } 34 34 * </pre> 35 * 35 * 36 36 * The selector decides, if the declaration block gets applied or not. 37 * 37 * 38 38 * All implementing classes of Selector are immutable. 39 39 */ 40 40 public interface Selector { … … 48 48 * @return true, if the selector applies 49 49 */ 50 50 boolean matches(Environment env); 51 51 52 52 String getSubpart(); 53 53 54 54 Range getRange(); 55 55 56 56 /** 57 57 * Create an "optimized" copy of this selector that omits the base check. 58 * 58 * 59 59 * For the style source, the list of rules is preprocessed, such that 60 60 * there is a separate list of rules for nodes, ways, ... 61 * 61 * 62 62 * This means that the base check does not have to be performed 63 63 * for each rule, but only once for each primitive. 64 * 64 * 65 65 * @return a selector that is identical to this object, except the base of the 66 66 * "rightmost" selector is not checked 67 67 */ 68 68 Selector optimizedBaseCheck(); 69 69 70 70 public static enum ChildOrParentSelectorType { 71 CHILD, PARENT, ELEMENT_OF, CROSSING, SIBLING 71 CHILD, 72 PARENT, 73 ELEMENT_OF, 74 NOT_ELEMENT_OF, 75 CROSSING, 76 SIBLING 72 77 } 73 78 74 79 /** … … 265 270 if (!right.matches(e)) 266 271 return false; 267 272 268 if (ChildOrParentSelectorType.ELEMENT_OF.equals(type)) { 273 boolean elementOf = ChildOrParentSelectorType.ELEMENT_OF.equals(type); 274 boolean notElementOf = ChildOrParentSelectorType.NOT_ELEMENT_OF.equals(type); 269 275 276 if (elementOf || notElementOf) { 277 270 278 if (e.osm instanceof Node || e.osm.getDataSet() == null) { 271 279 // nodes cannot contain elements 272 280 return false; … … 308 316 containsFinder.visit(e.osm.getDataSet().allPrimitives()); 309 317 } 310 318 311 return e .child != null;319 return elementOf ? e.child != null : e.child == null; 312 320 313 321 } else if (ChildOrParentSelectorType.CROSSING.equals(type) && e.osm instanceof Way) { 314 322 e.parent = e.osm; … … 379 387 public Range getRange() { 380 388 return right.getRange(); 381 389 } 382 390 383 391 @Override 384 392 public Selector optimizedBaseCheck() { 385 393 return new ChildOrParentSelector(left, link, right.optimizedBaseCheck(), type); … … 472 480 public GeneralSelector(String base, Pair<Integer, Integer> zoom, List<Condition> conds, String subpart) { 473 481 super(base, zoom, conds, subpart); 474 482 } 475 483 476 484 public boolean matchesConditions(Environment e) { 477 485 return super.matches(e); 478 486 } … … 487 495 return matchesBase(e) && super.matches(e); 488 496 } 489 497 } 490 498 491 499 public static class OptimizedGeneralSelector extends AbstractSelector { 492 500 public final String base; 493 501 public final Range range; … … 509 517 } 510 518 this.subpart = subpart; 511 519 } 512 520 513 521 public OptimizedGeneralSelector(String base, Range range, List<Condition> conds, String subpart) { 514 522 super(conds); 515 523 this.base = base; 516 524 this.range = range; 517 525 this.subpart = subpart; 518 526 } 519 527 520 528 public OptimizedGeneralSelector(GeneralSelector s) { 521 529 this(s.base, s.range, s.conds, s.subpart); 522 530 } … … 571 579 public Selector optimizedBaseCheck() { 572 580 throw new UnsupportedOperationException(); 573 581 } 574 582 575 583 public static Range fromLevel(int a, int b) { 576 584 if (a > b) 577 585 throw new AssertionError(); … … 595 603 // or similar level are displayed at the given scale 596 604 return 2.0 * Math.PI * R / Math.pow(2.0, lvl) / 2.56; 597 605 } 598 606 599 607 public static int scale2level(double scale) { 600 608 if (scale < 0) 601 609 throw new IllegalArgumentException();
