Ignore:
Timestamp:
2014-01-03T17:14:36+01:00 (10 years ago)
Author:
simon04
Message:

see #9516 - Replace BuildingInBuilding by a corresponding MapCSS test

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Environment.java

    r6601 r6611  
    215215        index = null;
    216216    }
     217
     218    public Cascade getCascade(String layer) {
     219        return mc == null ? null : mc.getCascade(layer == null ? this.layer : layer);
     220    }
    217221}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r6601 r6611  
    291291        @Override
    292292        public boolean applies(Environment env) {
    293             return env != null && env.mc != null && env.mc.getCascade(env.layer) != null && not ^ env.mc.getCascade(env.layer).containsKey(id);
     293            return env != null && env.getCascade(env.layer) != null && not ^ env.getCascade(env.layer).containsKey(id);
    294294        }
    295295
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r6610 r6611  
    55
    66import java.awt.Color;
     7import java.lang.annotation.ElementType;
     8import java.lang.annotation.Retention;
     9import java.lang.annotation.RetentionPolicy;
     10import java.lang.annotation.Target;
    711import java.lang.reflect.Array;
    812import java.lang.reflect.InvocationTargetException;
     
    3034 */
    3135public final class ExpressionFactory {
     36
     37    /**
     38     * Marks functions which should be executed also when one or more arguments are null.
     39     */
     40    @Target(ElementType.METHOD)
     41    @Retention(RetentionPolicy.RUNTIME)
     42    static @interface NullableArguments {}
    3243
    3344    private static final List<Method> arrayFunctions;
     
    146157
    147158        /**
     159         * Returns the first non-null object. The name originates from the {@code COALESCE} SQL function.
     160         * @see Utils#firstNonNull(Object[])
     161         */
     162        @NullableArguments
     163        public static Object coalesce(Object... args) {
     164            return Utils.firstNonNull(args);
     165        }
     166
     167        /**
    148168         * Get the {@code n}th element of the list {@code lst} (counting starts at 0).
    149169         * @since 5699
     
    221241         * Assembles the strings to one.
    222242         */
     243        @NullableArguments
    223244        public static String concat(Object... args) {
    224245            StringBuilder res = new StringBuilder();
    225246            for (Object f : args) {
    226                 res.append(f.toString());
     247                res.append(String.valueOf(f));
    227248            }
    228249            return res.toString();
     
    240261         */
    241262        public Object prop(String key, String layer) {
    242             Cascade c;
    243             if (layer == null) {
    244                 c = env.mc.getCascade(env.layer);
    245             } else {
    246                 c = env.mc.getCascade(layer);
    247             }
    248             return c.get(key);
     263            return env.getCascade(layer).get(key);
    249264        }
    250265
     
    260275         */
    261276        public Boolean is_prop_set(String key, String layer) {
    262             Cascade c;
    263             if (layer == null) {
    264                 // env.layer is null if expression is evaluated
    265                 // in ExpressionCondition, but MultiCascade.getCascade
    266                 // handles this
    267                 c = env.mc.getCascade(env.layer);
    268             } else {
    269                 c = env.mc.getCascade(layer);
    270             }
    271             return c.containsKey(key);
     277            return env.getCascade(layer).containsKey(key);
    272278        }
    273279
     
    650656            for (int i = 0; i < args.size(); ++i) {
    651657                convertedArgs[i] = Cascade.convertTo(args.get(i).evaluate(env), expectedParameterTypes[i]);
    652                 if (convertedArgs[i] == null) {
     658                if (convertedArgs[i] == null && m.getAnnotation(NullableArguments.class) == null) {
    653659                    return null;
    654660                }
     
    696702            for (int i = 0; i < args.size(); ++i) {
    697703                Object o = Cascade.convertTo(args.get(i).evaluate(env), arrayComponentType);
    698                 if (o == null) {
     704                if (o == null && m.getAnnotation(NullableArguments.class) == null) {
    699705                    return null;
    700706                }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java

    r6070 r6611  
    3131        public final String key;
    3232        public final Object val;
     33        public final boolean isSetInstruction;
    3334
    34         public AssignmentInstruction(String key, Object val) {
     35        public AssignmentInstruction(String key, Object val, boolean isSetInstruction) {
    3536            this.key = key;
     37            this.isSetInstruction = isSetInstruction;
    3638            if (val instanceof LiteralExpression) {
    3739                Object litValue = ((LiteralExpression) val).evaluate(null);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    r6609 r6611  
    472472            key=<IDENT> w()
    473473            ( <EQUAL> val=expression() )?
    474             { ins.add(new Instruction.AssignmentInstruction(key.image, val == null ? true : val)); }
     474            { ins.add(new Instruction.AssignmentInstruction(key.image, val == null ? true : val, true)); }
    475475            ( <RBRACE> { return ins; } | <SEMICOLON> w() )
    476476        )
     
    480480            LOOKAHEAD( float_array() w() ( <SEMICOLON> | <RBRACE> ) )
    481481                val=float_array()
    482                 { ins.add(new Instruction.AssignmentInstruction(key.image, val)); }
     482                { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); }
    483483                w()
    484484                ( <RBRACE> { return ins; } | <SEMICOLON> w() )
     
    486486            LOOKAHEAD( expression() ( <SEMICOLON> | <RBRACE> ) )
    487487                val=expression()
    488                 { ins.add(new Instruction.AssignmentInstruction(key.image, val)); }
     488                { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); }
    489489                ( <RBRACE> { return ins; } | <SEMICOLON> w() )
    490490            |
    491                 val=readRaw() w() { ins.add(new Instruction.AssignmentInstruction(key.image, val)); }
     491                val=readRaw() w() { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); }
    492492        )
    493493    )*
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r6609 r6611  
    160160            @Override
    161161            public void visit(Node n) {
    162                 if (e.parent == null && right.matches(e.withPrimitive(n))) {
     162                if (e.child == null && left.matches(e.withPrimitive(n))) {
    163163                    if (e.osm instanceof Way && Geometry.nodeInsidePolygon(n, ((Way) e.osm).getNodes())
    164164                            || e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon() && Geometry.isNodeInsideMultiPolygon(n, (Relation) e.osm, null)) {
    165                         e.parent = n;
     165                        e.child = n;
    166166                    }
    167167                }
     
    170170            @Override
    171171            public void visit(Way w) {
    172                 if (e.parent == null && right.matches(e.withPrimitive(w))) {
     172                if (e.child == null && left.matches(e.withPrimitive(w))) {
    173173                    if (e.osm instanceof Way && Geometry.PolygonIntersection.FIRST_INSIDE_SECOND.equals(Geometry.polygonIntersection(w.getNodes(), ((Way) e.osm).getNodes()))
    174174                            || e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon() && Geometry.isPolygonInsideMultiPolygon(w.getNodes(), (Relation) e.osm, null)) {
    175                         e.parent = w;
     175                        e.child = w;
    176176                    }
    177177                }
     
    184184            public void visit(Collection<? extends OsmPrimitive> primitives) {
    185185                for (OsmPrimitive p : primitives) {
    186                     if (e.parent != null) {
     186                    if (e.child != null) {
    187187                        // abort if first match has been found
    188188                        break;
     
    206206                    return false;
    207207                }
    208                 e.child = e.osm;
     208                e.parent = e.osm;
    209209
    210210                final ContainsFinder containsFinder = new ContainsFinder(e);
     
    221221                }
    222222
    223                 return e.parent != null;
     223                return e.child != null;
    224224
    225225            } else if (ChildOrParentSelectorType.CHILD.equals(type)) {
     
    374374
    375375        public boolean matchesBase(OsmPrimitiveType type) {
    376             if (OsmPrimitiveType.NODE.equals(type)) {
    377                 return base.equals("node") || base.equals("*");
     376            if (base.equals("*")) {
     377                return true;
     378            } else if (OsmPrimitiveType.NODE.equals(type)) {
     379                return base.equals("node");
    378380            } else if (OsmPrimitiveType.WAY.equals(type)) {
    379                 return base.equals("way") || base.equals("area") || base.equals("*");
     381                return base.equals("way") || base.equals("area");
    380382            } else if (OsmPrimitiveType.RELATION.equals(type)) {
    381383                return base.equals("area") || base.equals("relation") || base.equals("canvas");
Note: See TracChangeset for help on using the changeset viewer.