Index: /trunk/scripts/TagInfoExtract.groovy
===================================================================
--- /trunk/scripts/TagInfoExtract.groovy	(revision 10836)
+++ /trunk/scripts/TagInfoExtract.groovy	(revision 10837)
@@ -32,5 +32,5 @@
 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference
 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource
-import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.SimpleKeyValueCondition
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.SimpleKeyValueCondition
 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector
 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser
Index: /trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java	(revision 10836)
+++ /trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java	(revision 10837)
@@ -48,5 +48,5 @@
 import org.openstreetmap.josm.gui.mappaint.MultiCascade;
 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition;
-import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.ClassCondition;
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.ClassCondition;
 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression;
 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java	(revision 10836)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java	(revision 10837)
@@ -2,31 +2,7 @@
 package org.openstreetmap.josm.gui.mappaint.mapcss;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.text.MessageFormat;
-import java.util.Arrays;
-import java.util.EnumSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.function.BiFunction;
-import java.util.function.IntFunction;
-import java.util.function.Predicate;
-import java.util.regex.Pattern;
-
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.actions.search.SearchCompiler.InDataSourceArea;
-import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.OsmUtils;
-import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.data.osm.Tag;
-import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
-import org.openstreetmap.josm.gui.mappaint.Cascade;
-import org.openstreetmap.josm.gui.mappaint.ElemStyles;
 import org.openstreetmap.josm.gui.mappaint.Environment;
-import org.openstreetmap.josm.tools.CheckParameterUtil;
-import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -42,191 +18,4 @@
      */
     boolean applies(Environment e);
