Changeset 7881 in josm for trunk/src/org


Ignore:
Timestamp:
2014-12-24T15:30:06+01:00 (9 years ago)
Author:
Don-vip
Message:

fix regression caused by optimization done in r7879

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

Legend:

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

    r7879 r7881  
    1414import java.util.Collections;
    1515import java.util.HashMap;
     16import java.util.HashSet;
    1617import java.util.Iterator;
    1718import java.util.LinkedHashMap;
     
    4243import org.openstreetmap.josm.gui.mappaint.MultiCascade;
    4344import org.openstreetmap.josm.gui.mappaint.mapcss.Condition;
     45import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.ClassCondition;
    4446import org.openstreetmap.josm.gui.mappaint.mapcss.Expression;
    4547import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
     
    4850import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    4951import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
     52import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.AbstractSelector;
    5053import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector;
    5154import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser;
     
    147150        protected final Map<Instruction.AssignmentInstruction, Severity> errors = new HashMap<>();
    148151        protected final Map<String, Boolean> assertions = new HashMap<>();
     152        protected final Set<String> setClassExpressions = new HashSet<>();
    149153        protected boolean deletion = false;
    150154
     
    207211        static TagCheck ofMapCSSRule(final GroupedMapCSSRule rule) throws IllegalDataException {
    208212            final TagCheck check = new TagCheck(rule);
    209             boolean containsSetClassExpression = false;
    210213            for (Instruction i : rule.declaration.instructions) {
    211214                if (i instanceof Instruction.AssignmentInstruction) {
    212215                    final Instruction.AssignmentInstruction ai = (Instruction.AssignmentInstruction) i;
    213216                    if (ai.isSetInstruction) {
    214                         containsSetClassExpression = true;
     217                        check.setClassExpressions.add(ai.key);
    215218                        continue;
    216219                    }
     
    263266                }
    264267            }
    265             if (check.errors.isEmpty() && !containsSetClassExpression) {
    266                 throw new IllegalDataException("No "+POSSIBLE_THROWS+" given! You should specify a validation error message for " + rule.selectors);
     268            if (check.errors.isEmpty() && check.setClassExpressions.isEmpty()) {
     269                throw new IllegalDataException(
     270                        "No "+POSSIBLE_THROWS+" given! You should specify a validation error message for " + rule.selectors);
    267271            } else if (check.errors.size() > 1) {
    268                 throw new IllegalDataException("More than one "+POSSIBLE_THROWS+" given! You should specify a single validation error message for " + rule.selectors);
     272                throw new IllegalDataException(
     273                        "More than one "+POSSIBLE_THROWS+" given! You should specify a single validation error message for "
     274                                + rule.selectors);
    269275            }
    270276            return check;
     
    506512                return null;
    507513            }
     514        }
     515
     516        /**
     517         * Returns the set of tagchecks on which this check depends on.
     518         * @param schecks the collection of tagcheks to search in
     519         * @return the set of tagchecks on which this check depends on
     520         * @since 7881
     521         */
     522        public Set<TagCheck> getTagCheckDependencies(Collection<TagCheck> schecks) {
     523            Set<TagCheck> result = new HashSet<MapCSSTagChecker.TagCheck>();
     524            Set<String> classes = getClassesIds();
     525            if (schecks != null && !classes.isEmpty()) {
     526                for (TagCheck tc : schecks) {
     527                    if (this.equals(tc)) {
     528                        continue;
     529                    }
     530                    for (String id : tc.setClassExpressions) {
     531                        if (classes.contains(id)) {
     532                            result.add(tc);
     533                            break;
     534                        }
     535                    }
     536                }
     537            }
     538            return result;
     539        }
     540
     541        /**
     542         * Returns the list of ids of all MapCSS classes referenced in the rule selectors.
     543         * @return the list of ids of all MapCSS classes referenced in the rule selectors
     544         * @since 7881
     545         */
     546        public Set<String> getClassesIds() {
     547            Set<String> result = new HashSet<>();
     548            for (Selector s : rule.selectors) {
     549                if (s instanceof AbstractSelector) {
     550                    for (Condition c : ((AbstractSelector)s).getConditions()) {
     551                        if (c instanceof ClassCondition) {
     552                            result.add(((ClassCondition) c).id);
     553                        }
     554                    }
     555                }
     556            }
     557            return result;
    508558        }
    509559    }
     
    654704                }
    655705                final OsmPrimitive p = OsmUtils.createPrimitive(i.getKey());
     706                // Build minimal ordered list of checks to run to test the assertion
     707                List<Set<TagCheck>> checksToRun = new ArrayList<Set<TagCheck>>();
     708                Set<TagCheck> checkDependencies = check.getTagCheckDependencies(schecks);
     709                if (!checkDependencies.isEmpty()) {
     710                    checksToRun.add(checkDependencies);
     711                }
     712                checksToRun.add(Collections.singleton(check));
    656713                // Add primitive to dataset to avoid DataIntegrityProblemException when evaluating selectors
    657714                ds.addPrimitive(p);
    658                 final Collection<TestError> pErrors = getErrorsForPrimitive(p, true,
    659                         Collections.singleton(Collections.singleton(check)));
     715                final Collection<TestError> pErrors = getErrorsForPrimitive(p, true, checksToRun);
    660716                if (Main.isDebugEnabled()) {
    661717                    Main.debug("- Errors: "+pErrors);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java

    r7397 r7881  
    8787        @Override
    8888        public String toString() {
    89             return key + ": " + (val instanceof float[] ? Arrays.toString((float[]) val) : val instanceof String ? "String<"+val+">" : val) + ';';
     89            return key + ": " + (val instanceof float[] ? Arrays.toString((float[]) val) :
     90                val instanceof String ? "String<"+val+">" : val) + ';';
    9091        }
    9192    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r7864 r7881  
    428428        }
    429429
     430        /**
     431         * Returns the list of conditions.
     432         * @return the list of conditions
     433         */
    430434        public List<Condition> getConditions() {
    431435            if (conds == null) {
Note: See TracChangeset for help on using the changeset viewer.