Changeset 15987 in josm for trunk/src/org
- Timestamp:
- 2020-03-01T23:36:04+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r15984 r15987 54 54 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource.MapCSSRuleIndex; 55 55 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector; 56 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector. OptimizedGeneralSelector;56 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector; 57 57 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser; 58 58 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException; … … 453 453 /** 454 454 * Determines the {@code index}-th key/value/tag (depending on {@code type}) of the 455 * {@link org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector}.455 * {@link GeneralSelector}. 456 456 * @param matchingSelector matching selector 457 457 * @param index index … … 460 460 * @return argument value, can be {@code null} 461 461 */ 462 static String determineArgument( OptimizedGeneralSelector matchingSelector, int index, String type, OsmPrimitive p) {462 static String determineArgument(GeneralSelector matchingSelector, int index, String type, OsmPrimitive p) { 463 463 try { 464 464 final Condition c = matchingSelector.getConditions().get(index); … … 492 492 if (s != null && matchingSelector instanceof Selector.ChildOrParentSelector) { 493 493 return insertArguments(((Selector.ChildOrParentSelector) matchingSelector).right, s, p); 494 } else if (s == null || !(matchingSelector instanceof Selector.OptimizedGeneralSelector)) {494 } else if (s == null || !(matchingSelector instanceof GeneralSelector)) { 495 495 return s; 496 496 } … … 498 498 final StringBuffer sb = new StringBuffer(); 499 499 while (m.find()) { 500 final String argument = determineArgument(( Selector.OptimizedGeneralSelector) matchingSelector,500 final String argument = determineArgument((GeneralSelector) matchingSelector, 501 501 Integer.parseInt(m.group(1)), m.group(2), p); 502 502 try { -
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerIndex.java
r15986 r15987 89 89 } 90 90 91 MapCSSRule optRule = new MapCSSRule(s .optimizedBaseCheck(), c.rule.declaration);91 MapCSSRule optRule = new MapCSSRule(s, c.rule.declaration); 92 92 93 93 ruleToCheckMap.put(optRule, c); -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r15986 r15987 461 461 } 462 462 // optimization: filter rules for different primitive types 463 for (MapCSSRule r: rules) { 464 MapCSSRule optRule = new MapCSSRule(r.selector.optimizedBaseCheck(), r.declaration); 465 final String base = r.selector.getBase(); 463 for (MapCSSRule optRule: rules) { 464 final String base = optRule.selector.getBase(); 466 465 switch (base) { 467 466 case Selector.BASE_NODE: … … 488 487 break; 489 488 case Selector.BASE_CANVAS: 490 canvasRules.add( r);489 canvasRules.add(optRule); 491 490 break; 492 491 case Selector.BASE_META: -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r15986 r15987 113 113 114 114 String getBase(); 115 116 /**117 * Create an "optimized" copy of this selector that omits the base check.118 *119 * For the style source, the list of rules is preprocessed, such that120 * there is a separate list of rules for nodes, ways, ...121 *122 * This means that the base check does not have to be performed123 * for each rule, but only once for each primitive.124 *125 * @return a selector that is identical to this object, except the base of the126 * "rightmost" selector is not checked127 */128 Selector optimizedBaseCheck();129 115 130 116 /** … … 484 470 if (e.osm.getDataSet() == null) { 485 471 // do nothing 486 } else if (left instanceof OptimizedGeneralSelector) {487 if (withNodes && (( OptimizedGeneralSelector) left).matchesBase(OsmPrimitiveType.NODE)) {472 } else if (left instanceof GeneralSelector) { 473 if (withNodes && ((GeneralSelector) left).matchesBase(OsmPrimitiveType.NODE)) { 488 474 finder.visit(e.osm.getDataSet().searchNodes(e.osm.getBBox())); 489 475 } 490 if ((( OptimizedGeneralSelector) left).matchesBase(OsmPrimitiveType.WAY)) {476 if (((GeneralSelector) left).matchesBase(OsmPrimitiveType.WAY)) { 491 477 finder.visit(e.osm.getDataSet().searchWays(e.osm.getBBox())); 492 478 } 493 if ((( OptimizedGeneralSelector) left).matchesBase(OsmPrimitiveType.RELATION)) {479 if (((GeneralSelector) left).matchesBase(OsmPrimitiveType.RELATION)) { 494 480 finder.visit(e.osm.getDataSet().searchRelations(e.osm.getBBox())); 495 481 } … … 621 607 622 608 @Override 623 public Selector optimizedBaseCheck() {624 return new ChildOrParentSelector(left, link, right.optimizedBaseCheck(), type);625 }626 627 @Override628 609 public String toString() { 629 610 return left.toString() + ' ' + (ChildOrParentSelectorType.PARENT == type ? '<' : '>') + link + ' ' + right; … … 701 682 702 683 @Override 703 public Selector optimizedBaseCheck() {704 throw new UnsupportedOperationException();705 }706 707 @Override708 684 public String toString() { 709 685 return "LinkSelector{conditions=" + conds + '}'; … … 714 690 * General selector. See <a href="https://josm.openstreetmap.de/wiki/Help/Styles/MapCSSImplementation#Selectors">wiki</a> 715 691 */ 716 class GeneralSelector extends OptimizedGeneralSelector { 717 718 public GeneralSelector(String base, Range zoom, List<Condition> conds, Subpart subpart) { 719 super(base, zoom, conds, subpart); 720 } 721 722 public boolean matchesConditions(Environment e) { 723 return super.matches(e); 724 } 725 726 @Override 727 public Selector optimizedBaseCheck() { 728 return new OptimizedGeneralSelector(this); 729 } 730 731 @Override 732 public boolean matches(Environment e) { 733 return matchesBase(e) && super.matches(e); 734 } 735 } 736 737 /** 738 * Superclass of {@link GeneralSelector}. Used to create an "optimized" copy of this selector that omits the base check. 739 * @see Selector#optimizedBaseCheck 740 */ 741 class OptimizedGeneralSelector extends AbstractSelector { 692 class GeneralSelector extends AbstractSelector { 693 742 694 public final String base; 743 695 public final Range range; 744 696 public final Subpart subpart; 745 697 746 public OptimizedGeneralSelector(String base, Range range, List<Condition> conds, Subpart subpart) {698 public GeneralSelector(String base, Range range, List<Condition> conds, Subpart subpart) { 747 699 super(conds); 748 700 this.base = checkBase(base); … … 751 703 } 752 704 753 public OptimizedGeneralSelector(GeneralSelector s) {754 this(s.base, s.range, s.conds, s.subpart);755 }756 757 705 @Override 758 706 public Subpart getSubpart() { … … 763 711 public Range getRange() { 764 712 return range; 713 } 714 715 public boolean matchesConditions(Environment e) { 716 return super.matches(e); 717 } 718 719 @Override 720 public boolean matches(Environment e) { 721 return matchesBase(e) && super.matches(e); 765 722 } 766 723 … … 824 781 } 825 782 826 @Override827 public Selector optimizedBaseCheck() {828 throw new UnsupportedOperationException();829 }830 831 783 public static Range fromLevel(int a, int b) { 832 784 // for input validation in Range constructor below
Note:
See TracChangeset
for help on using the changeset viewer.