-
-    /**
-     * Create a new condition that checks the key and the value of the object.
-     * @param k The key.
-     * @param v The reference value
-     * @param op The operation to use when comparing the value
-     * @param context The type of context to use.
-     * @param considerValAsKey whether to consider {@code v} as another key and compare the values of key {@code k} and key {@code v}.
-     * @return The new condition.
-     */
-    static Condition createKeyValueCondition(String k, String v, Op op, Context context, boolean considerValAsKey) {
-        switch (context) {
-        case PRIMITIVE:
-            if (KeyValueRegexpCondition.SUPPORTED_OPS.contains(op) && !considerValAsKey)
-                return new KeyValueRegexpCondition(k, v, op, false);
-            if (!considerValAsKey && op.equals(Op.EQ))
-                return new SimpleKeyValueCondition(k, v);
-            return new KeyValueCondition(k, v, op, considerValAsKey);
-        case LINK:
-            if (considerValAsKey)
-                throw new MapCSSException("''considerValAsKey'' not supported in LINK context");
-            if ("role".equalsIgnoreCase(k))
-                return new RoleCondition(v, op);
-            else if ("index".equalsIgnoreCase(k))
-                return new IndexCondition(v, op);
-            else
-                throw new MapCSSException(
-                        MessageFormat.format("Expected key ''role'' or ''index'' in link context. Got ''{0}''.", k));
-
-        default: throw new AssertionError();
-        }
-    }
-
-    /**
-     * Create a condition in which the key and the value need to match a given regexp
-     * @param k The key regexp
-     * @param v The value regexp
-     * @param op The operation to use when comparing the key and the value.
-     * @return The new condition.
-     */
-    static Condition createRegexpKeyRegexpValueCondition(String k, String v, Op op) {
-        return new RegexpKeyValueRegexpCondition(k, v, op);
-    }
-
-    /**
-     * Creates a condition that checks the given key.
-     * @param k The key to test for
-     * @param not <code>true</code> to invert the match
-     * @param matchType The match type to check for.
-     * @param context The context this rule is found in.
-     * @return the new condition.
-     */
-    static Condition createKeyCondition(String k, boolean not, KeyMatchType matchType, Context context) {
-        switch (context) {
-        case PRIMITIVE:
-            return new KeyCondition(k, not, matchType);
-        case LINK:
-            if (matchType != null)
-                throw new MapCSSException("Question mark operator ''?'' and regexp match not supported in LINK context");
-            if (not)
-                return new RoleCondition(k, Op.NEQ);
-            else
-                return new RoleCondition(k, Op.EQ);
-
-        default: throw new AssertionError();
-        }
-    }
-
-    /**
-     * Create a new pseudo class condition
-     * @param id The id of the pseudo class
-     * @param not <code>true</code> to invert the condition
-     * @param context The context the class is found in.
-     * @return The new condition
-     */
-    static PseudoClassCondition createPseudoClassCondition(String id, boolean not, Context context) {
-        return PseudoClassCondition.createPseudoClassCondition(id, not, context);
-    }
-
-    /**
-     * Create a new class condition
-     * @param id The id of the class to match
-     * @param not <code>true</code> to invert the condition
-     * @param context Ignored
-     * @return The new condition
-     */
-    static ClassCondition createClassCondition(String id, boolean not, Context context) {
-        return new ClassCondition(id, not);
-    }
-
-    /**
-     * Create a new condition that a expression needs to be fulfilled
-     * @param e the expression to check
-     * @param context Ignored
-     * @return The new condition
-     */
-    static ExpressionCondition createExpressionCondition(Expression e, Context context) {
-        return new ExpressionCondition(e);
-    }
-
-    /**
-     * This is the operation that {@link KeyValueCondition} uses to match.
-     */
-    enum Op {
-        /** The value equals the given reference. */
-        EQ(Objects::equals),
-        /** The value does not equal the reference. */
-        NEQ(EQ),
-        /** The value is greater than or equal to the given reference value (as float). */
-        GREATER_OR_EQUAL(comparisonResult -> comparisonResult >= 0),
-        /** The value is greater than the given reference value (as float). */
-        GREATER(comparisonResult -> comparisonResult > 0),
-        /** The value is less than or equal to the given reference value (as float). */
-        LESS_OR_EQUAL(comparisonResult -> comparisonResult <= 0),
-        /** The value is less than the given reference value (as float). */
-        LESS(comparisonResult -> comparisonResult < 0),
-        /** The reference is treated as regular expression and the value needs to match it. */
-        REGEX((test, prototype) -> Pattern.compile(prototype).matcher(test).find()),
-        /** The reference is treated as regular expression and the value needs to not match it. */
-        NREGEX(REGEX),
-        /** The reference is treated as a list separated by ';'. Spaces around the ; are ignored.
-         *  The value needs to be equal one of the list elements. */
-        ONE_OF((test, prototype) -> Arrays.asList(test.split("\\s*;\\s*")).contains(prototype)),
-        /** The value needs to begin with the reference string. */
-        BEGINS_WITH(String::startsWith),
-        /** The value needs to end with the reference string. */
-        ENDS_WITH(String::endsWith),
-        /** The value needs to contain the reference string. */
-        CONTAINS(String::contains);
-
-        static final Set<Op> NEGATED_OPS = EnumSet.of(NEQ, NREGEX);
-
-        private final BiFunction<String, String, Boolean> function;
-
-        private final boolean negated;
-
-        /**
-         * Create a new string operation.
-         * @param func The function to apply during {@link #eval(String, String)}.
-         */
-        Op(BiFunction<String, String, Boolean> func) {
-            this.function = func;
-            negated = false;
-        }
-
-        /**
-         * Create a new float operation that compares two float values
-         * @param comparatorResult A function to mapt the result of the comparison
-         */
-        Op(IntFunction<Boolean> comparatorResult) {
-            this.function = (test, prototype) -> {
-                float testFloat;
-                try {
-                    testFloat = Float.parseFloat(test);
-                } catch (NumberFormatException e) {
-                    return false;
-                }
-                float prototypeFloat = Float.parseFloat(prototype);
-
-                int res = Float.compare(testFloat, prototypeFloat);
-                return comparatorResult.apply(res);
-            };
-            negated = false;
-        }
-
-        /**
-         * Create a new Op by negating an other op.
-         * @param negate inverse operation
-         */
-        Op(Op negate) {
-            this.function = (a, b) -> !negate.function.apply(a, b);
-            negated = true;
-        }
-
-        /**
-         * Evaluates a value against a reference string.
-         * @param testString The value. May be <code>null</code>
-         * @param prototypeString The reference string-
-         * @return <code>true</code> if and only if this operation matches for the given value/reference pair.
-         */
-        public boolean eval(String testString, String prototypeString) {
-            if (testString == null)
-                return negated;
-            else
-                return function.apply(testString, prototypeString);
-        }
-    }
 
     /**
@@ -246,611 +35,9 @@
 
     /**
-     * Most common case of a KeyValueCondition, this is the basic key=value case.
-     *
-     * Extra class for performance reasons.
-     */
-    class SimpleKeyValueCondition implements Condition, ToTagConvertable {
-        /**
-         * The key to search for.
-         */
-        public final String k;
-        /**
-         * The value to search for.
-         */
-        public final String v;
-
-        /**
-         * Create a new SimpleKeyValueCondition.
-         * @param k The key
-         * @param v The value.
-         */
-        public SimpleKeyValueCondition(String k, String v) {
-            this.k = k;
-            this.v = v;
-        }
-
-        @Override
-        public boolean applies(Environment e) {
-            return v.equals(e.osm.get(k));
-        }
-
-        @Override
-        public Tag asTag(OsmPrimitive primitive) {
-            return new Tag(k, v);
-        }
-
-        @Override
-        public String toString() {
-            return '[' + k + '=' + v + ']';
-        }
-
-    }
-
-    /**
-     * <p>Represents a key/value condition which is either applied to a primitive.</p>
-     *
-     */
-    class KeyValueCondition implements Condition, ToTagConvertable {
-        /**
-         * The key to search for.
-         */
-        public final String k;
-        /**
-         * The value to search for.
-         */
-        public final String v;
-        /**
-         * The key/value match operation.
-         */
-        public final Op op;
-        /**
-         * If this flag is set, {@link #v} is treated as a key and the value is the value set for that key.
-         */
-        public final boolean considerValAsKey;
-
-        /**
-         * <p>Creates a key/value-condition.</p>
-         *
-         * @param k the key
-         * @param v the value
-         * @param op the operation
-         * @param considerValAsKey whether to consider {@code v} as another key and compare the values of key {@code k} and key {@code v}.
-         */
-        public KeyValueCondition(String k, String v, Op op, boolean considerValAsKey) {
-            this.k = k;
-            this.v = v;
-            this.op = op;
-            this.considerValAsKey = considerValAsKey;
-        }
-
-        @Override
-        public boolean applies(Environment env) {
-            return op.eval(env.osm.get(k), considerValAsKey ? env.osm.get(v) : v);
-        }
-
-        @Override
-        public Tag asTag(OsmPrimitive primitive) {
-            return new Tag(k, v);
-        }
-
-        @Override
-        public String toString() {
-            return '[' + k + '\'' + op + '\'' + v + ']';
-        }
-    }
-
-    /**
-     * This condition requires a fixed key to match a given regexp
-     */
-    class KeyValueRegexpCondition extends KeyValueCondition {
-        protected static final Set<Op> SUPPORTED_OPS = EnumSet.of(Op.REGEX, Op.NREGEX);
-
-        final Pattern pattern;
-
-        public KeyValueRegexpCondition(String k, String v, Op op, boolean considerValAsKey) {
-            super(k, v, op, considerValAsKey);
-            CheckParameterUtil.ensureThat(!considerValAsKey, "considerValAsKey is not supported");
-            CheckParameterUtil.ensureThat(SUPPORTED_OPS.contains(op), "Op must be REGEX or NREGEX");
-            this.pattern = Pattern.compile(v);
-        }
-
-        protected boolean matches(Environment env) {
-            final String value = env.osm.get(k);
-            return value != null && pattern.matcher(value).find();
-        }
-
-        @Override
-        public boolean applies(Environment env) {
-            if (Op.REGEX.equals(op)) {
-                return matches(env);
-            } else if (Op.NREGEX.equals(op)) {
-                return !matches(env);
-            } else {
-                throw new IllegalStateException();
-            }
-        }
-    }
-
-    /**
-     * A condition that checks that a key with the matching pattern has a value with the matching pattern.
-     */
-    class RegexpKeyValueRegexpCondition extends KeyValueRegexpCondition {
-
-        public final Pattern keyPattern;
-
-        /**
-         * Create a condition in which the key and the value need to match a given regexp
-         * @param k The key regexp
-         * @param v The value regexp
-         * @param op The operation to use when comparing the key and the value.
-         */
-        public RegexpKeyValueRegexpCondition(String k, String v, Op op) {
-            super(k, v, op, false);
-            this.keyPattern = Pattern.compile(k);
-        }
-
-        @Override
-        protected boolean matches(Environment env) {
-            for (Map.Entry<String, String> kv: env.osm.getKeys().entrySet()) {
-                if (keyPattern.matcher(kv.getKey()).find() && pattern.matcher(kv.getValue()).find()) {
-                    return true;
-                }
-            }
-            return false;
-        }
-    }
-
-    class RoleCondition implements Condition {
-        public final String role;
-        public final Op op;
-
-        public RoleCondition(String role, Op op) {
-            this.role = role;
-            this.op = op;
-        }
-
-        @Override
-        public boolean applies(Environment env) {
-            String testRole = env.getRole();
-            if (testRole == null) return false;
-            return op.eval(testRole, role);
-        }
-    }
-
-    class IndexCondition implements Condition {
-        public final String index;
-        public final Op op;
-
-        public IndexCondition(String index, Op op) {
-            this.index = index;
-            this.op = op;
-        }
-
-        @Override
-        public boolean applies(Environment env) {
-            if (env.index == null) return false;
-            if (index.startsWith("-")) {
-                return env.count != null && op.eval(Integer.toString(env.index - env.count), index);
-            } else {
-                return op.eval(Integer.toString(env.index + 1), index);
-            }
-        }
-    }
-
-    /**
-     * This defines how {@link KeyCondition} matches a given key.
-     */
-    enum KeyMatchType {
-        /**
-         * The key needs to be equal to the given label.
-         */
-        EQ,
-        /**
-         * The key needs to have a true value (yes, ...)
-         * @see OsmUtils#isTrue(String)
-         */
-        TRUE,
-        /**
-         * The key needs to have a false value (no, ...)
-         * @see OsmUtils#isFalse(String)
-         */
-        FALSE,
-        /**
-         * The key needs to match the given regular expression.
-         */
-        REGEX
-    }
-
-    /**
-     * <p>KeyCondition represent one of the following conditions in either the link or the
-     * primitive context:</p>
-     * <pre>
-     *     ["a label"]  PRIMITIVE:   the primitive has a tag "a label"
-     *                  LINK:        the parent is a relation and it has at least one member with the role
-     *                               "a label" referring to the child
-     *
-     *     [!"a label"]  PRIMITIVE:  the primitive doesn't have a tag "a label"
-     *                   LINK:       the parent is a relation but doesn't have a member with the role
-     *                               "a label" referring to the child
-     *
-     *     ["a label"?]  PRIMITIVE:  the primitive has a tag "a label" whose value evaluates to a true-value
-     *                   LINK:       not supported
-     *
-     *     ["a label"?!] PRIMITIVE:  the primitive has a tag "a label" whose value evaluates to a false-value
-     *                   LINK:       not supported
-     * </pre>
-     */
-    class KeyCondition implements Condition, ToTagConvertable {
-
-        /**
-         * The key name.
-         */
-        public final String label;
-        /**
-         * If we should negate the result of the match.
-         */
-        public final boolean negateResult;
-        /**
-         * Describes how to match the label against the key.
-         * @see KeyMatchType
-         */
-        public final KeyMatchType matchType;
-        /**
-         * A predicate used to match a the regexp against the key. Only used if the match type is regexp.
-         */
-        public final Predicate<String> containsPattern;
-
-        /**
-         * Creates a new KeyCondition
-         * @param label The key name (or regexp) to use.
-         * @param negateResult If we should negate the result.,
-         * @param matchType The match type.
-         */
-        public KeyCondition(String label, boolean negateResult, KeyMatchType matchType) {
-            this.label = label;
-            this.negateResult = negateResult;
-            this.matchType = matchType == null ? KeyMatchType.EQ : matchType;
-            this.containsPattern = KeyMatchType.REGEX.equals(matchType)
-                    ? Pattern.compile(label).asPredicate()
-                    : null;
-        }
-
-        @Override
-        public boolean applies(Environment e) {
-            switch(e.getContext()) {
-            case PRIMITIVE:
-                switch (matchType) {
-                case TRUE:
-                    return e.osm.isKeyTrue(label) ^ negateResult;
-                case FALSE:
-                    return e.osm.isKeyFalse(label) ^ negateResult;
-                case REGEX:
-                    return e.osm.keySet().stream().anyMatch(containsPattern) ^ negateResult;
-                default:
-                    return e.osm.hasKey(label) ^ negateResult;
-                }
-            case LINK:
-                Utils.ensure(false, "Illegal state: KeyCondition not supported in LINK context");
-                return false;
-            default: throw new AssertionError();
-            }
-        }
-
-        /**
-         * Get the matched key and the corresponding value.
-         * <p>
-         * WARNING: This ignores {@link #negateResult}.
-         * <p>
-         * WARNING: For regexp, the regular expression is returned instead of a key if the match failed.
-         * @param p The primitive to get the value from.
-         * @return The tag.
-         */
-        @Override
-        public Tag asTag(OsmPrimitive p) {
-            String key = label;
-            if (KeyMatchType.REGEX.equals(matchType)) {
-                key = p.keySet().stream().filter(containsPattern).findAny().orElse(key);
-            }
-            return new Tag(key, p.get(key));
-        }
-
-        @Override
-        public String toString() {
-            return '[' + (negateResult ? "!" : "") + label + ']';
-        }
-    }
-
-    class ClassCondition implements Condition {
-
-        public final String id;
-        public final boolean not;
-
-        public ClassCondition(String id, boolean not) {
-            this.id = id;
-            this.not = not;
-        }
-
-        @Override
-        public boolean applies(Environment env) {
-            Cascade cascade = env.getCascade(env.layer);
-            return cascade != null && (not ^ cascade.containsKey(id));
-        }
-
-        @Override
-        public String toString() {
-            return (not ? "!" : "") + '.' + id;
-        }
-    }
-
-    /**
-     * Like <a href="http://www.w3.org/TR/css3-selectors/#pseudo-classes">CSS pseudo classes</a>, MapCSS pseudo classes
-     * are written in lower case with dashes between words.
-     */
-    final class PseudoClasses {
-
-        private PseudoClasses() {
-            // Hide default constructor for utilities classes
-        }
-
-        /**
-         * {@code closed} tests whether the way is closed or the relation is a closed multipolygon
-         * @param e MapCSS environment
-         * @return {@code true} if the way is closed or the relation is a closed multipolygon
-         */
-        static boolean closed(Environment e) { // NO_UCD (unused code)
-            if (e.osm instanceof Way && ((Way) e.osm).isClosed())
-                return true;
-            if (e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon())
-                return true;
-            return false;
-        }
-
-        /**
-         * {@code :modified} tests whether the object has been modified.
-         * @param e MapCSS environment
-         * @return {@code true} if the object has been modified
-         * @see OsmPrimitive#isModified()
-         */
-        static boolean modified(Environment e) { // NO_UCD (unused code)
-            return e.osm.isModified() || e.osm.isNewOrUndeleted();
-        }
-
-        /**
-         * {@code ;new} tests whether the object is new.
-         * @param e MapCSS environment
-         * @return {@code true} if the object is new
-         * @see OsmPrimitive#isNew()
-         */
-        static boolean _new(Environment e) { // NO_UCD (unused code)
-            return e.osm.isNew();
-        }
-
-        /**
-         * {@code :connection} tests whether the object is a connection node.
-         * @param e MapCSS environment
-         * @return {@code true} if the object is a connection node
-         * @see Node#isConnectionNode()
-         */
-        static boolean connection(Environment e) { // NO_UCD (unused code)
-            return e.osm instanceof Node && e.osm.getDataSet() != null && ((Node) e.osm).isConnectionNode();
-        }
-
-        /**
-         * {@code :tagged} tests whether the object is tagged.
-         * @param e MapCSS environment
-         * @return {@code true} if the object is tagged
-         * @see OsmPrimitive#isTagged()
-         */
-        static boolean tagged(Environment e) { // NO_UCD (unused code)
-            return e.osm.isTagged();
-        }
-
-        /**
-         * {@code :same-tags} tests whether the object has the same tags as its child/parent.
-         * @param e MapCSS environment
-         * @return {@code true} if the object has the same tags as its child/parent
-         * @see OsmPrimitive#hasSameInterestingTags(OsmPrimitive)
-         */
-        static boolean sameTags(Environment e) { // NO_UCD (unused code)
-            return e.osm.hasSameInterestingTags(Utils.firstNonNull(e.child, e.parent));
-        }
-
-        /**
-         * {@code :area-style} tests whether the object has an area style. This is useful for validators.
-         * @param e MapCSS environment
-         * @return {@code true} if the object has an area style
-         * @see ElemStyles#hasAreaElemStyle(OsmPrimitive, boolean)
-         */
-        static boolean areaStyle(Environment e) { // NO_UCD (unused code)
-            // only for validator
-            return ElemStyles.hasAreaElemStyle(e.osm, false);
-        }
-
-        /**
-         * {@code unconnected}: tests whether the object is a unconnected node.
-         * @param e MapCSS environment
-         * @return {@code true} if the object is a unconnected node
-         */
-        static boolean unconnected(Environment e) { // NO_UCD (unused code)
-            return e.osm instanceof Node && OsmPrimitive.getFilteredList(e.osm.getReferrers(), Way.class).isEmpty();
-        }
-
-        /**
-         * {@code righthandtraffic} checks if there is right-hand traffic at the current location.
-         * @param e MapCSS environment
-         * @return {@code true} if there is right-hand traffic at the current location
-         * @see ExpressionFactory.Functions#is_right_hand_traffic(Environment)
-         */
-        static boolean righthandtraffic(Environment e) { // NO_UCD (unused code)
-            return ExpressionFactory.Functions.is_right_hand_traffic(e);
-        }
-
-        /**
-         * {@code clockwise} whether the way is closed and oriented clockwise,
-         * or non-closed and the 1st, 2nd and last node are in clockwise order.
-         * @param e MapCSS environment
-         * @return {@code true} if the way clockwise
-         * @see ExpressionFactory.Functions#is_clockwise(Environment)
-         */
-        static boolean clockwise(Environment e) { // NO_UCD (unused code)
-            return ExpressionFactory.Functions.is_clockwise(e);
-        }
-
-        /**
-         * {@code anticlockwise} whether the way is closed and oriented anticlockwise,
-         * or non-closed and the 1st, 2nd and last node are in anticlockwise order.
-         * @param e MapCSS environment
-         * @return {@code true} if the way clockwise
-         * @see ExpressionFactory.Functions#is_anticlockwise(Environment)
-         */
-        static boolean anticlockwise(Environment e) { // NO_UCD (unused code)
-            return ExpressionFactory.Functions.is_anticlockwise(e);
-        }
-
-        /**
-         * {@code unclosed-multipolygon} tests whether the object is an unclosed multipolygon.
-         * @param e MapCSS environment
-         * @return {@code true} if the object is an unclosed multipolygon
-         */
-        static boolean unclosed_multipolygon(Environment e) { // NO_UCD (unused code)
-            return e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon() &&
-                    !e.osm.isIncomplete() && !((Relation) e.osm).hasIncompleteMembers() &&
-                    !MultipolygonCache.getInstance().get(Main.map.mapView, (Relation) e.osm).getOpenEnds().isEmpty();
-        }
-
-        private static final Predicate<OsmPrimitive> IN_DOWNLOADED_AREA = new InDataSourceArea(false);
-
-        /**
-         * {@code in-downloaded-area} tests whether the object is within source area ("downloaded area").
-         * @param e MapCSS environment
-         * @return {@code true} if the object is within source area ("downloaded area")
-         * @see InDataSourceArea
-         */
-        static boolean inDownloadedArea(Environment e) { // NO_UCD (unused code)
-            return IN_DOWNLOADED_AREA.test(e.osm);
-        }
-
-        static boolean completely_downloaded(Environment e) { // NO_UCD (unused code)
-            if (e.osm instanceof Relation) {
-                return !((Relation) e.osm).hasIncompleteMembers();
-            } else {
-                return true;
-            }
-        }
-
-        static boolean closed2(Environment e) { // NO_UCD (unused code)
-            if (e.osm instanceof Way && ((Way) e.osm).isClosed())
-                return true;
-            if (e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon())
-                return MultipolygonCache.getInstance().get(Main.map.mapView, (Relation) e.osm).getOpenEnds().isEmpty();
-            return false;
-        }
-
-        static boolean selected(Environment e) { // NO_UCD (unused code)
-            Cascade c = e.mc.getCascade(e.layer);
-            c.setDefaultSelectedHandling(false);
-            return e.osm.isSelected();
-        }
-    }
-
-    class PseudoClassCondition implements Condition {
-
-        public final Method method;
-        public final boolean not;
-
-        protected PseudoClassCondition(Method method, boolean not) {
-            this.method = method;
-            this.not = not;
-        }
-
-        /**
-         * Create a new pseudo class condition
-         * @param id The id of the pseudo class
-         * @param not <code>true</code> to invert the condition
-         * @param context The context the class is found in.
-         * @return The new condition
-         */
-        public static PseudoClassCondition createPseudoClassCondition(String id, boolean not, Context context) {
-            CheckParameterUtil.ensureThat(!"sameTags".equals(id) || Context.LINK.equals(context), "sameTags only supported in LINK context");
-            if ("open_end".equals(id)) {
-                return new OpenEndPseudoClassCondition(not);
-            }
-            final Method method = getMethod(id);
-            if (method != null) {
-                return new PseudoClassCondition(method, not);
-            }
-            throw new MapCSSException("Invalid pseudo class specified: " + id);
-        }
-
-        protected static Method getMethod(String id) {
-            id = id.replaceAll("-|_", "");
-            for (Method method : PseudoClasses.class.getDeclaredMethods()) {
-                // for backwards compatibility, consider :sameTags == :same-tags == :same_tags (#11150)
-                final String methodName = method.getName().replaceAll("-|_", "");
-                if (methodName.equalsIgnoreCase(id)) {
-                    return method;
-                }
-            }
-            return null;
-        }
-
-        @Override
-        public boolean applies(Environment e) {
-            try {
-                return not ^ (Boolean) method.invoke(null, e);
-            } catch (IllegalAccessException | InvocationTargetException ex) {
-                throw new RuntimeException(ex);
-            }
-        }
-
-        @Override
-        public String toString() {
-            return (not ? "!" : "") + ':' + method.getName();
-        }
-    }
-
-    class OpenEndPseudoClassCondition extends PseudoClassCondition {
-        public OpenEndPseudoClassCondition(boolean not) {
-            super(null, not);
-        }
-
-        @Override
-        public boolean applies(Environment e) {
-            return true;
-        }
-    }
-
-    /**
-     * A condition that is fulfilled whenever the expression is evaluated to be true.
-     */
-    class ExpressionCondition implements Condition {
-
-        private final Expression e;
-
-        /**
-         * Constructs a new {@code ExpressionFactory}
-         * @param e expression
-         */
-        public ExpressionCondition(Expression e) {
-            this.e = e;
-        }
-
-        @Override
-        public boolean applies(Environment env) {
-            Boolean b = Cascade.convertTo(e.evaluate(env), Boolean.class);
-            return b != null && b;
-        }
-
-        @Override
-        public String toString() {
-            return '[' + e.toString() + ']';
-        }
-    }
-
-    /**
      * This is a condition that can be converted to a tag
      * @author Michael Zangl
      * @since 10674
      */
