Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r15245 r15275 339 339 Object[] convertedArgs; 340 340 341 int start = 0; 342 int offset = 0; 341 343 if (needsEnvironment) { 342 convertedArgs = new Object[args.size()+1]; 344 start = 1; 345 offset = 1; 346 convertedArgs = new Object[args.size() + 1]; 343 347 convertedArgs[0] = env; 344 for (int i = 1; i < convertedArgs.length; ++i) {345 convertedArgs[i] = Cascade.convertTo(args.get(i-1).evaluate(env), expectedParameterTypes[i]);346 if (convertedArgs[i] == null && !nullable) {347 return null;348 }349 }350 348 } else { 351 349 convertedArgs = new Object[args.size()]; 352 for (int i = 0; i < convertedArgs.length; ++i) { 353 convertedArgs[i] = Cascade.convertTo(args.get(i).evaluate(env), expectedParameterTypes[i]); 354 if (convertedArgs[i] == null && !nullable) { 355 return null; 350 } 351 352 for (int i = start; i < convertedArgs.length; ++i) { 353 if (!expectedParameterTypes[i].isArray()) { 354 convertedArgs[i] = Cascade.convertTo(args.get(i - offset).evaluate(env), expectedParameterTypes[i]); 355 } else { 356 Class<?> clazz = expectedParameterTypes[i].getComponentType(); 357 Object[] varargs = (Object[]) Array.newInstance(clazz, args.size() - i + 1); 358 for (int j = 0; j < args.size() - i + 1; ++j) { 359 varargs[j] = Cascade.convertTo(args.get(j + i - 1).evaluate(env), clazz); 356 360 } 357 } 358 } 361 convertedArgs[i] = expectedParameterTypes[i].cast(varargs); 362 break; 363 } 364 if (convertedArgs[i] == null && !nullable) { 365 return null; 366 } 367 } 368 359 369 Object result = null; 360 370 try { -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
r15246 r15275 505 505 506 506 /** 507 * Returns t rue if role is in relation. Returns false if not a relation or it does not have the role.507 * Returns the number of primitives in a relation with the specified roles. 508 508 * @param env the environment 509 509 * @param roles The roles to count in the relation -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java
r15245 r15275 446 446 e = new Environment(way1, new MultiCascade(), Environment.DEFAULT_LAYER, null); 447 447 assertEquals(0, Functions.count_roles(e, "from", "to")); 448 449 /* Check with actual call to mapcss functions */ 450 MapCSSStyleSource source = new MapCSSStyleSource("relation[type=destination_sign] {roles: count_roles(\"from\");}"); 451 source.loadStyleSource(); 452 assertEquals(1, source.rules.size()); 453 e = new Environment(rel1, new MultiCascade(), Environment.DEFAULT_LAYER, null); 454 assertTrue(source.rules.get(0).selector.matches(e)); 455 source.rules.get(0).declaration.execute(e); 456 assertEquals((Integer) 1, e.getCascade(Environment.DEFAULT_LAYER).get("roles", null, Integer.class)); 448 457 } 449 458
Note:
See TracChangeset
for help on using the changeset viewer.