Changeset 7064 in josm for trunk/src/org
- Timestamp:
- 2014-05-05T13:26:03+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
r7057 r7064 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
r7057 r7064 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; … … 48 49 MapCSSStyleSource sheet; 49 50 StringBuilder sb; 51 int declarationCounter; 50 52 51 53 /** … … 71 73 public MapCSSParser(InputStream in, String encoding, LexicalState initState) { 72 74 this(createTokenManager(in, encoding, initState)); 75 declarationCounter = 0; 73 76 } 74 77 … … 469 472 void sheet(MapCSSStyleSource sheet): 470 473 { 471 MapCSSRule r;472 474 } 473 475 { … … 476 478 ( 477 479 try { 478 r =rule() { if (r != null) { sheet.rules.add(r); } }w()480 rule() w() 479 481 } catch (MapCSSException mex) { 480 482 error_skipto(RBRACE, mex); … … 488 490 } 489 491 490 MapCSSRulerule():492 void rule(): 491 493 { 492 494 List<Selector> selectors = new ArrayList<Selector>(); 493 495 Selector sel; 494 List<Instruction>decl;496 Declaration decl; 495 497 } 496 498 { … … 501 503 )* 502 504 decl=declaration() 503 { return new MapCSSRule(selectors, decl); } 505 { 506 for (Selector s : selectors) { 507 sheet.rules.add(new MapCSSRule(s, decl)); 508 } 509 } 504 510 } 505 511 … … 707 713 } 708 714 709 List<Instruction>declaration() :715 Declaration declaration() : 710 716 { 711 717 List<Instruction> ins = new ArrayList<Instruction>(); … … 723 729 ( <EQUAL> val=expression() )? 724 730 { ins.add(new Instruction.AssignmentInstruction(key.image, val == null ? true : val, true)); } 725 ( <RBRACE> { return ins; } | <SEMICOLON> w() )731 ( <RBRACE> { return new Declaration(ins, declarationCounter++); } | <SEMICOLON> w() ) 726 732 ) 727 733 | … … 732 738 { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); } 733 739 w() 734 ( <RBRACE> { return ins; } | <SEMICOLON> w() )740 ( <RBRACE> { return new Declaration(ins, declarationCounter++); } | <SEMICOLON> w() ) 735 741 | 736 742 LOOKAHEAD( expression() ( <SEMICOLON> | <RBRACE> ) ) 737 743 val=expression() 738 744 { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); } 739 ( <RBRACE> { return ins; } | <SEMICOLON> w() )745 ( <RBRACE> { return new Declaration(ins, declarationCounter++); } | <SEMICOLON> w() ) 740 746 | 741 747 val=readRaw() w() { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); } … … 743 749 )* 744 750 <RBRACE> 745 { return ins; }751 { return new Declaration(ins, declarationCounter++); } 746 752 } 747 753 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSRule.java
r7057 r7064 9 9 public class MapCSSRule { 10 10 11 public List<Selector> selectors;12 public List<Instruction>declaration;11 public final Selector selector; 12 public final Declaration declaration; 13 13 14 public MapCSSRule(List<Selector> selectors, List<Instruction> declaration) { 15 this.selectors = selectors; 14 public static class Declaration { 15 public final List<Instruction> instructions; 16 // declarations in the StyleSource are numbered consecutively 17 public final int idx; 18 19 public Declaration(List<Instruction> instructions, int idx) { 20 this.instructions = instructions; 21 this.idx = idx; 22 } 23 } 24 25 public MapCSSRule(Selector selector, Declaration declaration) { 26 this.selector = selector; 16 27 this.declaration = declaration; 17 28 } … … 23 34 */ 24 35 public void execute(Environment env) { 25 for (Instruction i : declaration ) {36 for (Instruction i : declaration.instructions) { 26 37 i.execute(env); 27 38 } … … 30 41 @Override 31 42 public String toString() { 32 return Utils.join(",", selectors) + " {\n " + Utils.join("\n ", declaration) + "\n}";43 return selector + " {\n " + Utils.join("\n ", declaration.instructions) + "\n}"; 33 44 } 34 45 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r7057 r7064 28 28 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector; 29 29 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector; 30 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.OptimizedGeneralSelector;31 30 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser; 32 31 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException; … … 118 117 // optimization: filter rules for different primitive types 119 118 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)); 158 } 159 rules.clear(); 119 // find the rightmost selector, this must be a GeneralSelector 120 Selector selRightmost = r.selector; 121 while (selRightmost instanceof ChildOrParentSelector) { 122 selRightmost = ((ChildOrParentSelector) selRightmost).right; 123 } 124 MapCSSRule optRule = new MapCSSRule(r.selector.optimizedBaseCheck(), r.declaration); 125 switch (((GeneralSelector) selRightmost).getBase()) { 126 case "node": 127 nodeRules.add(optRule); 128 break; 129 case "way": 130 wayRules.add(optRule); 131 break; 132 case "area": 133 wayRules.add(optRule); 134 multipolygonRules.add(optRule); 135 break; 136 case "relation": 137 relationRules.add(optRule); 138 multipolygonRules.add(optRule); 139 break; 140 case "*": 141 nodeRules.add(optRule); 142 wayRules.add(optRule); 143 relationRules.add(optRule); 144 multipolygonRules.add(optRule); 145 break; 146 } 147 } 160 148 } 161 149 … … 217 205 Environment env = new Environment(n, mc, "default", this); 218 206 219 NEXT_RULE:220 207 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); 208 if ((r.selector instanceof GeneralSelector)) { 209 GeneralSelector gs = (GeneralSelector) r.selector; 210 if (gs.getBase().equals(type)) { 211 if (!gs.matchesConditions(env)) { 212 continue; 229 213 } 214 r.execute(env); 230 215 } 231 216 } … … 254 239 } 255 240 } 256 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; 241 242 // the declaration indices are sorted, so it suffices to save the 243 // last used index 244 int lastDeclUsed = -1; 245 246 for (MapCSSRule r : matchingRules) { 247 env.clearSelectorMatchingInformation(); 248 if (r.selector.matches(env)) { // as side effect env.parent will be set (if s is a child selector) 249 Selector s = r.selector; 250 if (s.getRange().contains(scale)) { 251 mc.range = Range.cut(mc.range, s.getRange()); 252 } else { 253 mc.range = mc.range.reduceAround(scale, s.getRange()); 254 continue; 255 } 256 257 if (r.declaration.idx == lastDeclUsed) continue; // don't apply one declaration more than once 258 lastDeclUsed = r.declaration.idx; 259 String sub = s.getSubpart(); 260 if (sub == null) { 261 sub = "default"; 262 } 263 else if ("*".equals(sub)) { 264 for (Entry<String, Cascade> entry : mc.getLayers()) { 265 env.layer = entry.getKey(); 266 if (Utils.equal(env.layer, "*")) { 267 continue; 268 } 269 r.execute(env); 265 270 } 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 } 271 } 272 env.layer = sub; 273 r.execute(env); 284 274 } 285 275 }
Note:
See TracChangeset
for help on using the changeset viewer.