+    @FunctionalInterface
     public interface ToTagConvertable {
         /**
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java	(revision 10837)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java	(revision 10837)
@@ -0,0 +1,833 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.gui.mappaint.mapcss;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.text.MessageFormat;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.function.BiFunction;
+import java.util.function.IntFunction;
+import java.util.function.Predicate;
+import java.util.regex.Pattern;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.search.SearchCompiler.InDataSourceArea;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.OsmUtils;
+import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.data.osm.Tag;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
+import org.openstreetmap.josm.gui.mappaint.Cascade;
+import org.openstreetmap.josm.gui.mappaint.ElemStyles;
+import org.openstreetmap.josm.gui.mappaint.Environment;
+import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context;
+import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.ToTagConvertable;
+import org.openstreetmap.josm.tools.CheckParameterUtil;
+import org.openstreetmap.josm.tools.Utils;
+
+/**
+ * Factory to generate {@link Condition}s.
+ * @since 10837 (Extracted from Condition)
+ */
+public final class ConditionFactory {
+
+    private ConditionFactory() {
+        // Hide default constructor for utils classes
+    }
+
+    /**
+     * Create a new condition that checks the key and the value of the object.
+     * @param k The key.
+     * @param v The reference value
+     * @param op The operation to use when comparing the value
+     * @param context The type of context to use.
+     * @param considerValAsKey whether to consider {@code v} as another key and compare the values of key {@code k} and key {@code v}.
+     * @return The new condition.
+     */
+    public static Condition createKeyValueCondition(String k, String v, Op op, Context context, boolean considerValAsKey) {
+        switch (context) {
+        case PRIMITIVE:
+            if (KeyValueRegexpCondition.SUPPORTED_OPS.contains(op) && !considerValAsKey)
+                return new KeyValueRegexpCondition(k, v, op, false);
+            if (!considerValAsKey && op.equals(Op.EQ))
+                return new SimpleKeyValueCondition(k, v);
+            return new KeyValueCondition(k, v, op, considerValAsKey);
+        case LINK:
+            if (considerValAsKey)
+                throw new MapCSSException("''considerValAsKey'' not supported in LINK context");
+            if ("role".equalsIgnoreCase(k))
+                return new RoleCondition(v, op);
+            else if ("index".equalsIgnoreCase(k))
+                return new IndexCondition(v, op);
+            else
+                throw new MapCSSException(
+                        MessageFormat.format("Expected key ''role'' or ''index'' in link context. Got ''{0}''.", k));
+
+        default: throw new AssertionError();
+        }
+    }
+
+    /**
+     * Create a condition in which the key and the value need to match a given regexp
+     * @param k The key regexp
+     * @param v The value regexp
+     * @param op The operation to use when comparing the key and the value.
+     * @return The new condition.
+     */
+    public static Condition createRegexpKeyRegexpValueCondition(String k, String v, Op op) {
+        return new RegexpKeyValueRegexpCondition(k, v, op);
+    }
+
+    /**
+     * Creates a condition that checks the given key.
+     * @param k The key to test for
+     * @param not <code>true</code> to invert the match
+     * @param matchType The match type to check for.
+     * @param context The context this rule is found in.
+     * @return the new condition.
+     */
+    public static Condition createKeyCondition(String k, boolean not, KeyMatchType matchType, Context context) {
+        switch (context) {
+        case PRIMITIVE:
+            return new KeyCondition(k, not, matchType);
+        case LINK:
+            if (matchType != null)
+                throw new MapCSSException("Question mark operator ''?'' and regexp match not supported in LINK context");
+            if (not)
+                return new RoleCondition(k, Op.NEQ);
+            else
+                return new RoleCondition(k, Op.EQ);
+
+        default: throw new AssertionError();
+        }
+    }
+
+    /**
+     * Create a new pseudo class condition
+     * @param id The id of the pseudo class
+     * @param not <code>true</code> to invert the condition
+     * @param context The context the class is found in.
+     * @return The new condition
+     */
+    public static PseudoClassCondition createPseudoClassCondition(String id, boolean not, Context context) {
+        return PseudoClassCondition.createPseudoClassCondition(id, not, context);
+    }
+
+    /**
+     * Create a new class condition
+     * @param id The id of the class to match
+     * @param not <code>true</code> to invert the condition
+     * @param context Ignored
+     * @return The new condition
+     */
+    public static ClassCondition createClassCondition(String id, boolean not, Context context) {
+        return new ClassCondition(id, not);
+    }
+
+    /**
+     * Create a new condition that a expression needs to be fulfilled
+     * @param e the expression to check
+     * @param context Ignored
+     * @return The new condition
+     */
+    public static ExpressionCondition createExpressionCondition(Expression e, Context context) {
+        return new ExpressionCondition(e);
+    }
+
+    /**
+     * This is the operation that {@link KeyValueCondition} uses to match.
+     */
+    public enum Op {
+        /** The value equals the given reference. */
+        EQ(Objects::equals),
+        /** The value does not equal the reference. */
+        NEQ(EQ),
+        /** The value is greater than or equal to the given reference value (as float). */
+        GREATER_OR_EQUAL(comparisonResult -> comparisonResult >= 0),
+        /** The value is greater than the given reference value (as float). */
+        GREATER(comparisonResult -> comparisonResult > 0),
+        /** The value is less than or equal to the given reference value (as float). */
+        LESS_OR_EQUAL(comparisonResult -> comparisonResult <= 0),
+        /** The value is less than the given reference value (as float). */
+        LESS(comparisonResult -> comparisonResult < 0),
+        /** The reference is treated as regular expression and the value needs to match it. */
+        REGEX((test, prototype) -> Pattern.compile(prototype).matcher(test).find()),
+        /** The reference is treated as regular expression and the value needs to not match it. */
+        NREGEX(REGEX),
+        /** The reference is treated as a list separated by ';'. Spaces around the ; are ignored.
+         *  The value needs to be equal one of the list elements. */
+        ONE_OF((test, prototype) -> Arrays.asList(test.split("\\s*;\\s*")).contains(prototype)),
+        /** The value needs to begin with the reference string. */
+        BEGINS_WITH(String::startsWith),
+        /** The value needs to end with the reference string. */
+        ENDS_WITH(String::endsWith),
+        /** The value needs to contain the reference string. */
+        CONTAINS(String::contains);
+
+        static final Set<Op> NEGATED_OPS = EnumSet.of(NEQ, NREGEX);
+
+        private final BiFunction<String, String, Boolean> function;
+
+        private final boolean negated;
+
+        /**
+         * Create a new string operation.
+         * @param func The function to apply during {@link #eval(String, String)}.
+         */
+        Op(BiFunction<String, String, Boolean> func) {
+            this.function = func;
+            negated = false;
+        }
+
+        /**
+         * Create a new float operation that compares two float values
+         * @param comparatorResult A function to mapt the result of the comparison
+         */
+        Op(IntFunction<Boolean> comparatorResult) {
+            this.function = (test, prototype) -> {
+                float testFloat;
+                try {
+                    testFloat = Float.parseFloat(test);
+                } catch (NumberFormatException e) {
+                    return false;
+                }
+                float prototypeFloat = Float.parseFloat(prototype);
+
+                int res = Float.compare(testFloat, prototypeFloat);
+                return comparatorResult.apply(res);
+            };
+            negated = false;
+        }
+
+        /**
+         * Create a new Op by negating an other op.
+         * @param negate inverse operation
+         */
+        Op(Op negate) {
+            this.function = (a, b) -> !negate.function.apply(a, b);
+            negated = true;
+        }
+
+        /**
+         * Evaluates a value against a reference string.
+         * @param testString The value. May be <code>null</code>
+         * @param prototypeString The reference string-
+         * @return <code>true</code> if and only if this operation matches for the given value/reference pair.
+         */
+        public boolean eval(String testString, String prototypeString) {
+            if (testString == null)
+                return negated;
+            else
+                return function.apply(testString, prototypeString);
+        }
+    }
+
+    /**
+     * Most common case of a KeyValueCondition, this is the basic key=value case.
+     *
+     * Extra class for performance reasons.
+     */
+    public static class SimpleKeyValueCondition implements Condition, ToTagConvertable {
+        /**
+         * The key to search for.
+         */
+        public final String k;
+        /**
+         * The value to search for.
+         */
+        public final String v;
+
+        /**
+         * Create a new SimpleKeyValueCondition.
+         * @param k The key
+         * @param v The value.
+         */
+        public SimpleKeyValueCondition(String k, String v) {
+            this.k = k;
+            this.v = v;
+        }
+
+        @Override
+        public boolean applies(Environment e) {
+            return v.equals(e.osm.get(k));
+        }
+
+        @Override
+        public Tag asTag(OsmPrimitive primitive) {
+            return new Tag(k, v);
+        }
+
+        @Override
+        public String toString() {
+            return '[' + k + '=' + v + ']';
+        }
+
+    }
+
+    /**
+     * <p>Represents a key/value condition which is either applied to a primitive.</p>
+     *
+     */
+    public static class KeyValueCondition implements Condition, ToTagConvertable {
+        /**
+         * The key to search for.
+         */
+        public final String k;
+        /**
+         * The value to search for.
+         */
+        public final String v;
+        /**
+         * The key/value match operation.
+         */
+        public final Op op;
+        /**
+         * If this flag is set, {@link #v} is treated as a key and the value is the value set for that key.
+         */
+        public final boolean considerValAsKey;
+
+        /**
+         * <p>Creates a key/value-condition.</p>
+         *
+         * @param k the key
+         * @param v the value
+         * @param op the operation
+         * @param considerValAsKey whether to consider {@code v} as another key and compare the values of key {@code k} and key {@code v}.
+         */
+        public KeyValueCondition(String k, String v, Op op, boolean considerValAsKey) {
+            this.k = k;
+            this.v = v;
+            this.op = op;
+            this.considerValAsKey = considerValAsKey;
+        }
+
+        @Override
+        public boolean applies(Environment env) {
+            return op.eval(env.osm.get(k), considerValAsKey ? env.osm.get(v) : v);
+        }
+
+        @Override
+        public Tag asTag(OsmPrimitive primitive) {
+            return new Tag(k, v);
+        }
+
+        @Override
+        public String toString() {
+            return '[' + k + '\'' + op + '\'' + v + ']';
+        }
+    }
+
+    /**
+     * This condition requires a fixed key to match a given regexp
+     */
+    public static class KeyValueRegexpCondition extends KeyValueCondition {
+        protected static final Set<Op> SUPPORTED_OPS = EnumSet.of(Op.REGEX, Op.NREGEX);
+
+        final Pattern pattern;
+
+        public KeyValueRegexpCondition(String k, String v, Op op, boolean considerValAsKey) {
+            super(k, v, op, considerValAsKey);
+            CheckParameterUtil.ensureThat(!considerValAsKey, "considerValAsKey is not supported");
+            CheckParameterUtil.ensureThat(SUPPORTED_OPS.contains(op), "Op must be REGEX or NREGEX");
+            this.pattern = Pattern.compile(v);
+        }
+
+        protected boolean matches(Environment env) {
+            final String value = env.osm.get(k);
+            return value != null && pattern.matcher(value).find();
+        }
+
+        @Override
+        public boolean applies(Environment env) {
+            if (Op.REGEX.equals(op)) {
+                return matches(env);
+            } else if (Op.NREGEX.equals(op)) {
+                return !matches(env);
+            } else {
+                throw new IllegalStateException();
+            }
+        }
+    }
+
+    /**
+     * A condition that checks that a key with the matching pattern has a value with the matching pattern.
+     */
+    public static class RegexpKeyValueRegexpCondition extends KeyValueRegexpCondition {
+
+        public final Pattern keyPattern;
+
+        /**
+         * Create a condition in which the key and the value need to match a given regexp
+         * @param k The key regexp
+         * @param v The value regexp
+         * @param op The operation to use when comparing the key and the value.
+         */
+        public RegexpKeyValueRegexpCondition(String k, String v, Op op) {
+            super(k, v, op, false);
+            this.keyPattern = Pattern.compile(k);
+        }
+
+        @Override
+        protected boolean matches(Environment env) {
+            for (Map.Entry<String, String> kv: env.osm.getKeys().entrySet()) {
+                if (keyPattern.matcher(kv.getKey()).find() && pattern.matcher(kv.getValue()).find()) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    public static class RoleCondition implements Condition {
+        public final String role;
+        public final Op op;
+
+        public RoleCondition(String role, Op op) {
+            this.role = role;
+            this.op = op;
+        }
+
+        @Override
+        public boolean applies(Environment env) {
+            String testRole = env.getRole();
+            if (testRole == null) return false;
+            return op.eval(testRole, role);
+        }
+    }
+
+    public static class IndexCondition implements Condition {
+        public final String index;
+        public final Op op;
+
+        public IndexCondition(String index, Op op) {
+            this.index = index;
+            this.op = op;
+        }
+
+        @Override
+        public boolean applies(Environment env) {
+            if (env.index == null) return false;
+            if (index.startsWith("-")) {
+                return env.count != null && op.eval(Integer.toString(env.index - env.count), index);
+            } else {
+                return op.eval(Integer.toString(env.index + 1), index);
+            }
+        }
+    }
+
+    /**
+     * This defines how {@link KeyCondition} matches a given key.
+     */
+    public enum KeyMatchType {
+        /**
+         * The key needs to be equal to the given label.
+         */
+        EQ,
+        /**
+         * The key needs to have a true value (yes, ...)
+         * @see OsmUtils#isTrue(String)
+         */
+        TRUE,
+        /**
+         * The key needs to have a false value (no, ...)
+         * @see OsmUtils#isFalse(String)
+         */
+        FALSE,
+        /**
+         * The key needs to match the given regular expression.
+         */
+        REGEX
+    }
+
+    /**
+     * <p>KeyCondition represent one of the following conditions in either the link or the
+     * primitive context:</p>
+     * <pre>
+     *     ["a label"]  PRIMITIVE:   the primitive has a tag "a label"
+     *                  LINK:        the parent is a relation and it has at least one member with the role
+     *                               "a label" referring to the child
+     *
+     *     [!"a label"]  PRIMITIVE:  the primitive doesn't have a tag "a label"
+     *                   LINK:       the parent is a relation but doesn't have a member with the role
+     *                               "a label" referring to the child
+     *
+     *     ["a label"?]  PRIMITIVE:  the primitive has a tag "a label" whose value evaluates to a true-value
+     *                   LINK:       not supported
+     *
+     *     ["a label"?!] PRIMITIVE:  the primitive has a tag "a label" whose value evaluates to a false-value
+     *                   LINK:       not supported
+     * </pre>
+     */
+    public static class KeyCondition implements Condition, ToTagConvertable {
+
+        /**
+         * The key name.
+         */
+        public final String label;
+        /**
+         * If we should negate the result of the match.
+         */
+        public final boolean negateResult;
+        /**
+         * Describes how to match the label against the key.
+         * @see KeyMatchType
+         */
+        public final KeyMatchType matchType;
+        /**
+         * A predicate used to match a the regexp against the key. Only used if the match type is regexp.
+         */
+        public final Predicate<String> containsPattern;
+
+        /**
+         * Creates a new KeyCondition
+         * @param label The key name (or regexp) to use.
+         * @param negateResult If we should negate the result.,
+         * @param matchType The match type.
+         */
+        public KeyCondition(String label, boolean negateResult, KeyMatchType matchType) {
+            this.label = label;
+            this.negateResult = negateResult;
+            this.matchType = matchType == null ? KeyMatchType.EQ : matchType;
+            this.containsPattern = KeyMatchType.REGEX.equals(matchType)
+                    ? Pattern.compile(label).asPredicate()
+                    : null;
+        }
+
+        @Override
+        public boolean applies(Environment e) {
+            switch(e.getContext()) {
+            case PRIMITIVE:
+                switch (matchType) {
+                case TRUE:
+                    return e.osm.isKeyTrue(label) ^ negateResult;
+                case FALSE:
+                    return e.osm.isKeyFalse(label) ^ negateResult;
+                case REGEX:
+                    return e.osm.keySet().stream().anyMatch(containsPattern) ^ negateResult;
+                default:
+                    return e.osm.hasKey(label) ^ negateResult;
+                }
+            case LINK:
+                Utils.ensure(false, "Illegal state: KeyCondition not supported in LINK context");
+                return false;
+            default: throw new AssertionError();
+            }
+        }
+
+        /**
+         * Get the matched key and the corresponding value.
+         * <p>
+         * WARNING: This ignores {@link #negateResult}.
+         * <p>
+         * WARNING: For regexp, the regular expression is returned instead of a key if the match failed.
+         * @param p The primitive to get the value from.
+         * @return The tag.
+         */
+        @Override
+        public Tag asTag(OsmPrimitive p) {
+            String key = label;
+            if (KeyMatchType.REGEX.equals(matchType)) {
+                key = p.keySet().stream().filter(containsPattern).findAny().orElse(key);
+            }
+            return new Tag(key, p.get(key));
+        }
+
+        @Override
+        public String toString() {
+            return '[' + (negateResult ? "!" : "") + label + ']';
+        }
+    }
+
+    public static class ClassCondition implements Condition {
+
+        public final String id;
+        public final boolean not;
+
+        public ClassCondition(String id, boolean not) {
+            this.id = id;
+            this.not = not;
+        }
+
+        @Override
+        public boolean applies(Environment env) {
+            Cascade cascade = env.getCascade(env.layer);
+            return cascade != null && (not ^ cascade.containsKey(id));
+        }
+
+        @Override
+        public String toString() {
+            return (not ? "!" : "") + '.' + id;
+        }
+    }
+
+    /**
+     * Like <a href="http://www.w3.org/TR/css3-selectors/#pseudo-classes">CSS pseudo classes</a>, MapCSS pseudo classes
+     * are written in lower case with dashes between words.
+     */
+    public static final class PseudoClasses {
+
+        private PseudoClasses() {
+            // Hide default constructor for utilities classes
+        }
+
+        /**
+         * {@code closed} tests whether the way is closed or the relation is a closed multipolygon
+         * @param e MapCSS environment
+         * @return {@code true} if the way is closed or the relation is a closed multipolygon
+         */
+        static boolean closed(Environment e) { // NO_UCD (unused code)
+            if (e.osm instanceof Way && ((Way) e.osm).isClosed())
+                return true;
+            if (e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon())
+                return true;
+            return false;
+        }
+
+        /**
+         * {@code :modified} tests whether the object has been modified.
+         * @param e MapCSS environment
+         * @return {@code true} if the object has been modified
+         * @see OsmPrimitive#isModified()
+         */
+        static boolean modified(Environment e) { // NO_UCD (unused code)
+            return e.osm.isModified() || e.osm.isNewOrUndeleted();
+        }
+
+        /**
+         * {@code ;new} tests whether the object is new.
+         * @param e MapCSS environment
+         * @return {@code true} if the object is new
+         * @see OsmPrimitive#isNew()
+         */
+        static boolean _new(Environment e) { // NO_UCD (unused code)
+            return e.osm.isNew();
+        }
+
+        /**
+         * {@code :connection} tests whether the object is a connection node.
+         * @param e MapCSS environment
+         * @return {@code true} if the object is a connection node
+         * @see Node#isConnectionNode()
+         */
+        static boolean connection(Environment e) { // NO_UCD (unused code)
+            return e.osm instanceof Node && e.osm.getDataSet() != null && ((Node) e.osm).isConnectionNode();
+        }
+
+        /**
+         * {@code :tagged} tests whether the object is tagged.
+         * @param e MapCSS environment
+         * @return {@code true} if the object is tagged
+         * @see OsmPrimitive#isTagged()
+         */
+        static boolean tagged(Environment e) { // NO_UCD (unused code)
+            return e.osm.isTagged();
+        }
+
+        /**
+         * {@code :same-tags} tests whether the object has the same tags as its child/parent.
+         * @param e MapCSS environment
+         * @return {@code true} if the object has the same tags as its child/parent
+         * @see OsmPrimitive#hasSameInterestingTags(OsmPrimitive)
+         */
+        static boolean sameTags(Environment e) { // NO_UCD (unused code)
+            return e.osm.hasSameInterestingTags(Utils.firstNonNull(e.child, e.parent));
+        }
+
+        /**
+         * {@code :area-style} tests whether the object has an area style. This is useful for validators.
+         * @param e MapCSS environment
+         * @return {@code true} if the object has an area style
+         * @see ElemStyles#hasAreaElemStyle(OsmPrimitive, boolean)
+         */
+        static boolean areaStyle(Environment e) { // NO_UCD (unused code)
+            // only for validator
+            return ElemStyles.hasAreaElemStyle(e.osm, false);
+        }
+
+        /**
+         * {@code unconnected}: tests whether the object is a unconnected node.
+         * @param e MapCSS environment
+         * @return {@code true} if the object is a unconnected node
+         */
+        static boolean unconnected(Environment e) { // NO_UCD (unused code)
+            return e.osm instanceof Node && OsmPrimitive.getFilteredList(e.osm.getReferrers(), Way.class).isEmpty();
+        }
+
+        /**
+         * {@code righthandtraffic} checks if there is right-hand traffic at the current location.
+         * @param e MapCSS environment
+         * @return {@code true} if there is right-hand traffic at the current location
+         * @see ExpressionFactory.Functions#is_right_hand_traffic(Environment)
+         */
+        static boolean righthandtraffic(Environment e) { // NO_UCD (unused code)
+            return ExpressionFactory.Functions.is_right_hand_traffic(e);
+        }
+
+        /**
+         * {@code clockwise} whether the way is closed and oriented clockwise,
+         * or non-closed and the 1st, 2nd and last node are in clockwise order.
+         * @param e MapCSS environment
+         * @return {@code true} if the way clockwise
+         * @see ExpressionFactory.Functions#is_clockwise(Environment)
+         */
+        static boolean clockwise(Environment e) { // NO_UCD (unused code)
+            return ExpressionFactory.Functions.is_clockwise(e);
+        }
+
+        /**
+         * {@code anticlockwise} whether the way is closed and oriented anticlockwise,
+         * or non-closed and the 1st, 2nd and last node are in anticlockwise order.
+         * @param e MapCSS environment
+         * @return {@code true} if the way clockwise
+         * @see ExpressionFactory.Functions#is_anticlockwise(Environment)
+         */
+        static boolean anticlockwise(Environment e) { // NO_UCD (unused code)
+            return ExpressionFactory.Functions.is_anticlockwise(e);
+        }
+
+        /**
+         * {@code unclosed-multipolygon} tests whether the object is an unclosed multipolygon.
+         * @param e MapCSS environment
+         * @return {@code true} if the object is an unclosed multipolygon
+         */
+        static boolean unclosed_multipolygon(Environment e) { // NO_UCD (unused code)
+            return e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon() &&
+                    !e.osm.isIncomplete() && !((Relation) e.osm).hasIncompleteMembers() &&
+                    !MultipolygonCache.getInstance().get(Main.map.mapView, (Relation) e.osm).getOpenEnds().isEmpty();
+        }
+
+        private static final Predicate<OsmPrimitive> IN_DOWNLOADED_AREA = new InDataSourceArea(false);
+
+        /**
+         * {@code in-downloaded-area} tests whether the object is within source area ("downloaded area").
+         * @param e MapCSS environment
+         * @return {@code true} if the object is within source area ("downloaded area")
+         * @see InDataSourceArea
+         */
+        static boolean inDownloadedArea(Environment e) { // NO_UCD (unused code)
+            return IN_DOWNLOADED_AREA.test(e.osm);
+        }
+
+        static boolean completely_downloaded(Environment e) { // NO_UCD (unused code)
+            if (e.osm instanceof Relation) {
+                return !((Relation) e.osm).hasIncompleteMembers();
+            } else {
+                return true;
+            }
+        }
+
+        static boolean closed2(Environment e) { // NO_UCD (unused code)
+            if (e.osm instanceof Way && ((Way) e.osm).isClosed())
+                return true;
+            if (e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon())
+                return MultipolygonCache.getInstance().get(Main.map.mapView, (Relation) e.osm).getOpenEnds().isEmpty();
+            return false;
+        }
+
+        static boolean selected(Environment e) { // NO_UCD (unused code)
+            Cascade c = e.mc.getCascade(e.layer);
+            c.setDefaultSelectedHandling(false);
+            return e.osm.isSelected();
+        }
+    }
+
+    public static class PseudoClassCondition implements Condition {
+
+        public final Method method;
+        public final boolean not;
+
+        protected PseudoClassCondition(Method method, boolean not) {
+            this.method = method;
+            this.not = not;
+        }
+
+        /**
+         * Create a new pseudo class condition
+         * @param id The id of the pseudo class
+         * @param not <code>true</code> to invert the condition
+         * @param context The context the class is found in.
+         * @return The new condition
+         */
+        public static PseudoClassCondition createPseudoClassCondition(String id, boolean not, Context context) {
+            CheckParameterUtil.ensureThat(!"sameTags".equals(id) || Context.LINK.equals(context), "sameTags only supported in LINK context");
+            if ("open_end".equals(id)) {
+                return new OpenEndPseudoClassCondition(not);
+            }
+            final Method method = getMethod(id);
+            if (method != null) {
+                return new PseudoClassCondition(method, not);
+            }
+            throw new MapCSSException("Invalid pseudo class specified: " + id);
+        }
+
+        protected static Method getMethod(String id) {
+            id = id.replaceAll("-|_", "");
+            for (Method method : PseudoClasses.class.getDeclaredMethods()) {
+                // for backwards compatibility, consider :sameTags == :same-tags == :same_tags (#11150)
+                final String methodName = method.getName().replaceAll("-|_", "");
+                if (methodName.equalsIgnoreCase(id)) {
+                    return method;
+                }
+            }
+            return null;
+        }
+
+        @Override
+        public boolean applies(Environment e) {
+            try {
+                return not ^ (Boolean) method.invoke(null, e);
+            } catch (IllegalAccessException | InvocationTargetException ex) {
+                throw new RuntimeException(ex);
+            }
+        }
+
+        @Override
+        public String toString() {
+            return (not ? "!" : "") + ':' + method.getName();
+        }
+    }
+
+    public static class OpenEndPseudoClassCondition extends PseudoClassCondition {
+        public OpenEndPseudoClassCondition(boolean not) {
+            super(null, not);
+        }
+
+        @Override
+        public boolean applies(Environment e) {
+            return true;
+        }
+    }
+
+    /**
+     * A condition that is fulfilled whenever the expression is evaluated to be true.
+     */
+    public static class ExpressionCondition implements Condition {
+
+        private final Expression e;
+
+        /**
+         * Constructs a new {@code ExpressionFactory}
+         * @param e expression
+         */
+        public ExpressionCondition(Expression e) {
+            this.e = e;
+        }
+
+        @Override
+        public boolean applies(Environment env) {
+            Boolean b = Cascade.convertTo(e.evaluate(env), Boolean.class);
+            return b != null && b;
+        }
+
+        @Override
+        public String toString() {
+            return '[' + e.toString() + ']';
+        }
+    }
+}
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java	(revision 10836)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java	(revision 10837)
@@ -43,6 +43,6 @@
 
 /**
- * Factory to generate Expressions.
- *
+ * Factory to generate {@link Expression}s.
+ * <p>
  * See {@link #createFunctionExpression}.
  */
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj	(revision 10836)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj	(revision 10837)
@@ -22,4 +22,7 @@
 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition;
 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context;
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory;
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyMatchType;
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.Op;
 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression;
 import org.openstreetmap.josm.gui.mappaint.mapcss.ExpressionFactory;
@@ -744,5 +747,5 @@
             c=simple_key_value_condition(context) s() <RSQUARE> { return c; }
         |
-            e=expression() <RSQUARE> { return Condition.createExpressionCondition(e, context); }
+            e=expression() <RSQUARE> { return ConditionFactory.createExpressionCondition(e, context); }
     )
 }
@@ -762,5 +765,5 @@
 {
     boolean not = false;
-    Condition.KeyMatchType matchType = null;;
+    KeyMatchType matchType = null;;
     String key;
 }
@@ -768,11 +771,11 @@
     ( <EXCLAMATION> { not = true; } )?
     (
-        { matchType = Condition.KeyMatchType.REGEX; } key = regex()
+        { matchType = KeyMatchType.REGEX; } key = regex()
     |
         key = tag_key()
     )
-    ( LOOKAHEAD(2) <QUESTION> <EXCLAMATION> { matchType = Condition.KeyMatchType.FALSE; } )?
-    (              <QUESTION>               { matchType = Condition.KeyMatchType.TRUE;  } )?
-    { return Condition.createKeyCondition(key, not, matchType, context); }
+    ( LOOKAHEAD(2) <QUESTION> <EXCLAMATION> { matchType = KeyMatchType.FALSE; } )?
+    (              <QUESTION>               { matchType = KeyMatchType.TRUE;  } )?
+    { return ConditionFactory.createKeyCondition(key, not, matchType, context); }
 }
 
@@ -783,11 +786,11 @@
     float f;
     int i;
-    Condition.KeyMatchType matchType = null;;
-    Condition.Op op;
+    KeyMatchType matchType = null;;
+    Op op;
     boolean considerValAsKey = false;
 }
 {
     (
-        key = regex() s() { matchType = Condition.KeyMatchType.REGEX; }
+        key = regex() s() { matchType = KeyMatchType.REGEX; }
     |
         key=tag_key() s()
@@ -796,7 +799,7 @@
         LOOKAHEAD(3)
             (
-                    <EQUAL> <TILDE> { op=Condition.Op.REGEX; }
+                    <EQUAL> <TILDE> { op=Op.REGEX; }
                 |
-                    <EXCLAMATION> <TILDE> { op=Condition.Op.NREGEX; }
+                    <EXCLAMATION> <TILDE> { op=Op.NREGEX; }
             )
             s()
@@ -805,15 +808,15 @@
         |
             (
-                    <EXCLAMATION> <EQUAL> { op=Condition.Op.NEQ; }
+                    <EXCLAMATION> <EQUAL> { op=Op.NEQ; }
                 |
-                    <EQUAL> { op=Condition.Op.EQ; }
+                    <EQUAL> { op=Op.EQ; }
                 |
-                    <TILDE> <EQUAL> { op=Condition.Op.ONE_OF; }
+                    <TILDE> <EQUAL> { op=Op.ONE_OF; }
                 |
-                    <CARET> <EQUAL> { op=Condition.Op.BEGINS_WITH; }
+                    <CARET> <EQUAL> { op=Op.BEGINS_WITH; }
                 |
-                    <DOLLAR> <EQUAL> { op=Condition.Op.ENDS_WITH; }
+                    <DOLLAR> <EQUAL> { op=Op.ENDS_WITH; }
                 |
-                    <STAR> <EQUAL> { op=Condition.Op.CONTAINS; }
+                    <STAR> <EQUAL> { op=Op.CONTAINS; }
             )
             s()
@@ -829,18 +832,18 @@
         |
             (
-                    <GREATER_EQUAL> { op=Condition.Op.GREATER_OR_EQUAL; }
+                    <GREATER_EQUAL> { op=Op.GREATER_OR_EQUAL; }
                 |
-                    <GREATER> { op=Condition.Op.GREATER; }
+                    <GREATER> { op=Op.GREATER; }
                 |
-                    <LESS_EQUAL> { op=Condition.Op.LESS_OR_EQUAL; }
+                    <LESS_EQUAL> { op=Op.LESS_OR_EQUAL; }
                 |
-                    <LESS> { op=Condition.Op.LESS; }
+                    <LESS> { op=Op.LESS; }
             )
             s()
             f=float_() { val=Float.toString(f); }
     )
-    { return Condition.KeyMatchType.REGEX == matchType
-            ? Condition.createRegexpKeyRegexpValueCondition(key, val, op)
-            : Condition.createKeyValueCondition(key, val, op, context, considerValAsKey); }
+    { return KeyMatchType.REGEX == matchType
+            ? ConditionFactory.createRegexpKeyRegexpValueCondition(key, val, op)
+            : ConditionFactory.createKeyValueCondition(key, val, op, context, considerValAsKey); }
 }
 
