Ticket #17845: 17845_varargs.patch
| File 17845_varargs.patch, 3.0 KB (added by , 7 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
572 572 } 573 573 574 574 /** 575 * Returns t rue if role is in relation. Returns false if not a relation or it does not have the role.575 * Returns the number of primitives in a relation with the specified roles. 576 576 * @param env the environment 577 577 * @param roles The roles to count in the relation 578 578 * @return The number of relation members with the specified role … … 1371 1371 convertedArgs = new Object[args.size()+1]; 1372 1372 convertedArgs[0] = env; 1373 1373 for (int i = 1; i < convertedArgs.length; ++i) { 1374 convertedArgs[i] = Cascade.convertTo(args.get(i-1).evaluate(env), expectedParameterTypes[i]); 1374 if (!expectedParameterTypes[i].isArray()) { 1375 convertedArgs[i] = Cascade.convertTo(args.get(i-1).evaluate(env), expectedParameterTypes[i]); 1376 } else { 1377 Class<?> clazz = expectedParameterTypes[i].getComponentType(); 1378 Object[] varargs = (Object[]) Array.newInstance(clazz, args.size() - i + 1); 1379 for (int j = 0; j < args.size() - i + 1; ++j) { 1380 varargs[j] = Cascade.convertTo(args.get(j + i - 1).evaluate(env), clazz); 1381 } 1382 convertedArgs[i] = expectedParameterTypes[i].cast(varargs); 1383 break; 1384 } 1375 1385 if (convertedArgs[i] == null && !nullable) { 1376 1386 return null; 1377 1387 } -
test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java
445 445 /* Check with non-relation */ 446 446 e = new Environment(way1, new MultiCascade(), Environment.DEFAULT_LAYER, null); 447 447 assertEquals(0, ExpressionFactory.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)); 457 448 458 } 449 459 450 460 @Test
