Ignore:
Timestamp:
2011-03-27T13:41:58+02:00 (15 years ago)
Author:
bastiK
Message:

see #6150 mapcss - extended functionality for instruction text: ... (patch by Gubaer)

File:
1 edited

Legend:

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

    r3980 r4007  
    1616import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
    1717import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
     18import org.openstreetmap.josm.data.osm.OsmPrimitive;
     19import org.openstreetmap.josm.data.osm.Relation;
    1820import org.openstreetmap.josm.gui.mappaint.Cascade;
    1921import org.openstreetmap.josm.gui.mappaint.Environment;
     22import org.openstreetmap.josm.tools.CheckParameterUtil;
    2023import org.openstreetmap.josm.tools.Utils;
    2124
    2225public interface Expression {
    23 
    2426    public Object evaluate(Environment env);
    2527
     
    2729        Object literal;
    2830
    29         public LiteralExpression(Object lit) {
    30             this.literal = lit;
     31        public LiteralExpression(Object literal) {
     32            CheckParameterUtil.ensureParameterNotNull(literal);
     33            this.literal = literal;
    3134        }
    3235
     
    3841        @Override
    3942        public String toString() {
    40             if (literal == null)
    41                 return "Lit{<null>}";
    4243            if (literal instanceof float[])
    4344                return Arrays.toString((float[]) literal);
     
    4748
    4849    public static class FunctionExpression implements Expression {
     50        //static Logger logger = Logger.getLogger(FunctionExpression.class.getName());
     51
    4952        String name;
    5053        List<Expression> args;
     
    7376                if (args.length == 0)
    7477                    return 0f;
    75                 if (args.length == 1) { // unary minus
     78                if (args.length == 1)
    7679                    return -args[0];
    77                 }
    7880                float res = args[0];
    7981                for (int i=1; i<args.length; ++i) {
     
    160162            }
    161163
    162             public String get_tag_value(String key) {
     164            public String tag(String key) {
    163165                return env.osm.get(key);
     166            }
     167
     168            // FIXME: respect parent selector chain
     169            public String parent_tag(String key) {
     170                for (Relation parent: OsmPrimitive.getFilteredList(env.osm.getReferrers(), Relation.class)) {
     171                    String value = parent.get(key);
     172                    if (value != null) return value;
     173                }
     174                return null;
    164175            }
    165176
     
    286297            }
    287298            for (Method m : allMethods) {
    288                 if (!m.getName().equals(name))
     299                if (!m.getName().equals(name)) {
    289300                    continue;
     301                }
    290302                Class<?>[] expectedParameterTypes = m.getParameterTypes();
    291303                Object[] convertedArgs = new Object[expectedParameterTypes.length];
     
    304316                    convertedArgs[0] = arrayArg;
    305317                } else {
    306                     if (args.size() != expectedParameterTypes.length)
     318                    if (args.size() != expectedParameterTypes.length) {
    307319                        continue;
     320                    }
    308321                    for (int i=0; i<args.size(); ++i) {
    309322                        convertedArgs[i] = Cascade.convertTo(args.get(i).evaluate(env), expectedParameterTypes[i]);
Note: See TracChangeset for help on using the changeset viewer.