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:
|
215 | 215 | | < FULLSTOP: "." > |
216 | 216 | | < DEG: "°" > |
217 | 217 | | < ELEMENT_OF: "∈" > |
| 218 | | < NOT_ELEMENT_OF: "∉" > |
218 | 219 | | < CROSSING: "⧉" > |
219 | 220 | | < PERCENT: "%" > |
220 | 221 | | < COMMENT_START: "/*" > : COMMENT |
… |
… |
Selector child_selector() :
|
690 | 691 | | |
691 | 692 | <ELEMENT_OF> { type = Selector.ChildOrParentSelectorType.ELEMENT_OF; } |
692 | 693 | | |
| 694 | <NOT_ELEMENT_OF> { type = Selector.ChildOrParentSelectorType.NOT_ELEMENT_OF; } |
| 695 | | |
693 | 696 | <CROSSING> { type = Selector.ChildOrParentSelectorType.CROSSING; } |
694 | 697 | ) |
695 | 698 | w() |
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 {
|
93 | 93 | * @see ChildOrParentSelector |
94 | 94 | */ |
95 | 95 | enum ChildOrParentSelectorType { |
96 | | CHILD, PARENT, ELEMENT_OF, CROSSING, SIBLING |
| 96 | CHILD, PARENT, ELEMENT_OF, NOT_ELEMENT_OF, CROSSING, SIBLING |
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
… |
… |
public interface Selector {
|
312 | 312 | |
313 | 313 | @Override |
314 | 314 | 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 | } |
315 | 338 | |
316 | 339 | if (!right.matches(e)) |
317 | 340 | return false; |
318 | 341 | |
319 | 342 | if (ChildOrParentSelectorType.ELEMENT_OF == type) { |
320 | | |
| 343 | /* |
321 | 344 | if (e.osm instanceof INode || e.osm.getDataSet() == null) { |
322 | 345 | // nodes cannot contain elements |
323 | 346 | return false; |
… |
… |
public interface Selector {
|
362 | 385 | } |
363 | 386 | |
364 | 387 | return e.child != null; |
365 | | |
| 388 | */ |
366 | 389 | } else if (ChildOrParentSelectorType.CROSSING == type && e.osm instanceof IWay) { |
367 | 390 | e.parent = e.osm; |
368 | 391 | final CrossingFinder crossingFinder = new CrossingFinder(e); |