Ticket #10391: 0001-Add-support-for-not-element-of-operator.patch

File 0001-Add-support-for-not-element-of-operator.patch, 4.0 KB (added by qeef, 6 years ago)

Add support for "not element of" operator (∉)

  • src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    From 0146231166e7dee8f85f072eb576b29dfce3cbe6 Mon Sep 17 00:00:00 2001
    From: Jiri Hubacek <jiri.hubacek@gmail.com>
    Date: Sat, 8 Sep 2018 14:58:46 +0200
    Subject: [PATCH 1/2] =?UTF-8?q?Add=20support=20for=20"not=20element=20of"?=
     =?UTF-8?q?=20operator=20(=E2=88=89)?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    This patch changes the `matches` method of `ChildOrParentSelector` in a
    such way that `ELEMENT_OF` and `NOT_ELEMENT_OF` operators iterate over
    the *left* selector.
    ---
     .../josm/gui/mappaint/mapcss/MapCSSParser.jj       |  3 +++
     .../josm/gui/mappaint/mapcss/Selector.java         | 29 +++++++++++++++++++---
     2 files changed, 29 insertions(+), 3 deletions(-)
    
    diff --git src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
    index 258bfe79e..c6241391b 100644
    TOKEN:  
    215215|   < FULLSTOP: "." >
    216216|   < DEG: "°" >
    217217|   < ELEMENT_OF: "∈" >
     218|   < NOT_ELEMENT_OF: "∉" >
    218219|   < CROSSING: "⧉" >
    219220|   < PERCENT: "%" >
    220221|   < COMMENT_START: "/*" > : COMMENT
    Selector child_selector() :  
    690691            |
    691692                <ELEMENT_OF> { type = Selector.ChildOrParentSelectorType.ELEMENT_OF; }
    692693            |
     694                <NOT_ELEMENT_OF> { type = Selector.ChildOrParentSelectorType.NOT_ELEMENT_OF; }
     695            |
    693696                <CROSSING> { type = Selector.ChildOrParentSelectorType.CROSSING; }
    694697            )
    695698            w()
  • src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    diff --git src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
    index 30f0007a8..3edcc7d95 100644
    public interface Selector {  
    9393     * @see ChildOrParentSelector
    9494     */
    9595    enum ChildOrParentSelectorType {
    96         CHILD, PARENT, ELEMENT_OF, CROSSING, SIBLING
     96        CHILD, PARENT, ELEMENT_OF, NOT_ELEMENT_OF, CROSSING, SIBLING
    9797    }
    9898
    9999    /**
    public interface Selector {  
    312312
    313313        @Override
    314314        public boolean matches(Environment e) {
     315            if (ChildOrParentSelectorType.ELEMENT_OF == type ||
     316                    ChildOrParentSelectorType.NOT_ELEMENT_OF == type) {
     317                if (!left.matches(e))
     318                    return false;
     319                boolean is_element_of = false;
     320                // Does exist any element in dataset that contains e.osm?
     321                for (IPrimitive p: e.osm.getDataSet().allPrimitives()) {
     322                    Environment ne = new Environment(p);
     323                    if (!right.matches(ne))
     324                        continue;
     325                    ContainsFinder cf = new ContainsFinder(ne);
     326                    if (e.osm instanceof IWay)
     327                        cf.visit((IWay) e.osm);
     328                    if (e.osm instanceof INode)
     329                        cf.visit((INode) e.osm);
     330                    if (ne.child == e.osm)
     331                        is_element_of = true;
     332                }
     333                if (ChildOrParentSelectorType.ELEMENT_OF == type)
     334                    return is_element_of;
     335                else
     336                    return !is_element_of;
     337            }
    315338
    316339            if (!right.matches(e))
    317340                return false;
    318341
    319342            if (ChildOrParentSelectorType.ELEMENT_OF == type) {
    320 
     343/*
    321344                if (e.osm instanceof INode || e.osm.getDataSet() == null) {
    322345                    // nodes cannot contain elements
    323346                    return false;
    public interface Selector {  
    362385                }
    363386
    364387                return e.child != null;
    365 
     388*/
    366389            } else if (ChildOrParentSelectorType.CROSSING == type && e.osm instanceof IWay) {
    367390                e.parent = e.osm;
    368391                final CrossingFinder crossingFinder = new CrossingFinder(e);