- Timestamp:
- 2014-01-03T17:14:36+01:00 (11 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/validator/geometry.mapcss
r6550 r6611 10 10 assertNoMatch: "node bridge=13"; 11 11 } 12 13 /* Building inside building (spatial test) */ 14 *[building!~/no|entrance/][coalesce(tag("layer"),"0") = coalesce(parent_tag("layer"),"0")] ∈ 15 *[building!~/no|entrance/] { 16 throwWarning: tr("Building inside building"); 17 } -
trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java
r6605 r6611 24 24 import org.openstreetmap.josm.data.validation.tests.Addresses; 25 25 import org.openstreetmap.josm.data.validation.tests.BarriersEntrances; 26 import org.openstreetmap.josm.data.validation.tests.BuildingInBuilding;27 26 import org.openstreetmap.josm.data.validation.tests.Coastlines; 28 27 import org.openstreetmap.josm.data.validation.tests.ConditionalKeys; … … 111 110 TurnrestrictionTest.class, // ID 1801 .. 1899 112 111 DuplicateRelation.class, // ID 1901 .. 1999 113 BuildingInBuilding.class, // ID 2001 .. 2099114 112 OverlappingAreas.class, // ID 2201 .. 2299 115 113 WayConnectedToArea.class, // ID 2301 .. 2399 -
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r6610 r6611 116 116 if (i instanceof Instruction.AssignmentInstruction) { 117 117 final Instruction.AssignmentInstruction ai = (Instruction.AssignmentInstruction) i; 118 if (ai.isSetInstruction) { 119 containsSetClassExpression = true; 120 continue; 121 } 118 122 final String val = ai.val instanceof Expression 119 123 ? (String) ((Expression) ai.val).evaluate(new Environment()) … … 141 145 } else if ("assertNoMatch".equals(ai.key) && val != null) { 142 146 check.assertions.put(val, false); 143 } else if (ai.val instanceof Boolean && ((Boolean) ai.val)) {144 containsSetClassExpression = true;145 147 } else { 146 148 throw new RuntimeException("Cannot add instruction " + ai.key + ": " + ai.val + "!"); -
trunk/src/org/openstreetmap/josm/gui/mappaint/Environment.java
r6601 r6611 215 215 index = null; 216 216 } 217 218 public Cascade getCascade(String layer) { 219 return mc == null ? null : mc.getCascade(layer == null ? this.layer : layer); 220 } 217 221 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
r6601 r6611 291 291 @Override 292 292 public boolean applies(Environment env) { 293 return env != null && env. mc != null && env.mc.getCascade(env.layer) != null && not ^ env.mc.getCascade(env.layer).containsKey(id);293 return env != null && env.getCascade(env.layer) != null && not ^ env.getCascade(env.layer).containsKey(id); 294 294 } 295 295 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r6610 r6611 5 5 6 6 import java.awt.Color; 7 import java.lang.annotation.ElementType; 8 import java.lang.annotation.Retention; 9 import java.lang.annotation.RetentionPolicy; 10 import java.lang.annotation.Target; 7 11 import java.lang.reflect.Array; 8 12 import java.lang.reflect.InvocationTargetException; … … 30 34 */ 31 35 public final class ExpressionFactory { 36 37 /** 38 * Marks functions which should be executed also when one or more arguments are null. 39 */ 40 @Target(ElementType.METHOD) 41 @Retention(RetentionPolicy.RUNTIME) 42 static @interface NullableArguments {} 32 43 33 44 private static final List<Method> arrayFunctions; … … 146 157 147 158 /** 159 * Returns the first non-null object. The name originates from the {@code COALESCE} SQL function. 160 * @see Utils#firstNonNull(Object[]) 161 */ 162 @NullableArguments 163 public static Object coalesce(Object... args) { 164 return Utils.firstNonNull(args); 165 } 166 167 /** 148 168 * Get the {@code n}th element of the list {@code lst} (counting starts at 0). 149 169 * @since 5699 … … 221 241 * Assembles the strings to one. 222 242 */ 243 @NullableArguments 223 244 public static String concat(Object... args) { 224 245 StringBuilder res = new StringBuilder(); 225 246 for (Object f : args) { 226 res.append( f.toString());247 res.append(String.valueOf(f)); 227 248 } 228 249 return res.toString(); … … 240 261 */ 241 262 public Object prop(String key, String layer) { 242 Cascade c; 243 if (layer == null) { 244 c = env.mc.getCascade(env.layer); 245 } else { 246 c = env.mc.getCascade(layer); 247 } 248 return c.get(key); 263 return env.getCascade(layer).get(key); 249 264 } 250 265 … … 260 275 */ 261 276 public Boolean is_prop_set(String key, String layer) { 262 Cascade c; 263 if (layer == null) { 264 // env.layer is null if expression is evaluated 265 // in ExpressionCondition, but MultiCascade.getCascade 266 // handles this 267 c = env.mc.getCascade(env.layer); 268 } else { 269 c = env.mc.getCascade(layer); 270 } 271 return c.containsKey(key); 277 return env.getCascade(layer).containsKey(key); 272 278 } 273 279 … … 650 656 for (int i = 0; i < args.size(); ++i) { 651 657 convertedArgs[i] = Cascade.convertTo(args.get(i).evaluate(env), expectedParameterTypes[i]); 652 if (convertedArgs[i] == null ) {658 if (convertedArgs[i] == null && m.getAnnotation(NullableArguments.class) == null) { 653 659 return null; 654 660 } … … 696 702 for (int i = 0; i < args.size(); ++i) { 697 703 Object o = Cascade.convertTo(args.get(i).evaluate(env), arrayComponentType); 698 if (o == null ) {704 if (o == null && m.getAnnotation(NullableArguments.class) == null) { 699 705 return null; 700 706 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java
r6070 r6611 31 31 public final String key; 32 32 public final Object val; 33 public final boolean isSetInstruction; 33 34 34 public AssignmentInstruction(String key, Object val ) {35 public AssignmentInstruction(String key, Object val, boolean isSetInstruction) { 35 36 this.key = key; 37 this.isSetInstruction = isSetInstruction; 36 38 if (val instanceof LiteralExpression) { 37 39 Object litValue = ((LiteralExpression) val).evaluate(null); -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r6609 r6611 472 472 key=<IDENT> w() 473 473 ( <EQUAL> val=expression() )? 474 { ins.add(new Instruction.AssignmentInstruction(key.image, val == null ? true : val )); }474 { ins.add(new Instruction.AssignmentInstruction(key.image, val == null ? true : val, true)); } 475 475 ( <RBRACE> { return ins; } | <SEMICOLON> w() ) 476 476 ) … … 480 480 LOOKAHEAD( float_array() w() ( <SEMICOLON> | <RBRACE> ) ) 481 481 val=float_array() 482 { ins.add(new Instruction.AssignmentInstruction(key.image, val )); }482 { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); } 483 483 w() 484 484 ( <RBRACE> { return ins; } | <SEMICOLON> w() ) … … 486 486 LOOKAHEAD( expression() ( <SEMICOLON> | <RBRACE> ) ) 487 487 val=expression() 488 { ins.add(new Instruction.AssignmentInstruction(key.image, val )); }488 { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); } 489 489 ( <RBRACE> { return ins; } | <SEMICOLON> w() ) 490 490 | 491 val=readRaw() w() { ins.add(new Instruction.AssignmentInstruction(key.image, val )); }491 val=readRaw() w() { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); } 492 492 ) 493 493 )* -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r6609 r6611 160 160 @Override 161 161 public void visit(Node n) { 162 if (e. parent == null && right.matches(e.withPrimitive(n))) {162 if (e.child == null && left.matches(e.withPrimitive(n))) { 163 163 if (e.osm instanceof Way && Geometry.nodeInsidePolygon(n, ((Way) e.osm).getNodes()) 164 164 || e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon() && Geometry.isNodeInsideMultiPolygon(n, (Relation) e.osm, null)) { 165 e. parent= n;165 e.child = n; 166 166 } 167 167 } … … 170 170 @Override 171 171 public void visit(Way w) { 172 if (e. parent == null && right.matches(e.withPrimitive(w))) {172 if (e.child == null && left.matches(e.withPrimitive(w))) { 173 173 if (e.osm instanceof Way && Geometry.PolygonIntersection.FIRST_INSIDE_SECOND.equals(Geometry.polygonIntersection(w.getNodes(), ((Way) e.osm).getNodes())) 174 174 || e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon() && Geometry.isPolygonInsideMultiPolygon(w.getNodes(), (Relation) e.osm, null)) { 175 e. parent= w;175 e.child = w; 176 176 } 177 177 } … … 184 184 public void visit(Collection<? extends OsmPrimitive> primitives) { 185 185 for (OsmPrimitive p : primitives) { 186 if (e. parent!= null) {186 if (e.child != null) { 187 187 // abort if first match has been found 188 188 break; … … 206 206 return false; 207 207 } 208 e. child= e.osm;208 e.parent = e.osm; 209 209 210 210 final ContainsFinder containsFinder = new ContainsFinder(e); … … 221 221 } 222 222 223 return e. parent!= null;223 return e.child != null; 224 224 225 225 } else if (ChildOrParentSelectorType.CHILD.equals(type)) { … … 374 374 375 375 public boolean matchesBase(OsmPrimitiveType type) { 376 if (OsmPrimitiveType.NODE.equals(type)) { 377 return base.equals("node") || base.equals("*"); 376 if (base.equals("*")) { 377 return true; 378 } else if (OsmPrimitiveType.NODE.equals(type)) { 379 return base.equals("node"); 378 380 } else if (OsmPrimitiveType.WAY.equals(type)) { 379 return base.equals("way") || base.equals("area") || base.equals("*");381 return base.equals("way") || base.equals("area"); 380 382 } else if (OsmPrimitiveType.RELATION.equals(type)) { 381 383 return base.equals("area") || base.equals("relation") || base.equals("canvas");
Note:
See TracChangeset
for help on using the changeset viewer.