Changeset 7069 in josm for trunk


Ignore:
Timestamp:
2014-05-06T12:06:16+02:00 (10 years ago)
Author:
bastiK
Message:

see #9691 - fix broken MapCSSTagChecker unit test

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

Legend:

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

    r7064 r7069  
    3737import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
    3838import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;
     39import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule.Declaration;
    3940import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    4041import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
     
    4748import org.openstreetmap.josm.io.UTFInputStreamReader;
    4849import org.openstreetmap.josm.tools.CheckParameterUtil;
     50import org.openstreetmap.josm.tools.MultiMap;
    4951import org.openstreetmap.josm.tools.Predicate;
    5052import org.openstreetmap.josm.tools.Utils;
     
    5658public class MapCSSTagChecker extends Test.TagTest {
    5759
     60    public static class GroupedMapCSSRule {
     61        final public List<Selector> selectors;
     62        final public Declaration declaration;
     63
     64        public GroupedMapCSSRule(List<Selector> selectors, Declaration declaration) {
     65            this.selectors = selectors;
     66            this.declaration = declaration;
     67        }
     68    }
    5869    /**
    5970     * The preference key for tag checker source entries.
     
    7283
    7384    static class TagCheck implements Predicate<OsmPrimitive> {
    74         protected final MapCSSRule rule;
     85        protected final GroupedMapCSSRule rule;
    7586        protected final List<PrimitiveToTag> change = new ArrayList<>();
    7687        protected final Map<String, String> keyChange = new LinkedHashMap<>();
     
    7990        protected final Map<String, Boolean> assertions = new HashMap<>();
    8091
    81         TagCheck(MapCSSRule rule) {
     92        TagCheck(GroupedMapCSSRule rule) {
    8293            this.rule = rule;
    8394        }
     
    120131        }
    121132
    122         static TagCheck ofMapCSSRule(final MapCSSRule rule) {
     133        static TagCheck ofMapCSSRule(final GroupedMapCSSRule rule) {
    123134            final TagCheck check = new TagCheck(rule);
    124135            boolean containsSetClassExpression = false;
     
    161172            }
    162173            if (check.errors.isEmpty() && !containsSetClassExpression) {
    163                 throw new RuntimeException("No throwError/throwWarning/throwOther given! You should specify a validation error message for " + rule.selector);
     174                throw new RuntimeException("No throwError/throwWarning/throwOther given! You should specify a validation error message for " + rule.selectors);
    164175            } else if (check.errors.size() > 1) {
    165                 throw new RuntimeException("More than one throwError/throwWarning/throwOther given! You should specify a single validation error message for " + rule.selector);
     176                throw new RuntimeException("More than one throwError/throwWarning/throwOther given! You should specify a single validation error message for " + rule.selectors);
    166177            }
    167178            return check;
     
    180191            // Ignore "meta" rule(s) from external rules of JOSM wiki
    181192            removeMetaRules(source);
    182             return new ArrayList<>(Utils.transform(source.rules, new Utils.Function<MapCSSRule, TagCheck>() {
    183                 @Override
    184                 public TagCheck apply(MapCSSRule x) {
    185                     return TagCheck.ofMapCSSRule(x);
    186                 }
    187             }));
     193            // group rules with common declaration block
     194            MultiMap<MapCSSRule.Declaration, MapCSSRule> rules = new MultiMap<>();
     195            for (MapCSSRule rule : source.rules) {
     196                rules.put(rule.declaration, rule);
     197            }
     198            List<TagCheck> result = new ArrayList<>();
     199            for (Collection<MapCSSRule> rulesCommonDecl : rules.values()) {
     200                List<Selector> selectors = new ArrayList<>();
     201                for (MapCSSRule rule : rulesCommonDecl) {
     202                    selectors.add(rule.selector);
     203                }
     204                if (!rulesCommonDecl.isEmpty()) {
     205                    result.add(TagCheck.ofMapCSSRule(
     206                            new GroupedMapCSSRule(selectors, rulesCommonDecl.iterator().next().declaration)));
     207                }
     208            }
     209            return result;
    188210        }
    189211
     
    211233
    212234        Selector whichSelectorMatchesEnvironment(Environment env) {
    213             env.clearSelectorMatchingInformation();
    214             if (rule.selector.matches(env)) {
    215                 return rule.selector;
     235            for (Selector i : rule.selectors) {
     236                env.clearSelectorMatchingInformation();
     237                if (i.matches(env)) {
     238                    return i;
     239                }
    216240            }
    217241            return null;
     
    384408
    385409    static class MapCSSTagCheckerAndRule extends MapCSSTagChecker {
    386         public final MapCSSRule rule;
    387 
    388         MapCSSTagCheckerAndRule(MapCSSRule rule) {
     410        public final GroupedMapCSSRule rule;
     411
     412        MapCSSTagCheckerAndRule(GroupedMapCSSRule rule) {
    389413            this.rule = rule;
    390414        }
     
    394418            return super.equals(obj)
    395419                    || (obj instanceof TagCheck && rule.equals(((TagCheck) obj).rule))
    396                     || (obj instanceof MapCSSRule && rule.equals(obj));
     420                    || (obj instanceof GroupedMapCSSRule && rule.equals(obj));
    397421        }
    398422    }
     
    410434            final Selector selector = check.whichSelectorMatchesEnvironment(env);
    411435            if (selector != null) {
    412                 check.rule.execute(env);
     436                check.rule.declaration.execute(env);
    413437                final TestError error = check.getErrorForPrimitive(p, selector, env);
    414438                if (error != null) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Range.java

    r6986 r7069  
    88 */
    99public class Range {
    10     private double lower;
    11     private double upper;
     10    private final double lower;
     11    private final double upper;
    1212
    1313    public static final Range ZERO_TO_INFINITY = new Range(0.0, Double.POSITIVE_INFINITY);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r7055 r7069  
    173173            return new Tag(k, v);
    174174        }
     175
     176        @Override
     177        public String toString() {
     178            return '[' + k + '=' + v + ']';
     179        }
     180       
    175181    }
    176182
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java

    r7014 r7069  
    1111import org.openstreetmap.josm.gui.mappaint.StyleKeys;
    1212
    13 public abstract class Instruction implements StyleKeys {
     13public interface Instruction extends StyleKeys {
    1414
    15     public abstract void execute(Environment env);
     15    void execute(Environment env);
    1616
    1717    public static class RelativeFloat {
     
    2828    }
    2929
    30     public static class AssignmentInstruction extends Instruction {
     30    public static class AssignmentInstruction implements Instruction {
    3131        public final String key;
    3232        public final Object val;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSRule.java

    r7064 r7069  
    2121            this.idx = idx;
    2222        }
     23       
     24        /**
     25         * <p>Executes the instructions against the environment {@code env}</p>
     26         *
     27         * @param env the environment
     28         */
     29        public void execute(Environment env) {
     30            for (Instruction i : instructions) {
     31                i.execute(env);
     32            }
     33        }
    2334    }
    2435   
     
    3445     */
    3546    public void execute(Environment env) {
    36         for (Instruction i : declaration.instructions) {
    37             i.execute(env);
    38         }
     47        declaration.execute(env);
    3948    }
    4049
Note: See TracChangeset for help on using the changeset viewer.