Changeset 4007 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Expression.java
- Timestamp:
- 2011-03-27T13:41:58+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Expression.java
r3980 r4007 16 16 import org.openstreetmap.josm.actions.search.SearchCompiler.Match; 17 17 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 import org.openstreetmap.josm.data.osm.Relation; 18 20 import org.openstreetmap.josm.gui.mappaint.Cascade; 19 21 import org.openstreetmap.josm.gui.mappaint.Environment; 22 import org.openstreetmap.josm.tools.CheckParameterUtil; 20 23 import org.openstreetmap.josm.tools.Utils; 21 24 22 25 public interface Expression { 23 24 26 public Object evaluate(Environment env); 25 27 … … 27 29 Object literal; 28 30 29 public LiteralExpression(Object lit) { 30 this.literal = lit; 31 public LiteralExpression(Object literal) { 32 CheckParameterUtil.ensureParameterNotNull(literal); 33 this.literal = literal; 31 34 } 32 35 … … 38 41 @Override 39 42 public String toString() { 40 if (literal == null)41 return "Lit{<null>}";42 43 if (literal instanceof float[]) 43 44 return Arrays.toString((float[]) literal); … … 47 48 48 49 public static class FunctionExpression implements Expression { 50 //static Logger logger = Logger.getLogger(FunctionExpression.class.getName()); 51 49 52 String name; 50 53 List<Expression> args; … … 73 76 if (args.length == 0) 74 77 return 0f; 75 if (args.length == 1) { // unary minus78 if (args.length == 1) 76 79 return -args[0]; 77 }78 80 float res = args[0]; 79 81 for (int i=1; i<args.length; ++i) { … … 160 162 } 161 163 162 public String get_tag_value(String key) {164 public String tag(String key) { 163 165 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; 164 175 } 165 176 … … 286 297 } 287 298 for (Method m : allMethods) { 288 if (!m.getName().equals(name)) 299 if (!m.getName().equals(name)) { 289 300 continue; 301 } 290 302 Class<?>[] expectedParameterTypes = m.getParameterTypes(); 291 303 Object[] convertedArgs = new Object[expectedParameterTypes.length]; … … 304 316 convertedArgs[0] = arrayArg; 305 317 } else { 306 if (args.size() != expectedParameterTypes.length) 318 if (args.size() != expectedParameterTypes.length) { 307 319 continue; 320 } 308 321 for (int i=0; i<args.size(); ++i) { 309 322 convertedArgs[i] = Cascade.convertTo(args.get(i).evaluate(env), expectedParameterTypes[i]);
Note:
See TracChangeset
for help on using the changeset viewer.