@@ -860,6 +863,6 @@
     s=ident()
     { return pseudo
-        ? Condition.createPseudoClassCondition(s, not, context)
-        : Condition.createClassCondition(s, not, context); }
+        ? ConditionFactory.createPseudoClassCondition(s, not, context)
+        : ConditionFactory.createClassCondition(s, not, context); }
 }
 
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java	(revision 10836)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java	(revision 10837)
@@ -45,9 +45,9 @@
 import org.openstreetmap.josm.gui.mappaint.StyleSetting.BooleanStyleSetting;
 import org.openstreetmap.josm.gui.mappaint.StyleSource;
-import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.KeyCondition;
-import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.KeyMatchType;
-import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.KeyValueCondition;
-import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Op;
-import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.SimpleKeyValueCondition;
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyCondition;
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyMatchType;
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyValueCondition;
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.Op;
+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;
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java	(revision 10836)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java	(revision 10837)
@@ -21,4 +21,5 @@
 import org.openstreetmap.josm.gui.mappaint.Environment;
 import org.openstreetmap.josm.gui.mappaint.Range;
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.OpenEndPseudoClassCondition;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
 import org.openstreetmap.josm.tools.Geometry;
@@ -377,5 +378,5 @@
             } else if (ChildOrParentSelectorType.CHILD.equals(type)
                     && link.conds != null && !link.conds.isEmpty()
-                    && link.conds.get(0) instanceof Condition.OpenEndPseudoClassCondition) {
+                    && link.conds.get(0) instanceof OpenEndPseudoClassCondition) {
                 if (e.osm instanceof Node) {
                     e.osm.visitReferrers(new MultipolygonOpenEndFinder(e));
Index: /trunk/test/performance/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSConditionPerformanceTest.java
===================================================================
--- /trunk/test/performance/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSConditionPerformanceTest.java	(revision 10836)
+++ /trunk/test/performance/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSConditionPerformanceTest.java	(revision 10837)
@@ -6,5 +6,5 @@
 import org.junit.Test;
 import org.openstreetmap.josm.PerformanceTestUtils;
-import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Op;
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.Op;
 
 /**
Index: /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionTest.java	(revision 10836)
+++ /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionTest.java	(revision 10837)
@@ -13,7 +13,7 @@
 import org.openstreetmap.josm.gui.mappaint.Environment;
 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context;
-import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Op;
-import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.SimpleKeyValueCondition;
 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.ToTagConvertable;
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.Op;
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.SimpleKeyValueCondition;
 import org.openstreetmap.josm.testutils.JOSMTestRules;
 
@@ -54,5 +54,5 @@
     @Test
     public void testKeyValueEq() {
-        Condition op = Condition.createKeyValueCondition("k1", "v1", Op.EQ, Context.PRIMITIVE, false);
+        Condition op = ConditionFactory.createKeyValueCondition("k1", "v1", Op.EQ, Context.PRIMITIVE, false);
         assertFalse(op.applies(genEnv(node0)));
         assertTrue(op.applies(genEnv(node1)));
@@ -72,5 +72,5 @@
     @Test
     public void testKeyValueEqAsKey() {
-        Condition op = Condition.createKeyValueCondition("k1", "k2", Op.EQ, Context.PRIMITIVE, true);
+        Condition op = ConditionFactory.createKeyValueCondition("k1", "k2", Op.EQ, Context.PRIMITIVE, true);
         assertFalse(op.applies(genEnv(node0)));
         assertTrue(op.applies(genEnv(node1)));
@@ -88,5 +88,5 @@
     @Test
     public void testKeyValueNeq() {
-        Condition op = Condition.createKeyValueCondition("k1", "v1", Op.NEQ, Context.PRIMITIVE, false);
+        Condition op = ConditionFactory.createKeyValueCondition("k1", "v1", Op.NEQ, Context.PRIMITIVE, false);
         assertTrue(op.applies(genEnv(node0)));
         assertFalse(op.applies(genEnv(node1)));
@@ -101,5 +101,5 @@
     @Test
     public void testKeyValueGreatherEq() {
-        Condition op = Condition.createKeyValueCondition("f1", "0.2", Op.GREATER_OR_EQUAL, Context.PRIMITIVE, false);
+        Condition op = ConditionFactory.createKeyValueCondition("f1", "0.2", Op.GREATER_OR_EQUAL, Context.PRIMITIVE, false);
         assertFalse(op.applies(genEnv(node0)));
         assertTrue(op.applies(genEnv(node1)));
@@ -114,5 +114,5 @@
     @Test
     public void testKeyValueGreather() {
-        Condition op = Condition.createKeyValueCondition("f1", "0.2", Op.GREATER, Context.PRIMITIVE, false);
+        Condition op = ConditionFactory.createKeyValueCondition("f1", "0.2", Op.GREATER, Context.PRIMITIVE, false);
         assertFalse(op.applies(genEnv(node0)));
         assertFalse(op.applies(genEnv(node1)));
@@ -127,5 +127,5 @@
     @Test
     public void testKeyValueLessEq() {
-        Condition op = Condition.createKeyValueCondition("f1", "0.2", Op.LESS_OR_EQUAL, Context.PRIMITIVE, false);
+        Condition op = ConditionFactory.createKeyValueCondition("f1", "0.2", Op.LESS_OR_EQUAL, Context.PRIMITIVE, false);
         assertFalse(op.applies(genEnv(node0)));
         assertTrue(op.applies(genEnv(node1)));
@@ -140,5 +140,5 @@
     @Test
     public void testKeyValueLess() {
-        Condition op = Condition.createKeyValueCondition("f1", "0.2", Op.LESS, Context.PRIMITIVE, false);
+        Condition op = ConditionFactory.createKeyValueCondition("f1", "0.2", Op.LESS, Context.PRIMITIVE, false);
         assertFalse(op.applies(genEnv(node0)));
         assertFalse(op.applies(genEnv(node1)));
@@ -153,5 +153,5 @@
     @Test
     public void testKeyValueRegex() {
-        Condition op = Condition.createKeyValueCondition("r1", "(ab){2}", Op.REGEX, Context.PRIMITIVE, false);
+        Condition op = ConditionFactory.createKeyValueCondition("r1", "(ab){2}", Op.REGEX, Context.PRIMITIVE, false);
         assertFalse(op.applies(genEnv(node0)));
         assertTrue(op.applies(genEnv(node1)));
@@ -166,5 +166,5 @@
     @Test
     public void testKeyValueNregex() {
-        Condition op = Condition.createKeyValueCondition("r1", "(ab){2}", Op.NREGEX, Context.PRIMITIVE, false);
+        Condition op = ConditionFactory.createKeyValueCondition("r1", "(ab){2}", Op.NREGEX, Context.PRIMITIVE, false);
         assertTrue(op.applies(genEnv(node0)));
         assertFalse(op.applies(genEnv(node1)));
@@ -179,5 +179,5 @@
     @Test
     public void testKeyValueOneOf() {
-        Condition op = Condition.createKeyValueCondition("one", "a", Op.ONE_OF, Context.PRIMITIVE, false);
+        Condition op = ConditionFactory.createKeyValueCondition("one", "a", Op.ONE_OF, Context.PRIMITIVE, false);
         assertFalse(op.applies(genEnv(node0)));
         assertTrue(op.applies(genEnv(node1)));
@@ -192,5 +192,5 @@
     @Test
     public void testKeyValueBeginsWith() {
-        Condition op = Condition.createKeyValueCondition("c1", "xy", Op.BEGINS_WITH, Context.PRIMITIVE, false);
+        Condition op = ConditionFactory.createKeyValueCondition("c1", "xy", Op.BEGINS_WITH, Context.PRIMITIVE, false);
         assertFalse(op.applies(genEnv(node0)));
         assertTrue(op.applies(genEnv(node1)));
@@ -205,5 +205,5 @@
     @Test
     public void testKeyValueEndsWith() {
-        Condition op = Condition.createKeyValueCondition("c1", "xy", Op.ENDS_WITH, Context.PRIMITIVE, false);
+        Condition op = ConditionFactory.createKeyValueCondition("c1", "xy", Op.ENDS_WITH, Context.PRIMITIVE, false);
         assertFalse(op.applies(genEnv(node0)));
         assertFalse(op.applies(genEnv(node1)));
@@ -218,25 +218,25 @@
     @Test
     public void testKeyValueContains() {
-        Condition op = Condition.createKeyValueCondition("c1", "xy", Op.CONTAINS, Context.PRIMITIVE, false);
-        assertFalse(op.applies(genEnv(node0)));
-        assertTrue(op.applies(genEnv(node1)));
-        assertTrue(op.applies(genEnv(node2)));
-        assertTrue(op.applies(genEnv(node3)));
-        assertTrue(op.applies(genEnv(node4)));
-    }
-
-    /**
-     * Test of {@link Condition#createRegexpKeyRegexpValueCondition(String, String, Op)}
+        Condition op = ConditionFactory.createKeyValueCondition("c1", "xy", Op.CONTAINS, Context.PRIMITIVE, false);
+        assertFalse(op.applies(genEnv(node0)));
+        assertTrue(op.applies(genEnv(node1)));
+        assertTrue(op.applies(genEnv(node2)));
+        assertTrue(op.applies(genEnv(node3)));
+        assertTrue(op.applies(genEnv(node4)));
+    }
+
+    /**
+     * Test of {@link ConditionFactory#createRegexpKeyRegexpValueCondition(String, String, Op)}
      */
     @Test
     public void testRegexpKeyValueRegexpCondition() {
-        Condition op = Condition.createRegexpKeyRegexpValueCondition("^k", "\\da", Op.REGEX);
-        assertFalse(op.applies(genEnv(node0)));
-        assertFalse(op.applies(genEnv(node1)));
-        assertTrue(op.applies(genEnv(node2)));
-        assertFalse(op.applies(genEnv(node3)));
-        assertTrue(op.applies(genEnv(node4)));
-
-        Condition notOp = Condition.createRegexpKeyRegexpValueCondition("^k", "\\da", Op.NREGEX);
+        Condition op = ConditionFactory.createRegexpKeyRegexpValueCondition("^k", "\\da", Op.REGEX);
+        assertFalse(op.applies(genEnv(node0)));
+        assertFalse(op.applies(genEnv(node1)));
+        assertTrue(op.applies(genEnv(node2)));
+        assertFalse(op.applies(genEnv(node3)));
+        assertTrue(op.applies(genEnv(node4)));
+
+        Condition notOp = ConditionFactory.createRegexpKeyRegexpValueCondition("^k", "\\da", Op.NREGEX);
         assertTrue(notOp.applies(genEnv(node0)));
         assertTrue(notOp.applies(genEnv(node1)));
Index: /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyConditionTest.groovy
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyConditionTest.groovy	(revision 10836)
+++ /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyConditionTest.groovy	(revision 10837)
@@ -13,4 +13,5 @@
 import org.openstreetmap.josm.gui.mappaint.Environment
 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyMatchType
 
 class KeyConditionTest {
@@ -47,25 +48,25 @@
 
         // ["a label"]
-        Condition c = Condition.createKeyCondition("a key", false, Condition.KeyMatchType.FALSE, Context.PRIMITIVE)
+        Condition c = ConditionFactory.createKeyCondition("a key", false, KeyMatchType.FALSE, Context.PRIMITIVE)
         // ["a label"?]
-        c = Condition.createKeyCondition("a key", false, Condition.KeyMatchType.TRUE, Context.PRIMITIVE)
+        c = ConditionFactory.createKeyCondition("a key", false, KeyMatchType.TRUE, Context.PRIMITIVE)
         // [!"a label"]
-        c = Condition.createKeyCondition("a key", true, Condition.KeyMatchType.FALSE, Context.PRIMITIVE)
+        c = ConditionFactory.createKeyCondition("a key", true, KeyMatchType.FALSE, Context.PRIMITIVE)
         // [!"a label"?]
-        c = Condition.createKeyCondition("a key", true, Condition.KeyMatchType.TRUE, Context.PRIMITIVE)
+        c = ConditionFactory.createKeyCondition("a key", true, KeyMatchType.TRUE, Context.PRIMITIVE)
 
         // ["a label"]
-        c = Condition.createKeyCondition("a key", false, null, Context.LINK)
+        c = ConditionFactory.createKeyCondition("a key", false, null, Context.LINK)
         // [!"a label"]
-        c = Condition.createKeyCondition("a key", true, null, Context.LINK)
+        c = ConditionFactory.createKeyCondition("a key", true, null, Context.LINK)
 
         shouldFail(MapCSSException) {
             // ["a label"?]
-           c = Condition.createKeyCondition("a key", false, Condition.KeyMatchType.TRUE, Context.LINK)
+           c = ConditionFactory.createKeyCondition("a key", false, KeyMatchType.TRUE, Context.LINK)
         }
 
         shouldFail(MapCSSException) {
             // [!"a label"?]
-            c = Condition.createKeyCondition("a key", true, Condition.KeyMatchType.TRUE, Context.LINK)
+            c = ConditionFactory.createKeyCondition("a key", true, KeyMatchType.TRUE, Context.LINK)
         }
     }
@@ -79,8 +80,8 @@
         Environment e = new Environment(n).withParent(r).withIndex(0, r.membersCount).withLinkContext()
 
-        Condition cond = Condition.createKeyCondition("my_role", false, null, Context.LINK)
+        Condition cond = ConditionFactory.createKeyCondition("my_role", false, null, Context.LINK)
         assert cond.applies(e)
 
-        cond = Condition.createKeyCondition("my_role", true, null, Context.LINK)
+        cond = ConditionFactory.createKeyCondition("my_role", true, null, Context.LINK)
         assert !cond.applies(e)
     }
@@ -94,8 +95,8 @@
         Environment e = new Environment(n).withParent(r).withIndex(0, r.membersCount).withLinkContext()
 
-        Condition cond = Condition.createKeyCondition("another_role", false, null, Context.LINK)
+        Condition cond = ConditionFactory.createKeyCondition("another_role", false, null, Context.LINK)
         assert !cond.applies(e)
 
-        cond = Condition.createKeyCondition("another_role", true, null, Context.LINK)
+        cond = ConditionFactory.createKeyCondition("another_role", true, null, Context.LINK)
         assert cond.applies(e)
     }
Index: /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyValueConditionTest.groovy
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyValueConditionTest.groovy	(revision 10836)
+++ /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyValueConditionTest.groovy	(revision 10837)
@@ -12,5 +12,5 @@
 import org.openstreetmap.josm.gui.mappaint.Environment
 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context
-import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Op
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.Op
 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser
 
@@ -47,11 +47,11 @@
     @Test
     public void create() {
-        Condition c = Condition.createKeyValueCondition("a key", "a value", Op.EQ, Context.PRIMITIVE, false)
+        Condition c = ConditionFactory.createKeyValueCondition("a key", "a value", Op.EQ, Context.PRIMITIVE, false)
 
-        c = Condition.createKeyValueCondition("role", "a role", Op.EQ, Context.LINK, false)
-        c = Condition.createKeyValueCondition("RoLe", "a role", Op.EQ, Context.LINK, false)
+        c = ConditionFactory.createKeyValueCondition("role", "a role", Op.EQ, Context.LINK, false)
+        c = ConditionFactory.createKeyValueCondition("RoLe", "a role", Op.EQ, Context.LINK, false)
 
         shouldFail(MapCSSException) {
-            c = Condition.createKeyValueCondition("an arbitry tag", "a role", Op.EQ, Context.LINK, false)
+            c = ConditionFactory.createKeyValueCondition("an arbitry tag", "a role", Op.EQ, Context.LINK, false)
         }
     }
@@ -65,8 +65,8 @@
         Environment e = new Environment(n).withParent(r).withLinkContext().withIndex(0, r.membersCount)
 
-        Condition cond = new Condition.RoleCondition("my_role", Op.EQ)
+        Condition cond = new ConditionFactory.RoleCondition("my_role", Op.EQ)
         assert cond.applies(e)
 
-        cond = new Condition.RoleCondition("another_role", Op.EQ)
+        cond = new ConditionFactory.RoleCondition("another_role", Op.EQ)
         assert !cond.applies(e)
     }
