Changeset 15935 in josm for trunk/src/org


Ignore:
Timestamp:
2020-02-26T01:52:19+01:00 (5 years ago)
Author:
simon04
Message:

see #18749, see #16183 - Add non-regression test

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    r15910 r15935  
    702702                    <PLUS> { type = Selector.ChildOrParentSelectorType.SIBLING; }
    703703                )
    704                 ( ( c=condition(Context.LINK) | c=class_or_pseudoclass(Context.LINK) ) { conditions.add(c); } )*
     704                ( ( c=condition(Context.LINK) | c=class_or_pseudoclass(Context.LINK) ) { if (c!= null) conditions.add(c); } )*
    705705            |
    706706                <SUBSET_OR_EQUAL> { type = Selector.ChildOrParentSelectorType.SUBSET_OR_EQUAL; }
     
    735735    ( base=<IDENT> | base=<STAR> )
    736736    ( r=zoom() )?
    737     ( ( c=condition(Context.PRIMITIVE) | c=class_or_pseudoclass(Context.PRIMITIVE) ) { conditions.add(c); } )*
     737    ( ( c=condition(Context.PRIMITIVE) | c=class_or_pseudoclass(Context.PRIMITIVE) ) { if (c!= null) conditions.add(c); } )*
    738738    ( sub=subpart() )?
    739739    { return new GeneralSelector(base.image, r, conditions, sub); }
     
    887887    )
    888888    s=ident()
    889     { return pseudo
    890         ? ConditionFactory.createPseudoClassCondition(s, not, context)
    891         : ConditionFactory.createClassCondition(s, not, context); }
     889    {
     890        if (pseudo && sheet != null && sheet.isRemoveAreaStylePseudoClass() && s.matches("areaStyle|area-style|area_style")) {
     891            Logging.warn("Removing 'areaStyle' pseudo-class. This class is only meant for validator");
     892            return null;
     893        } else if (pseudo) {
     894            return ConditionFactory.createPseudoClassCondition(s, not, context);
     895        } else {
     896            return ConditionFactory.createClassCondition(s, not, context);
     897        }
     898    }
    892899}
    893900
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r15731 r15935  
    5555import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyMatchType;
    5656import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyValueCondition;
    57 import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.PseudoClassCondition;
    5857import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.SimpleKeyValueCondition;
    59 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.AbstractSelector;
    6058import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector;
    6159import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector;
     
    119117    private ZipFile zipFile;
    120118
     119    private boolean removeAreaStylePseudoClass;
     120
    121121    /**
    122122     * This lock prevents concurrent execution of {@link MapCSSRuleIndex#clear() } /
     
    430430            multipolygonRules.clear();
    431431            canvasRules.clear();
     432            // remove "areaStyle" pseudo classes intended only for validator (causes StackOverflowError otherwise), see #16183
     433            removeAreaStylePseudoClass = true;
    432434            try (InputStream in = getSourceInputStream()) {
    433435                try (Reader reader = new BufferedReader(UTFInputStreamReader.create(in))) {
     
    445447                        loadSettings();
    446448                    }
    447                     // remove "areaStyle" pseudo classes intended only for validator (causes StackOverflowError otherwise)
    448                     removeAreaStyleClasses();
    449449                } finally {
    450450                    closeSourceInputStream(in);
     
    770770
    771771    /**
    772      * Removes "areaStyle" pseudo-classes. Only needed for validator.
    773      * @since 13633
    774      */
    775     public void removeAreaStyleClasses() {
    776         for (Iterator<MapCSSRule> it = rules.iterator(); it.hasNext();) {
    777             removeAreaStyleClasses(it.next().selector);
    778         }
    779     }
    780 
    781     private static void removeAreaStyleClasses(Selector sel) {
    782         if (sel instanceof ChildOrParentSelector) {
    783             removeAreaStyleClasses((ChildOrParentSelector) sel);
    784         } else if (sel instanceof AbstractSelector) {
    785             removeAreaStyleClasses((AbstractSelector) sel);
    786         }
    787     }
    788 
    789     private static void removeAreaStyleClasses(ChildOrParentSelector sel) {
    790         removeAreaStyleClasses(sel.left);
    791         removeAreaStyleClasses(sel.right);
    792     }
    793 
    794     private static void removeAreaStyleClasses(AbstractSelector sel) {
    795         if (sel.conds != null) {
    796             for (Iterator<Condition> it = sel.conds.iterator(); it.hasNext();) {
    797                 Condition c = it.next();
    798                 if (c instanceof PseudoClassCondition) {
    799                     PseudoClassCondition cc = (PseudoClassCondition) c;
    800                     if ("areaStyle".equals(cc.method.getName())) {
    801                         Logging.warn("Removing 'areaStyle' pseudo-class from "+sel+". This class is only meant for validator");
    802                         it.remove();
    803                     }
    804                 }
    805             }
    806         }
     772     * Whether to remove "areaStyle" pseudo classes. Only for use in MapCSSParser!
     773     * @return whether to remove "areaStyle" pseudo classes
     774     */
     775    public boolean isRemoveAreaStylePseudoClass() {
     776        return removeAreaStylePseudoClass;
    807777    }
    808778
Note: See TracChangeset for help on using the changeset viewer.