Changeset 8331 in josm


Ignore:
Timestamp:
2015-05-05T22:08:03+02:00 (10 years ago)
Author:
simon04
Message:

fix #10278 - MapCSSTagChecker: preprocess MapCSS for media queries support

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r8318 r8331  
    88import java.io.InputStream;
    99import java.io.Reader;
     10import java.io.StringReader;
    1011import java.text.MessageFormat;
    1112import java.util.ArrayList;
     
    317318        static List<TagCheck> readMapCSS(Reader css) throws ParseException {
    318319            CheckParameterUtil.ensureParameterNotNull(css, "css");
    319             return readMapCSS(new MapCSSParser(css));
    320         }
    321 
    322         static List<TagCheck> readMapCSS(MapCSSParser css) throws ParseException {
    323             CheckParameterUtil.ensureParameterNotNull(css, "css");
     320
    324321            final MapCSSStyleSource source = new MapCSSStyleSource("");
    325             css.sheet(source);
     322            final MapCSSParser preprocessor = new MapCSSParser(css, MapCSSParser.LexicalState.PREPROCESSOR);
     323
     324            css = new StringReader(preprocessor.pp_root(source));
     325            final MapCSSParser parser = new MapCSSParser(css, MapCSSParser.LexicalState.DEFAULT);
     326            parser.sheet(source);
    326327            assert source.getErrors().isEmpty();
    327328            // Ignore "meta" rule(s) from external rules of JOSM wiki
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    r8260 r8331  
    99
    1010import java.io.InputStream;
     11import java.io.Reader;
    1112import java.util.ArrayList;
    1213import java.util.Arrays;
     
    8788            throw new RuntimeException(e);
    8889        }
     90        return new MapCSSParserTokenManager(scs, initState.idx);
     91    }
     92
     93    /**
     94     * Constructor which initializes the parser with a certain lexical state.
     95     */
     96    public MapCSSParser(Reader in, LexicalState initState) {
     97        this(createTokenManager(in, initState));
     98        declarationCounter = 0;
     99    }
     100
     101    protected static MapCSSParserTokenManager createTokenManager(Reader in, LexicalState initState) {
     102        final SimpleCharStream scs = new SimpleCharStream(in, 1, 1);
    89103        return new MapCSSParserTokenManager(scs, initState.idx);
    90104    }
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

    r8266 r8331  
    118118
    119119    @Test
     120    public void testPreprocessing() throws Exception {
     121        final MapCSSTagChecker test = buildTagChecker("" +
     122                "@media (min-josm-version: 1) { *[foo] { throwWarning: \"!\"; } }\n" +
     123                "@media (min-josm-version: 2147483647) { *[bar] { throwWarning: \"!\"; } }\n");
     124        assertThat(test.getErrorsForPrimitive(OsmUtils.createPrimitive("way foo=1"), false).size(), is(1));
     125        assertThat(test.getErrorsForPrimitive(OsmUtils.createPrimitive("way bar=1"), false).size(), is(0));
     126    }
     127
     128    @Test
    120129    public void testInit() throws Exception {
    121130        MapCSSTagChecker c = new MapCSSTagChecker();
Note: See TracChangeset for help on using the changeset viewer.