@@ -80,8 +80,8 @@
         Environment e = new Environment(n).withParent(r).withIndex(0, r.membersCount).withLinkContext()
 
-        Condition cond = Condition.createKeyValueCondition("role", "my_role", Op.NEQ, Context.LINK, false)
+        Condition cond = ConditionFactory.createKeyValueCondition("role", "my_role", Op.NEQ, Context.LINK, false)
         assert !cond.applies(e)
 
-        cond = Condition.createKeyValueCondition("role", "another_role", Op.NEQ, Context.LINK, false)
+        cond = ConditionFactory.createKeyValueCondition("role", "another_role", Op.NEQ, Context.LINK, false)
         assert cond.applies(e)
     }
Index: /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy	(revision 10836)
+++ /trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy	(revision 10837)
@@ -14,4 +14,11 @@
 import org.openstreetmap.josm.gui.mappaint.Environment
 import org.openstreetmap.josm.gui.mappaint.MultiCascade
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.ClassCondition
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyCondition
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyMatchType
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyValueCondition
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.Op
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.PseudoClassCondition
+import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.SimpleKeyValueCondition
 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser
 import org.openstreetmap.josm.tools.ColorHelper
@@ -50,8 +57,8 @@
     public void testClassCondition() throws Exception {
         def conditions = ((Selector.GeneralSelector) getParser("way[name=X].highway:closed").selector()).conds
-        assert conditions.get(0) instanceof Condition.SimpleKeyValueCondition
+        assert conditions.get(0) instanceof SimpleKeyValueCondition
         assert conditions.get(0).applies(getEnvironment("name", "X"))
-        assert conditions.get(1) instanceof Condition.ClassCondition
-        assert conditions.get(2) instanceof Condition.PseudoClassCondition
+        assert conditions.get(1) instanceof ClassCondition
+        assert conditions.get(2) instanceof PseudoClassCondition
         assert !conditions.get(2).applies(getEnvironment("name", "X"))
     }
