Changeset 15986 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-03-01T23:36:02+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerIndex.java
r15104 r15986 84 84 85 85 for (Selector s : c.rule.selectors) { 86 // find the rightmost selector, this must be a GeneralSelector 87 boolean hasLeftRightSel = false; 88 Selector selRightmost = s; 89 while (selRightmost instanceof Selector.ChildOrParentSelector) { 90 hasLeftRightSel = true; 91 selRightmost = ((Selector.ChildOrParentSelector) selRightmost).right; 92 } 86 boolean hasLeftRightSel = s instanceof Selector.ChildOrParentSelector; 93 87 if (!allTests && !hasLeftRightSel) { 94 88 continue; … … 98 92 99 93 ruleToCheckMap.put(optRule, c); 100 final String base = ((GeneralSelector) selRightmost).getBase();94 final String base = s.getBase(); 101 95 switch (base) { 102 96 case Selector.BASE_NODE: -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r15949 r15986 17 17 import java.util.ArrayList; 18 18 import java.util.BitSet; 19 import java.util.Collection; 19 20 import java.util.Collections; 20 21 import java.util.HashMap; … … 26 27 import java.util.Map.Entry; 27 28 import java.util.NoSuchElementException; 29 import java.util.Optional; 28 30 import java.util.Set; 29 31 import java.util.concurrent.locks.ReadWriteLock; … … 56 58 import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyValueCondition; 57 59 import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.SimpleKeyValueCondition; 58 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector;59 60 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector; 60 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.OptimizedGeneralSelector;61 61 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser; 62 62 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException; … … 292 292 for (int ruleIndex = 0; ruleIndex < rules.size(); ruleIndex++) { 293 293 MapCSSRule r = rules.get(ruleIndex); 294 // find the rightmost selector, this must be a GeneralSelector 295 Selector selRightmost = r.selector; 296 while (selRightmost instanceof ChildOrParentSelector) { 297 selRightmost = ((ChildOrParentSelector) selRightmost).right; 298 } 299 OptimizedGeneralSelector s = (OptimizedGeneralSelector) selRightmost; 300 if (s.conds == null) { 294 final List<Condition> conditions = r.selector.getConditions(); 295 if (conditions == null || conditions.isEmpty()) { 301 296 remaining.set(ruleIndex); 302 297 continue; 303 298 } 304 List<SimpleKeyValueCondition> sk = new ArrayList<>(Utils.filteredCollection(s.conds, 305 SimpleKeyValueCondition.class)); 306 if (!sk.isEmpty()) { 307 SimpleKeyValueCondition c = sk.get(sk.size() - 1); 308 getEntryInIndex(c.k).addForKeyAndValue(c.v, ruleIndex); 299 Optional<SimpleKeyValueCondition> lastCondition = Utils.filteredCollection(conditions, SimpleKeyValueCondition.class).stream() 300 .reduce((first, last) -> last); 301 if (lastCondition.isPresent()) { 302 getEntryInIndex(lastCondition.get().k).addForKeyAndValue(lastCondition.get().v, ruleIndex); 309 303 } else { 310 String key = findAnyRequiredKey( s.conds);304 String key = findAnyRequiredKey(conditions); 311 305 if (key != null) { 312 306 getEntryInIndex(key).addForKey(ruleIndex); … … 468 462 // optimization: filter rules for different primitive types 469 463 for (MapCSSRule r: rules) { 470 // find the rightmost selector, this must be a GeneralSelector471 Selector selRightmost = r.selector;472 while (selRightmost instanceof ChildOrParentSelector) {473 selRightmost = ((ChildOrParentSelector) selRightmost).right;474 }475 464 MapCSSRule optRule = new MapCSSRule(r.selector.optimizedBaseCheck(), r.declaration); 476 final String base = ((GeneralSelector) selRightmost).getBase();465 final String base = r.selector.getBase(); 477 466 switch (base) { 478 467 case Selector.BASE_NODE: … … 758 747 */ 759 748 public void removeMetaRules() { 760 for (Iterator<MapCSSRule> it = rules.iterator(); it.hasNext();) { 761 MapCSSRule x = it.next(); 762 if (x.selector instanceof GeneralSelector) { 763 GeneralSelector gs = (GeneralSelector) x.selector; 764 if (Selector.BASE_META.equals(gs.base)) { 765 it.remove(); 766 } 767 } 768 } 749 rules.removeIf(x -> x.selector instanceof GeneralSelector && Selector.BASE_META.equals(x.selector.getBase())); 769 750 } 770 751 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r15985 r15986 112 112 Range getRange(); 113 113 114 String getBase(); 115 114 116 /** 115 117 * Create an "optimized" copy of this selector that omits the base check. … … 177 179 this.right = b; 178 180 this.type = type; 181 } 182 183 @Override 184 public String getBase() { 185 // take the base from the rightmost selector 186 return right.getBase(); 179 187 } 180 188 … … 678 686 679 687 @Override 688 public String getBase() { 689 throw new UnsupportedOperationException(); 690 } 691 692 @Override 680 693 public Subpart getSubpart() { 681 throw new UnsupportedOperationException( "Not supported yet.");694 throw new UnsupportedOperationException(); 682 695 } 683 696 684 697 @Override 685 698 public Range getRange() { 686 throw new UnsupportedOperationException( "Not supported yet.");699 throw new UnsupportedOperationException(); 687 700 } 688 701 … … 774 787 } 775 788 789 @Override 776 790 public String getBase() { 777 791 return base;
Note:
See TracChangeset
for help on using the changeset viewer.