Changeset 13633 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2018-04-15T16:21:00+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #16183 - automatically remove "areaStyle" pseudo-classes from map paint styles. This class only works for validator rules.

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

Legend:

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

    r13597 r13633  
    1616import java.util.HashMap;
    1717import java.util.HashSet;
    18 import java.util.Iterator;
    1918import java.util.LinkedHashMap;
    2019import java.util.LinkedHashSet;
     
    376375            parser.sheet(source);
    377376            // Ignore "meta" rule(s) from external rules of JOSM wiki
    378             removeMetaRules(source);
     377            source.removeMetaRules();
    379378            // group rules with common declaration block
    380379            Map<Declaration, List<Selector>> g = new LinkedHashMap<>();
     
    399398            }
    400399            return new ParseResult(parseChecks, source.getErrors());
    401         }
    402 
    403         private static void removeMetaRules(MapCSSStyleSource source) {
    404             for (Iterator<MapCSSRule> it = source.rules.iterator(); it.hasNext();) {
    405                 MapCSSRule x = it.next();
    406                 if (x.selector instanceof GeneralSelector) {
    407                     GeneralSelector gs = (GeneralSelector) x.selector;
    408                     if ("meta".equals(gs.base)) {
    409                         it.remove();
    410                     }
    411                 }
    412             }
    413400        }
    414401
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r13561 r13633  
    4949import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyValueCondition;
    5050import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.Op;
     51import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.PseudoClassCondition;
    5152import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.SimpleKeyValueCondition;
     53import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.AbstractSelector;
    5254import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector;
    5355import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector;
     
    434436                    loadCanvas();
    435437                    loadSettings();
     438                    // remove "areaStyle" pseudo classes intended only for validator (causes StackOverflowError otherwise)
     439                    removeAreaStyleClasses();
    436440                } finally {
    437441                    closeSourceInputStream(in);
     
    715719    }
    716720
     721    /**
     722     * Removes "meta" rules. Not needed for validator.
     723     * @since 13633
     724     */
     725    public void removeMetaRules() {
     726        for (Iterator<MapCSSRule> it = rules.iterator(); it.hasNext();) {
     727            MapCSSRule x = it.next();
     728            if (x.selector instanceof GeneralSelector) {
     729                GeneralSelector gs = (GeneralSelector) x.selector;
     730                if ("meta".equals(gs.base)) {
     731                    it.remove();
     732                }
     733            }
     734        }
     735    }
     736
     737    /**
     738     * Removes "areaStyle" pseudo-classes. Only needed for validator.
     739     * @since 13633
     740     */
     741    public void removeAreaStyleClasses() {
     742        for (Iterator<MapCSSRule> it = rules.iterator(); it.hasNext();) {
     743            removeAreaStyleClasses(it.next().selector);
     744        }
     745    }
     746
     747    private static void removeAreaStyleClasses(Selector sel) {
     748        if (sel instanceof ChildOrParentSelector) {
     749            removeAreaStyleClasses((ChildOrParentSelector) sel);
     750        } else if (sel instanceof AbstractSelector) {
     751            removeAreaStyleClasses((AbstractSelector) sel);
     752        }
     753    }
     754
     755    private static void removeAreaStyleClasses(ChildOrParentSelector sel) {
     756        removeAreaStyleClasses(sel.left);
     757        removeAreaStyleClasses(sel.right);
     758    }
     759
     760    private static void removeAreaStyleClasses(AbstractSelector sel) {
     761        if (sel.conds != null) {
     762            for (Iterator<Condition> it = sel.conds.iterator(); it.hasNext();) {
     763                Condition c = it.next();
     764                if (c instanceof PseudoClassCondition) {
     765                    PseudoClassCondition cc = (PseudoClassCondition) c;
     766                    if ("areaStyle".equals(cc.method.getName())) {
     767                        Logging.warn("Removing 'areaStyle' pseudo-class from "+sel+". This class is only meant for validator");
     768                        it.remove();
     769                    }
     770                }
     771            }
     772        }
     773    }
     774
    717775    @Override
    718776    public String toString() {
Note: See TracChangeset for help on using the changeset viewer.