@@ -93,6 +100,6 @@
     @Test
     public void testEqualCondition() throws Exception {
-        def condition = (Condition.SimpleKeyValueCondition) getParser("[surface=paved]").condition(Condition.Context.PRIMITIVE)
-        assert condition instanceof Condition.SimpleKeyValueCondition
+        def condition = (SimpleKeyValueCondition) getParser("[surface=paved]").condition(Condition.Context.PRIMITIVE)
+        assert condition instanceof SimpleKeyValueCondition
         assert "surface".equals(condition.k)
         assert "paved".equals(condition.v)
@@ -103,6 +110,6 @@
     @Test
     public void testNotEqualCondition() throws Exception {
-        def condition = (Condition.KeyValueCondition) getParser("[surface!=paved]").condition(Condition.Context.PRIMITIVE)
-        assert Condition.Op.NEQ.equals(condition.op)
+        def condition = (KeyValueCondition) getParser("[surface!=paved]").condition(Condition.Context.PRIMITIVE)
+        assert Op.NEQ.equals(condition.op)
         assert !condition.applies(getEnvironment("surface", "paved"))
         assert condition.applies(getEnvironment("surface", "unpaved"))
@@ -111,6 +118,6 @@
     @Test
     public void testRegexCondition() throws Exception {
-        def condition = (Condition.KeyValueCondition) getParser("[surface=~/paved|unpaved/]").condition(Condition.Context.PRIMITIVE)
-        assert Condition.Op.REGEX.equals(condition.op)
+        def condition = (KeyValueCondition) getParser("[surface=~/paved|unpaved/]").condition(Condition.Context.PRIMITIVE)
+        assert Op.REGEX.equals(condition.op)
         assert condition.applies(getEnvironment("surface", "unpaved"))
         assert !condition.applies(getEnvironment("surface", "grass"))
@@ -119,5 +126,5 @@
     @Test
     public void testRegexConditionParenthesis() throws Exception {
-        def condition = (Condition.KeyValueCondition) getParser("[name =~ /^\\(foo\\)/]").condition(Condition.Context.PRIMITIVE)
+        def condition = (KeyValueCondition) getParser("[name =~ /^\\(foo\\)/]").condition(Condition.Context.PRIMITIVE)
         assert condition.applies(getEnvironment("name", "(foo)"))
         assert !condition.applies(getEnvironment("name", "foo"))
@@ -127,6 +134,6 @@
     @Test
     public void testNegatedRegexCondition() throws Exception {
-        def condition = (Condition.KeyValueCondition) getParser("[surface!~/paved|unpaved/]").condition(Condition.Context.PRIMITIVE)
-        assert Condition.Op.NREGEX.equals(condition.op)
+        def condition = (KeyValueCondition) getParser("[surface!~/paved|unpaved/]").condition(Condition.Context.PRIMITIVE)
+        assert Op.NREGEX.equals(condition.op)
         assert !condition.applies(getEnvironment("surface", "unpaved"))
         assert condition.applies(getEnvironment("surface", "grass"))
@@ -135,11 +142,11 @@
     @Test
     public void testBeginsEndsWithCondition() throws Exception {
-        def condition = (Condition.KeyValueCondition) getParser('[foo ^= bar]').condition(Condition.Context.PRIMITIVE)
-        assert Condition.Op.BEGINS_WITH.equals(condition.op)
+        def condition = (KeyValueCondition) getParser('[foo ^= bar]').condition(Condition.Context.PRIMITIVE)
+        assert Op.BEGINS_WITH.equals(condition.op)
         assert condition.applies(getEnvironment("foo", "bar123"))
         assert !condition.applies(getEnvironment("foo", "123bar"))
         assert !condition.applies(getEnvironment("foo", "123bar123"))
-        condition = (Condition.KeyValueCondition) getParser('[foo $= bar]').condition(Condition.Context.PRIMITIVE)
-        assert Condition.Op.ENDS_WITH.equals(condition.op)
+        condition = (KeyValueCondition) getParser('[foo $= bar]').condition(Condition.Context.PRIMITIVE)
+        assert Op.ENDS_WITH.equals(condition.op)
         assert !condition.applies(getEnvironment("foo", "bar123"))
         assert condition.applies(getEnvironment("foo", "123bar"))
@@ -158,10 +165,10 @@
     @Test
     public void testStandardKeyCondition() throws Exception {
-        def c1 = (Condition.KeyCondition) getParser("[ highway ]").condition(Condition.Context.PRIMITIVE)
-        assert Condition.KeyMatchType.EQ.equals(c1.matchType)
+        def c1 = (KeyCondition) getParser("[ highway ]").condition(Condition.Context.PRIMITIVE)
+        assert KeyMatchType.EQ.equals(c1.matchType)
         assert c1.applies(getEnvironment("highway", "unclassified"))
         assert !c1.applies(getEnvironment("railway", "rail"))
-        def c2 = (Condition.KeyCondition) getParser("[\"/slash/\"]").condition(Condition.Context.PRIMITIVE)
-        assert Condition.KeyMatchType.EQ.equals(c2.matchType)
+        def c2 = (KeyCondition) getParser("[\"/slash/\"]").condition(Condition.Context.PRIMITIVE)
+        assert KeyMatchType.EQ.equals(c2.matchType)
         assert c2.applies(getEnvironment("/slash/", "yes"))
         assert !c2.applies(getEnvironment("\"slash\"", "no"))
@@ -170,8 +177,8 @@
     @Test
     public void testYesNoKeyCondition() throws Exception {
-        def c1 = (Condition.KeyCondition) getParser("[oneway?]").condition(Condition.Context.PRIMITIVE)
-        def c2 = (Condition.KeyCondition) getParser("[oneway?!]").condition(Condition.Context.PRIMITIVE)
-        def c3 = (Condition.KeyCondition) getParser("[!oneway?]").condition(Condition.Context.PRIMITIVE)
-        def c4 = (Condition.KeyCondition) getParser("[!oneway?!]").condition(Condition.Context.PRIMITIVE)
+        def c1 = (KeyCondition) getParser("[oneway?]").condition(Condition.Context.PRIMITIVE)
+        def c2 = (KeyCondition) getParser("[oneway?!]").condition(Condition.Context.PRIMITIVE)
+        def c3 = (KeyCondition) getParser("[!oneway?]").condition(Condition.Context.PRIMITIVE)
+        def c4 = (KeyCondition) getParser("[!oneway?!]").condition(Condition.Context.PRIMITIVE)
         def yes = getEnvironment("oneway", "yes")
         def no = getEnvironment("oneway", "no")
@@ -193,6 +200,6 @@
     @Test
     public void testRegexKeyCondition() throws Exception {
-        def c1 = (Condition.KeyCondition) getParser("[/.*:(backward|forward)\$/]").condition(Condition.Context.PRIMITIVE)
-        assert Condition.KeyMatchType.REGEX.equals(c1.matchType)
+        def c1 = (KeyCondition) getParser("[/.*:(backward|forward)\$/]").condition(Condition.Context.PRIMITIVE)
+        assert KeyMatchType.REGEX.equals(c1.matchType)
         assert !c1.applies(getEnvironment("lanes", "3"))
         assert c1.applies(getEnvironment("lanes:forward", "3"))
@@ -214,5 +221,5 @@
     @Test
     public void testKeyKeyCondition() throws Exception {
-        def c1 = (Condition.KeyValueCondition) getParser("[foo = *bar]").condition(Condition.Context.PRIMITIVE)
+        def c1 = (KeyValueCondition) getParser("[foo = *bar]").condition(Condition.Context.PRIMITIVE)
         def w1 = new Way()
         w1.put("foo", "123")
@@ -221,5 +228,5 @@
         w1.put("bar", "123")
         assert c1.applies(new Environment(w1))
-        def c2 = (Condition.KeyValueCondition) getParser("[foo =~ */bar/]").condition(Condition.Context.PRIMITIVE)
+        def c2 = (KeyValueCondition) getParser("[foo =~ */bar/]").condition(Condition.Context.PRIMITIVE)
         def w2 = new Way(w1)
         w2.put("bar", "[0-9]{3}")
