Changeset 7057 in josm
- Timestamp:
- 2014-05-04T12:55:06+02:00 (10 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
r7056 r7057 123 123 final TagCheck check = new TagCheck(rule); 124 124 boolean containsSetClassExpression = false; 125 for (Instruction i : rule.declaration .instructions) {125 for (Instruction i : rule.declaration) { 126 126 if (i instanceof Instruction.AssignmentInstruction) { 127 127 final Instruction.AssignmentInstruction ai = (Instruction.AssignmentInstruction) i; … … 161 161 } 162 162 if (check.errors.isEmpty() && !containsSetClassExpression) { 163 throw new RuntimeException("No throwError/throwWarning/throwOther given! You should specify a validation error message for " + rule.selector );163 throw new RuntimeException("No throwError/throwWarning/throwOther given! You should specify a validation error message for " + rule.selectors); 164 164 } else if (check.errors.size() > 1) { 165 throw new RuntimeException("More than one throwError/throwWarning/throwOther given! You should specify a single validation error message for " + rule.selector );165 throw new RuntimeException("More than one throwError/throwWarning/throwOther given! You should specify a single validation error message for " + rule.selectors); 166 166 } 167 167 return check; … … 191 191 for (Iterator<MapCSSRule> it = source.rules.iterator(); it.hasNext(); ) { 192 192 MapCSSRule x = it.next(); 193 if (x.selector instanceof GeneralSelector) { 194 GeneralSelector gs = (GeneralSelector) x.selector; 195 if ("meta".equals(gs.base) && gs.getConditions().isEmpty()) { 196 it.remove(); 193 if (x.selectors.size() == 1) { 194 Selector sel = x.selectors.get(0); 195 if (sel instanceof GeneralSelector) { 196 GeneralSelector gs = (GeneralSelector) sel; 197 if ("meta".equals(gs.base) && gs.getConditions().isEmpty()) { 198 it.remove(); 199 } 197 200 } 198 201 } … … 211 214 212 215 Selector whichSelectorMatchesEnvironment(Environment env) { 213 env.clearSelectorMatchingInformation(); 214 if (rule.selector.matches(env)) { 215 return rule.selector; 216 for (Selector i : rule.selectors) { 217 env.clearSelectorMatchingInformation(); 218 if (i.matches(env)) { 219 return i; 220 } 216 221 } 217 222 return null; -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r7056 r7057 18 18 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction; 19 19 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule; 20 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule.Declaration;21 20 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 22 21 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector; … … 470 469 void sheet(MapCSSStyleSource sheet): 471 470 { 471 MapCSSRule r; 472 472 } 473 473 { … … 476 476 ( 477 477 try { 478 r ule()w()478 r=rule() { if (r != null) { sheet.rules.add(r); } } w() 479 479 } catch (MapCSSException mex) { 480 480 error_skipto(RBRACE, mex); … … 488 488 } 489 489 490 voidrule():490 MapCSSRule rule(): 491 491 { 492 492 List<Selector> selectors = new ArrayList<Selector>(); 493 493 Selector sel; 494 Declarationdecl;494 List<Instruction> decl; 495 495 } 496 496 { … … 501 501 )* 502 502 decl=declaration() 503 { 504 for (Selector s : selectors) { 505 sheet.rules.add(new MapCSSRule(s, decl)); 506 } 507 } 503 { return new MapCSSRule(selectors, decl); } 508 504 } 509 505 … … 711 707 } 712 708 713 Declarationdeclaration() :709 List<Instruction> declaration() : 714 710 { 715 711 List<Instruction> ins = new ArrayList<Instruction>(); … … 727 723 ( <EQUAL> val=expression() )? 728 724 { ins.add(new Instruction.AssignmentInstruction(key.image, val == null ? true : val, true)); } 729 ( <RBRACE> { return new Declaration(ins); } | <SEMICOLON> w() )725 ( <RBRACE> { return ins; } | <SEMICOLON> w() ) 730 726 ) 731 727 | … … 736 732 { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); } 737 733 w() 738 ( <RBRACE> { return new Declaration(ins); } | <SEMICOLON> w() )734 ( <RBRACE> { return ins; } | <SEMICOLON> w() ) 739 735 | 740 736 LOOKAHEAD( expression() ( <SEMICOLON> | <RBRACE> ) ) 741 737 val=expression() 742 738 { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); } 743 ( <RBRACE> { return new Declaration(ins); } | <SEMICOLON> w() )739 ( <RBRACE> { return ins; } | <SEMICOLON> w() ) 744 740 | 745 741 val=readRaw() w() { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); } … … 747 743 )* 748 744 <RBRACE> 749 { return new Declaration(ins); }745 { return ins; } 750 746 } 751 747 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSRule.java
r7056 r7057 9 9 public class MapCSSRule { 10 10 11 public Selector selector;12 public Declarationdeclaration;11 public List<Selector> selectors; 12 public List<Instruction> declaration; 13 13 14 public static class Declaration { 15 public List<Instruction> instructions; 16 // usedId is an optimized way to make sure that 17 // each declaration is only applied once for each primitive, 18 // even if multiple of the comma separated selectors in the 19 // rule match. 20 public int usedId; 21 22 public Declaration(List<Instruction> instructions) { 23 this.instructions = instructions; 24 usedId = 0; 25 } 26 } 27 28 public MapCSSRule(Selector selector, Declaration declaration) { 29 this.selector = selector; 14 public MapCSSRule(List<Selector> selectors, List<Instruction> declaration) { 15 this.selectors = selectors; 30 16 this.declaration = declaration; 31 17 } … … 37 23 */ 38 24 public void execute(Environment env) { 39 for (Instruction i : declaration .instructions) {25 for (Instruction i : declaration) { 40 26 i.execute(env); 41 27 } … … 44 30 @Override 45 31 public String toString() { 46 return selector + " {\n " + Utils.join("\n ", declaration.instructions) + "\n}";32 return Utils.join(",", selectors) + " {\n " + Utils.join("\n ", declaration) + "\n}"; 47 33 } 48 34 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r7056 r7057 58 58 private ZipFile zipFile; 59 59 60 private static int usedId = 1;61 62 60 public MapCSSStyleSource(String url, String name, String shortdescription) { 63 61 super(url, name, shortdescription); … … 120 118 // optimization: filter rules for different primitive types 121 119 for (MapCSSRule r: rules) { 122 // find the rightmost selector, this must be a GeneralSelector 123 Selector selRightmost = r.selector; 124 while (selRightmost instanceof ChildOrParentSelector) { 125 selRightmost = ((ChildOrParentSelector) selRightmost).right; 126 } 127 MapCSSRule optRule = new MapCSSRule(r.selector.optimizedBaseCheck(), r.declaration); 128 switch (((GeneralSelector) selRightmost).getBase()) { 129 case "node": 130 nodeRules.add(optRule); 131 break; 132 case "way": 133 wayRules.add(optRule); 134 break; 135 case "area": 136 wayRules.add(optRule); 137 multipolygonRules.add(optRule); 138 break; 139 case "relation": 140 relationRules.add(optRule); 141 multipolygonRules.add(optRule); 142 break; 143 case "*": 144 nodeRules.add(optRule); 145 wayRules.add(optRule); 146 relationRules.add(optRule); 147 multipolygonRules.add(optRule); 148 break; 149 } 120 List<Selector> nodeSel = new ArrayList<>(); 121 List<Selector> waySel = new ArrayList<>(); 122 List<Selector> relationSel = new ArrayList<>(); 123 List<Selector> multipolygonSel = new ArrayList<>(); 124 for (Selector sel : r.selectors) { 125 // find the rightmost selector, this must be a GeneralSelector 126 Selector selRightmost = sel; 127 while (selRightmost instanceof ChildOrParentSelector) { 128 selRightmost = ((ChildOrParentSelector) selRightmost).right; 129 } 130 Selector optimizedSel = sel.optimizedBaseCheck(); 131 switch (((GeneralSelector) selRightmost).getBase()) { 132 case "node": 133 nodeSel.add(optimizedSel); 134 break; 135 case "way": 136 waySel.add(optimizedSel); 137 break; 138 case "area": 139 waySel.add(optimizedSel); 140 multipolygonSel.add(optimizedSel); 141 break; 142 case "relation": 143 relationSel.add(optimizedSel); 144 multipolygonSel.add(optimizedSel); 145 break; 146 case "*": 147 nodeSel.add(optimizedSel); 148 waySel.add(optimizedSel); 149 relationSel.add(optimizedSel); 150 multipolygonSel.add(optimizedSel); 151 break; 152 } 153 } 154 nodeRules.add(new MapCSSRule(nodeSel, r.declaration)); 155 wayRules.add(new MapCSSRule(waySel, r.declaration)); 156 relationRules.add(new MapCSSRule(relationSel, r.declaration)); 157 multipolygonRules.add(new MapCSSRule(multipolygonSel, r.declaration)); 150 158 } 151 159 rules.clear(); … … 211 219 NEXT_RULE: 212 220 for (MapCSSRule r : rules) { 213 if ((r.selector instanceof GeneralSelector)) { 214 GeneralSelector gs = (GeneralSelector) r.selector; 215 if (gs.getBase().equals(type)) { 216 if (!gs.matchesConditions(env)) { 217 continue NEXT_RULE; 221 for (Selector s : r.selectors) { 222 if ((s instanceof GeneralSelector)) { 223 GeneralSelector gs = (GeneralSelector) s; 224 if (gs.getBase().equals(type)) { 225 if (!gs.matchesConditions(env)) { 226 continue NEXT_RULE; 227 } 228 r.execute(env); 218 229 } 219 r.execute(env);220 230 } 221 231 } … … 244 254 } 245 255 } 246 usedId++;247 256 RULE: for (MapCSSRule r : matchingRules) { 248 env.clearSelectorMatchingInformation(); 249 if (r.selector.matches(env)) { // as side effect env.parent will be set (if s is a child selector) 250 Selector s = r.selector; 251 if (s.getRange().contains(scale)) { 252 mc.range = Range.cut(mc.range, s.getRange()); 253 } else { 254 mc.range = mc.range.reduceAround(scale, s.getRange()); 255 continue; 257 for (Selector s : r.selectors) { 258 env.clearSelectorMatchingInformation(); 259 if (s.matches(env)) { // as side effect env.parent will be set (if s is a child selector) 260 if (s.getRange().contains(scale)) { 261 mc.range = Range.cut(mc.range, s.getRange()); 262 } else { 263 mc.range = mc.range.reduceAround(scale, s.getRange()); 264 continue; 265 } 266 267 String sub = s.getSubpart(); 268 if (sub == null) { 269 sub = "default"; 270 } 271 else if ("*".equals(sub)) { 272 for (Entry<String, Cascade> entry : mc.getLayers()) { 273 env.layer = entry.getKey(); 274 if (Utils.equal(env.layer, "*")) { 275 continue; 276 } 277 r.execute(env); 278 } 279 } 280 env.layer = sub; 281 r.execute(env); 282 continue RULE; 256 283 } 257 258 if (r.declaration.usedId == usedId) continue; // don't apply a declaration block more than once259 r.declaration.usedId = usedId;260 String sub = s.getSubpart();261 if (sub == null) {262 sub = "default";263 }264 else if ("*".equals(sub)) {265 for (Entry<String, Cascade> entry : mc.getLayers()) {266 env.layer = entry.getKey();267 if (Utils.equal(env.layer, "*")) {268 continue;269 }270 r.execute(env);271 }272 }273 env.layer = sub;274 r.execute(env);275 continue RULE;276 284 } 277 285 }
Note:
See TracChangeset
for help on using the changeset viewer.