Index: trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerIndex.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerIndex.java	(revision 15985)
+++ trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerIndex.java	(revision 15986)
@@ -84,11 +84,5 @@
 
             for (Selector s : c.rule.selectors) {
-                // find the rightmost selector, this must be a GeneralSelector
-                boolean hasLeftRightSel = false;
-                Selector selRightmost = s;
-                while (selRightmost instanceof Selector.ChildOrParentSelector) {
-                    hasLeftRightSel = true;
-                    selRightmost = ((Selector.ChildOrParentSelector) selRightmost).right;
-                }
+                boolean hasLeftRightSel = s instanceof Selector.ChildOrParentSelector;
                 if (!allTests && !hasLeftRightSel) {
                     continue;
@@ -98,5 +92,5 @@
 
                 ruleToCheckMap.put(optRule, c);
-                final String base = ((GeneralSelector) selRightmost).getBase();
+                final String base = s.getBase();
                 switch (base) {
                 case Selector.BASE_NODE:
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java	(revision 15985)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java	(revision 15986)
@@ -17,4 +17,5 @@
 import java.util.ArrayList;
 import java.util.BitSet;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -26,4 +27,5 @@
 import java.util.Map.Entry;
 import java.util.NoSuchElementException;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.locks.ReadWriteLock;
@@ -56,7 +58,5 @@
 import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyValueCondition;
 import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.SimpleKeyValueCondition;
-import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector;
 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector;
-import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.OptimizedGeneralSelector;
 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser;
 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
@@ -292,21 +292,15 @@
             for (int ruleIndex = 0; ruleIndex < rules.size(); ruleIndex++) {
                 MapCSSRule r = rules.get(ruleIndex);
-                // find the rightmost selector, this must be a GeneralSelector
-                Selector selRightmost = r.selector;
-                while (selRightmost instanceof ChildOrParentSelector) {
-                    selRightmost = ((ChildOrParentSelector) selRightmost).right;
-                }
-                OptimizedGeneralSelector s = (OptimizedGeneralSelector) selRightmost;
-                if (s.conds == null) {
+                final List<Condition> conditions = r.selector.getConditions();
+                if (conditions == null || conditions.isEmpty()) {
                     remaining.set(ruleIndex);
                     continue;
                 }
-                List<SimpleKeyValueCondition> sk = new ArrayList<>(Utils.filteredCollection(s.conds,
-                        SimpleKeyValueCondition.class));
-                if (!sk.isEmpty()) {
-                    SimpleKeyValueCondition c = sk.get(sk.size() - 1);
-                    getEntryInIndex(c.k).addForKeyAndValue(c.v, ruleIndex);
+                Optional<SimpleKeyValueCondition> lastCondition = Utils.filteredCollection(conditions, SimpleKeyValueCondition.class).stream()
+                        .reduce((first, last) -> last);
+                if (lastCondition.isPresent()) {
+                    getEntryInIndex(lastCondition.get().k).addForKeyAndValue(lastCondition.get().v, ruleIndex);
                 } else {
-                    String key = findAnyRequiredKey(s.conds);
+                    String key = findAnyRequiredKey(conditions);
                     if (key != null) {
                         getEntryInIndex(key).addForKey(ruleIndex);
@@ -468,11 +462,6 @@
             // optimization: filter rules for different primitive types
             for (MapCSSRule r: rules) {
-                // find the rightmost selector, this must be a GeneralSelector
-                Selector selRightmost = r.selector;
-                while (selRightmost instanceof ChildOrParentSelector) {
-                    selRightmost = ((ChildOrParentSelector) selRightmost).right;
-                }
                 MapCSSRule optRule = new MapCSSRule(r.selector.optimizedBaseCheck(), r.declaration);
-                final String base = ((GeneralSelector) selRightmost).getBase();
+                final String base = r.selector.getBase();
                 switch (base) {
                     case Selector.BASE_NODE:
@@ -758,13 +747,5 @@
      */
     public void removeMetaRules() {
-        for (Iterator<MapCSSRule> it = rules.iterator(); it.hasNext();) {
-            MapCSSRule x = it.next();
-            if (x.selector instanceof GeneralSelector) {
-                GeneralSelector gs = (GeneralSelector) x.selector;
-                if (Selector.BASE_META.equals(gs.base)) {
-                    it.remove();
-                }
-            }
-        }
+        rules.removeIf(x -> x.selector instanceof GeneralSelector && Selector.BASE_META.equals(x.selector.getBase()));
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java	(revision 15985)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java	(revision 15986)
@@ -112,4 +112,6 @@
     Range getRange();
 
+    String getBase();
+
     /**
      * Create an "optimized" copy of this selector that omits the base check.
@@ -177,4 +179,10 @@
             this.right = b;
             this.type = type;
+        }
+
+        @Override
+        public String getBase() {
+            // take the base from the rightmost selector
+            return right.getBase();
         }
 
@@ -678,11 +686,16 @@
 
         @Override
+        public String getBase() {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
         public Subpart getSubpart() {
-            throw new UnsupportedOperationException("Not supported yet.");
+            throw new UnsupportedOperationException();
         }
 
         @Override
         public Range getRange() {
-            throw new UnsupportedOperationException("Not supported yet.");
+            throw new UnsupportedOperationException();
         }
 
@@ -774,4 +787,5 @@
         }
 
+        @Override
         public String getBase() {
             return base;
