Changeset 7069 in josm
- Timestamp:
- 2014-05-06T12:06:16+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java ¶
r7064 r7069 37 37 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction; 38 38 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule; 39 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule.Declaration; 39 40 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 40 41 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector; … … 47 48 import org.openstreetmap.josm.io.UTFInputStreamReader; 48 49 import org.openstreetmap.josm.tools.CheckParameterUtil; 50 import org.openstreetmap.josm.tools.MultiMap; 49 51 import org.openstreetmap.josm.tools.Predicate; 50 52 import org.openstreetmap.josm.tools.Utils; … … 56 58 public class MapCSSTagChecker extends Test.TagTest { 57 59 60 public static class GroupedMapCSSRule { 61 final public List<Selector> selectors; 62 final public Declaration declaration; 63 64 public GroupedMapCSSRule(List<Selector> selectors, Declaration declaration) { 65 this.selectors = selectors; 66 this.declaration = declaration; 67 } 68 } 58 69 /** 59 70 * The preference key for tag checker source entries. … … 72 83 73 84 static class TagCheck implements Predicate<OsmPrimitive> { 74 protected final MapCSSRule rule; 85 protected final GroupedMapCSSRule rule; 75 86 protected final List<PrimitiveToTag> change = new ArrayList<>(); 76 87 protected final Map<String, String> keyChange = new LinkedHashMap<>(); … … 79 90 protected final Map<String, Boolean> assertions = new HashMap<>(); 80 91 81 TagCheck(MapCSSRule rule) { 92 TagCheck(GroupedMapCSSRule rule) { 82 93 this.rule = rule; 83 94 } … … 120 131 } 121 132 122 static TagCheck ofMapCSSRule(final MapCSSRule rule) { 133 static TagCheck ofMapCSSRule(final GroupedMapCSSRule rule) { 123 134 final TagCheck check = new TagCheck(rule); 124 135 boolean containsSetClassExpression = false; … … 161 172 } 162 173 if (check.errors.isEmpty() && !containsSetClassExpression) { 163 throw new RuntimeException("No throwError/throwWarning/throwOther given! You should specify a validation error message for " + rule.selector); 174 throw new RuntimeException("No throwError/throwWarning/throwOther given! You should specify a validation error message for " + rule.selectors); 164 175 } 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); 176 throw new RuntimeException("More than one throwError/throwWarning/throwOther given! You should specify a single validation error message for " + rule.selectors); 166 177 } 167 178 return check; … … 180 191 // Ignore "meta" rule(s) from external rules of JOSM wiki 181 192 removeMetaRules(source); 182 return new ArrayList<>(Utils.transform(source.rules, new Utils.Function<MapCSSRule, TagCheck>() { 183 @Override 184 public TagCheck apply(MapCSSRule x) { 185 return TagCheck.ofMapCSSRule(x); 186 } 187 })); 193 // group rules with common declaration block 194 MultiMap<MapCSSRule.Declaration, MapCSSRule> rules = new MultiMap<>(); 195 for (MapCSSRule rule : source.rules) { 196 rules.put(rule.declaration, rule); 197 } 198 List<TagCheck> result = new ArrayList<>(); 199 for (Collection<MapCSSRule> rulesCommonDecl : rules.values()) { 200 List<Selector> selectors = new ArrayList<>(); 201 for (MapCSSRule rule : rulesCommonDecl) { 202 selectors.add(rule.selector); 203 } 204 if (!rulesCommonDecl.isEmpty()) { 205 result.add(TagCheck.ofMapCSSRule( 206 new GroupedMapCSSRule(selectors, rulesCommonDecl.iterator().next().declaration))); 207 } 208 } 209 return result; 188 210 } 189 211 … … 211 233 212 234 Selector whichSelectorMatchesEnvironment(Environment env) { 213 env.clearSelectorMatchingInformation(); 214 if (rule.selector.matches(env)) { 215 return rule.selector; 235 for (Selector i : rule.selectors) { 236 env.clearSelectorMatchingInformation(); 237 if (i.matches(env)) { 238 return i; 239 } 216 240 } 217 241 return null; … … 384 408 385 409 static class MapCSSTagCheckerAndRule extends MapCSSTagChecker { 386 public final MapCSSRule rule; 387 388 MapCSSTagCheckerAndRule(MapCSSRule rule) { 410 public final GroupedMapCSSRule rule; 411 412 MapCSSTagCheckerAndRule(GroupedMapCSSRule rule) { 389 413 this.rule = rule; 390 414 } … … 394 418 return super.equals(obj) 395 419 || (obj instanceof TagCheck && rule.equals(((TagCheck) obj).rule)) 396 || (obj instanceof MapCSSRule && rule.equals(obj)); 420 || (obj instanceof GroupedMapCSSRule && rule.equals(obj)); 397 421 } 398 422 } … … 410 434 final Selector selector = check.whichSelectorMatchesEnvironment(env); 411 435 if (selector != null) { 412 check.rule.execute(env); 436 check.rule.declaration.execute(env); 413 437 final TestError error = check.getErrorForPrimitive(p, selector, env); 414 438 if (error != null) { -
TabularUnified trunk/src/org/openstreetmap/josm/gui/mappaint/Range.java ¶
r6986 r7069 8 8 */ 9 9 public class Range { 10 private double lower; 11 private double upper; 10 private final double lower; 11 private final double upper; 12 12 13 13 public static final Range ZERO_TO_INFINITY = new Range(0.0, Double.POSITIVE_INFINITY); -
TabularUnified trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java ¶
r7055 r7069 173 173 return new Tag(k, v); 174 174 } 175 176 @Override 177 public String toString() { 178 return '[' + k + '=' + v + ']'; 179 } 180 175 181 } 176 182 -
TabularUnified trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java ¶
r7014 r7069 11 11 import org.openstreetmap.josm.gui.mappaint.StyleKeys; 12 12 13 public abstract classInstructionimplements StyleKeys {13 public interface Instruction extends StyleKeys { 14 14 15 public abstractvoid execute(Environment env);15 void execute(Environment env); 16 16 17 17 public static class RelativeFloat { … … 28 28 } 29 29 30 public static class AssignmentInstruction extends Instruction {30 public static class AssignmentInstruction implements Instruction { 31 31 public final String key; 32 32 public final Object val; -
TabularUnified trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSRule.java ¶
r7064 r7069 21 21 this.idx = idx; 22 22 } 23 24 /** 25 * <p>Executes the instructions against the environment {@code env}</p> 26 * 27 * @param env the environment 28 */ 29 public void execute(Environment env) { 30 for (Instruction i : instructions) { 31 i.execute(env); 32 } 33 } 23 34 } 24 35 … … 34 45 */ 35 46 public void execute(Environment env) { 36 for (Instruction i : declaration.instructions) { 37 i.execute(env); 38 } 47 declaration.execute(env); 39 48 } 40 49
Note:
See TracChangeset
for help on using the changeset viewer.