Ticket #17995: 17995.2.patch

File 17995.2.patch, 6.2 KB (added by taylor.smock, 5 years ago)

Add missing @since xxx

  • src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

     
    338338        public Object evaluate(Environment env) {
    339339            Object[] convertedArgs;
    340340
     341            int start = 0;
     342            int offset = 0;
    341343            if (needsEnvironment) {
    342                 convertedArgs = new Object[args.size()+1];
     344                start = 1;
     345                offset = 1;
     346                convertedArgs = new Object[args.size() + 1];
    343347                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                 }
    350348            } else {
    351349                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);
    356360                    }
     361                    convertedArgs[i] = expectedParameterTypes[i].cast(varargs);
     362                    break;
    357363                }
     364                if (convertedArgs[i] == null && !nullable) {
     365                    return null;
     366                }
    358367            }
     368
    359369            Object result = null;
    360370            try {
    361371                result = m.invoke(null, convertedArgs);
  • src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java

     
    494494    }
    495495
    496496    /**
     497     * Sort an array of strings
     498     * @param sortables The array to sort
     499     * @return The sorted array
     500     * @since xxx
     501     */
     502    public static List<String> sort(String... sortables) {
     503        Logging.setLogLevel(Logging.LEVEL_DEBUG);
     504        Logging.debug("Sorting");
     505        Arrays.parallelSort(sortables);
     506        Logging.debug("{}", (Object[]) sortables);
     507        return Arrays.asList(sortables);
     508    }
     509
     510    /**
    497511     * Returns the role of current object in parent relation, or role of child if current object is a relation.
    498512     * @param env the environment
    499513     * @return role of current object in parent relation, or role of child if current object is a relation
     
    504518    }
    505519
    506520    /**
    507      * Returns true if role is in relation. Returns false if not a relation or it does not have the role.
     521     * Returns the number of primitives in a relation with the specified roles.
    508522     * @param env the environment
    509523     * @param roles The roles to count in the relation
    510524     * @return The number of relation members with the specified role
  • test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java

     
    99
    1010import java.awt.Color;
    1111import java.io.StringReader;
     12import java.util.Arrays;
    1213import java.util.List;
    1314
    1415import org.junit.Rule;
     
    407408    }
    408409
    409410    @Test
     411    public void testSort() throws Exception {
     412        assertEquals(Arrays.asList(new String[] {"alpha", "beta"}), Functions.sort("beta", "alpha"));
     413        Way way1 = TestUtils.newWay("highway=residential name=Alpha alt_name=Beta", new Node(new LatLon(0.001, 0.001)),
     414                new Node(new LatLon(0.002, 0.002)));
     415
     416        MapCSSStyleSource source = new MapCSSStyleSource("way[highway] {sorted: join_list(\",\", sort(tag(\"alt_name\"), tag(\"name\")));}");
     417        source.loadStyleSource();
     418        assertEquals(1, source.rules.size());
     419        Environment e = new Environment(way1, new MultiCascade(), Environment.DEFAULT_LAYER, null);
     420        assertTrue(source.rules.get(0).selector.matches(e));
     421        source.rules.get(0).declaration.execute(e);
     422        assertEquals(Functions.join(",", "Alpha", "Beta"), e.getCascade(Environment.DEFAULT_LAYER).get("sorted", null, String.class));
     423    }
     424
     425    @Test
    410426    public void testCountRoles() throws Exception {
    411427        DataSet ds = new DataSet();
    412428        Way way1 = TestUtils.newWay("highway=residential name=1",
     
    445461        /* Check with non-relation */
    446462        e = new Environment(way1, new MultiCascade(), Environment.DEFAULT_LAYER, null);
    447463        assertEquals(0, Functions.count_roles(e, "from", "to"));
     464
     465        /* Check with actual call to mapcss functions */
     466        MapCSSStyleSource source = new MapCSSStyleSource("relation[type=destination_sign] {roles: count_roles(\"from\");}");
     467        source.loadStyleSource();
     468        assertEquals(1, source.rules.size());
     469        e = new Environment(rel1, new MultiCascade(), Environment.DEFAULT_LAYER, null);
     470        assertTrue(source.rules.get(0).selector.matches(e));
     471        source.rules.get(0).declaration.execute(e);
     472        assertEquals((Integer) 1, e.getCascade(Environment.DEFAULT_LAYER).get("roles", null, Integer.class));
    448473    }
    449474
    450475    @Test