Changeset 6513 in josm for trunk/src


Ignore:
Timestamp:
2013-12-23T00:13:58+01:00 (12 years ago)
Author:
simon04
Message:

see #9414 - convert some tagchecker tests to MapCSS, extend MapCSS by test for false values

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

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

    r6512 r6513  
    9999    }
    100100
     101    /**
     102     * This constructs a {@link Tag} by splitting {@code s} on the first equality sign.
     103     * @see org.openstreetmap.josm.tools.TextTagParser
     104     * @param s the string to convert
     105     * @return the constructed tag
     106     */
    101107    public static Tag ofString(String s) {
    102108        CheckParameterUtil.ensureParameterNotNull(s, "s");
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r6512 r6513  
    229229    public void initialize() throws Exception {
    230230        addMapCSS(new InputStreamReader(getClass().getResourceAsStream("/data/validator/deprecated.mapcss"), "UTF-8"));
     231        addMapCSS(new InputStreamReader(getClass().getResourceAsStream("/data/validator/highway.mapcss"), "UTF-8"));
    231232    }
    232233}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r6455 r6513  
    3838    }
    3939
    40     public static Condition create(String k, boolean not, boolean yes, Context context) {
     40    public static Condition create(String k, boolean not, boolean yes, boolean no, Context context) {
    4141        switch (context) {
    4242        case PRIMITIVE:
    43             return new KeyCondition(k, not, yes);
     43            return new KeyCondition(k, not, yes, no);
    4444        case LINK:
    45             if (yes)
     45            if (yes || no)
    4646                throw new MapCSSException("Question mark operator ''?'' not supported in LINK context");
    4747            if (not)
     
    216216     *     ["a label"?]  PRIMITIVE:  the primitive has a tag "a label" whose value evaluates to a true-value
    217217     *                   LINK:       not supported
     218     *
     219     *     ["a label"?!] PRIMITIVE:  the primitive has a tag "a label" whose value evaluates to a false-value
     220     *                   LINK:       not supported
    218221     * </pre>
    219222     */
     
    221224
    222225        private String label;
    223         private boolean exclamationMarkPresent;
    224         private boolean questionMarkPresent;
    225 
    226         /**
    227          *
    228          * @param label
    229          * @param exclamationMarkPresent
    230          * @param questionMarkPresent
    231          */
    232         public KeyCondition(String label, boolean exclamationMarkPresent, boolean questionMarkPresent){
     226        private boolean negateResult;
     227        private boolean testForTrueValues;
     228        private boolean testForFalseValues;
     229
     230        public KeyCondition(String label, boolean negateResult, boolean testForTrueValues, boolean testForFalseValues){
    233231            this.label = label;
    234             this.exclamationMarkPresent = exclamationMarkPresent;
    235             this.questionMarkPresent = questionMarkPresent;
     232            this.negateResult = negateResult;
     233            this.testForTrueValues = testForTrueValues;
     234            this.testForFalseValues = testForFalseValues;
    236235        }
    237236
     
    240239            switch(e.getContext()) {
    241240            case PRIMITIVE:
    242                 if (questionMarkPresent)
    243                     return OsmUtils.isTrue(e.osm.get(label)) ^ exclamationMarkPresent;
     241                if (testForTrueValues)
     242                    return OsmUtils.isTrue(e.osm.get(label)) ^ negateResult;
     243                else if (testForFalseValues)
     244                    return OsmUtils.isFalse(e.osm.get(label)) ^ negateResult;
    244245                else
    245                     return e.osm.hasKey(label) ^ exclamationMarkPresent;
     246                    return e.osm.hasKey(label) ^ negateResult;
    246247            case LINK:
    247248                Utils.ensure(false, "Illegal state: KeyCondition not supported in LINK context");
     
    253254        @Override
    254255        public String toString() {
    255             return "[" + (exclamationMarkPresent ? "!" : "") + label + "]";
     256            return "[" + (negateResult ? "!" : "") + label + "]";
    256257        }
    257258    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    r6455 r6513  
    345345    boolean not = false;
    346346    boolean yes = false;
     347    boolean no = false;
    347348    String key;
    348349}
     
    350351    ( <EXCLAMATION> { not = true; } )?
    351352    key=tag_key()
     353    ( LOOKAHEAD(2) <QUESTION> <EXCLAMATION> { no = true; } )?
    352354    ( <QUESTION> { yes = true; } )?
    353     { return Condition.create(key, not, yes, context); }
     355    { return Condition.create(key, not, yes, no, context); }
    354356}
    355357
Note: See TracChangeset for help on using the changeset viewer.