- Timestamp:
- 2014-05-03T11:32:22+02:00 (11 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
r7055 r7056 123 123 final TagCheck check = new TagCheck(rule); 124 124 boolean containsSetClassExpression = false; 125 for (Instruction i : rule.declaration ) {125 for (Instruction i : rule.declaration.instructions) { 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 s);163 throw new RuntimeException("No throwError/throwWarning/throwOther given! You should specify a validation error message for " + rule.selector); 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 s);165 throw new RuntimeException("More than one throwError/throwWarning/throwOther given! You should specify a single validation error message for " + rule.selector); 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.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 } 193 if (x.selector instanceof GeneralSelector) { 194 GeneralSelector gs = (GeneralSelector) x.selector; 195 if ("meta".equals(gs.base) && gs.getConditions().isEmpty()) { 196 it.remove(); 200 197 } 201 198 } … … 214 211 215 212 Selector whichSelectorMatchesEnvironment(Environment env) { 216 for (Selector i : rule.selectors) { 217 env.clearSelectorMatchingInformation(); 218 if (i.matches(env)) { 219 return i; 220 } 213 env.clearSelectorMatchingInformation(); 214 if (rule.selector.matches(env)) { 215 return rule.selector; 221 216 } 222 217 return null; -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r6970 r7056 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; 20 21 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 21 22 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector; … … 469 470 void sheet(MapCSSStyleSource sheet): 470 471 { 471 MapCSSRule r;472 472 } 473 473 { … … 476 476 ( 477 477 try { 478 r =rule() { if (r != null) { sheet.rules.add(r); } }w()478 rule() w() 479 479 } catch (MapCSSException mex) { 480 480 error_skipto(RBRACE, mex); … … 488 488 } 489 489 490 MapCSSRulerule():490 void rule(): 491 491 { 492 492 List<Selector> selectors = new ArrayList<Selector>(); 493 493 Selector sel; 494 List<Instruction>decl;494 Declaration decl; 495 495 } 496 496 { … … 501 501 )* 502 502 decl=declaration() 503 { return new MapCSSRule(selectors, decl); } 503 { 504 for (Selector s : selectors) { 505 sheet.rules.add(new MapCSSRule(s, decl)); 506 } 507 } 504 508 } 505 509 … … 707 711 } 708 712 709 List<Instruction>declaration() :713 Declaration declaration() : 710 714 { 711 715 List<Instruction> ins = new ArrayList<Instruction>(); … … 723 727 ( <EQUAL> val=expression() )? 724 728 { ins.add(new Instruction.AssignmentInstruction(key.image, val == null ? true : val, true)); } 725 ( <RBRACE> { return ins; } | <SEMICOLON> w() )729 ( <RBRACE> { return new Declaration(ins); } | <SEMICOLON> w() ) 726 730 ) 727 731 | … … 732 736 { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); } 733 737 w() 734 ( <RBRACE> { return ins; } | <SEMICOLON> w() )738 ( <RBRACE> { return new Declaration(ins); } | <SEMICOLON> w() ) 735 739 | 736 740 LOOKAHEAD( expression() ( <SEMICOLON> | <RBRACE> ) ) 737 741 val=expression() 738 742 { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); } 739 ( <RBRACE> { return ins; } | <SEMICOLON> w() )743 ( <RBRACE> { return new Declaration(ins); } | <SEMICOLON> w() ) 740 744 | 741 745 val=readRaw() w() { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); } … … 743 747 )* 744 748 <RBRACE> 745 { return ins; }749 { return new Declaration(ins); } 746 750 } 747 751 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSRule.java
r6070 r7056 9 9 public class MapCSSRule { 10 10 11 public List<Selector> selectors;12 public List<Instruction>declaration;11 public Selector selector; 12 public Declaration declaration; 13 13 14 public MapCSSRule(List<Selector> selectors, List<Instruction> declaration) { 15 this.selectors = selectors; 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; 16 30 this.declaration = declaration; 17 31 } … … 23 37 */ 24 38 public void execute(Environment env) { 25 for (Instruction i : declaration ) {39 for (Instruction i : declaration.instructions) { 26 40 i.execute(env); 27 41 } … … 30 44 @Override 31 45 public String toString() { 32 return Utils.join(",", selectors) + " {\n " + Utils.join("\n ", declaration) + "\n}";46 return selector + " {\n " + Utils.join("\n ", declaration.instructions) + "\n}"; 33 47 } 34 48 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r7054 r7056 58 58 private ZipFile zipFile; 59 59 60 private static int usedId = 1; 61 60 62 public MapCSSStyleSource(String url, String name, String shortdescription) { 61 63 super(url, name, shortdescription); … … 118 120 // optimization: filter rules for different primitive types 119 121 for (MapCSSRule r: rules) { 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)); 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 } 158 150 } 159 151 rules.clear(); … … 219 211 NEXT_RULE: 220 212 for (MapCSSRule r : rules) { 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); 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; 229 218 } 219 r.execute(env); 230 220 } 231 221 } … … 254 244 } 255 245 } 246 usedId++; 256 247 RULE: for (MapCSSRule r : matchingRules) { 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; 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; 256 } 257 258 if (r.declaration.usedId == usedId) continue; // don't apply a declaration block more than once 259 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); 265 271 } 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;283 272 } 273 env.layer = sub; 274 r.execute(env); 275 continue RULE; 284 276 } 285 277 }
Note:
See TracChangeset
for help on using the changeset viewer.