Ignore:
Timestamp:
2018-12-02T02:32:13+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #17058 - Cannot add assertMatch/assertNoMatch declarations with inside() selector

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/OsmUtils.java

    r14238 r14484  
    113113
    114114    /**
    115      * Creates a new OSM primitive according to the given assertion. Originally written for unit tests,
     115     * Creates a new OSM primitive around (0,0) according to the given assertion. Originally written for unit tests,
    116116     * this can also be used in another places like validation of local MapCSS validator rules.
    117117     * @param assertion The assertion describing OSM primitive (ex: "way name=Foo railway=rail")
     
    121121     */
    122122    public static OsmPrimitive createPrimitive(String assertion) {
     123        return createPrimitive(assertion, LatLon.ZERO);
     124    }
     125
     126    /**
     127     * Creates a new OSM primitive according to the given assertion. Originally written for unit tests,
     128     * this can also be used in another places like validation of local MapCSS validator rules.
     129     * @param assertion The assertion describing OSM primitive (ex: "way name=Foo railway=rail")
     130     * @param around the coordinate at which the primitive will be located
     131     * @return a new OSM primitive according to the given assertion
     132     * @throws IllegalArgumentException if assertion is null or if the primitive type cannot be deduced from it
     133     * @since 14484
     134     */
     135    public static OsmPrimitive createPrimitive(String assertion, LatLon around) {
    123136        CheckParameterUtil.ensureParameterNotNull(assertion, "assertion");
    124137        final String[] x = assertion.split("\\s+", 2);
    125138        final OsmPrimitive p = "n".equals(x[0]) || "node".equals(x[0])
    126                 ? new Node(LatLon.ZERO)
     139                ? new Node(around)
    127140                : "w".equals(x[0]) || "way".equals(x[0]) || /*for MapCSS related usage*/ "area".equals(x[0])
    128                 ? new Way()
     141                ? newWay(around)
    129142                : "r".equals(x[0]) || "relation".equals(x[0])
    130                 ? new Relation()
     143                ? newRelation(around)
    131144                : null;
    132145        if (p == null) {
     
    139152        }
    140153        return p;
     154    }
     155
     156    private static Node newNode(LatLon around) {
     157        return new Node(around);
     158    }
     159
     160    private static Way newWay(LatLon around) {
     161        Way w = new Way();
     162        w.addNode(newNode(new LatLon(around.lat()+0.1, around.lon())));
     163        w.addNode(newNode(new LatLon(around.lat()-0.1, around.lon())));
     164        return w;
     165    }
     166
     167    private static Relation newRelation(LatLon around) {
     168        Relation r = new Relation();
     169        r.addMember(new RelationMember(null, newNode(around)));
     170        return r;
    141171    }
    142172
Note: See TracChangeset for help on using the changeset viewer.