use of com.taobao.weex.el.parse.Token in project incubator-weex by apache.
the class Statements method renderProps.
public static Map<String, Object> renderProps(JSONObject props, ArrayStack stack) {
Set<Map.Entry<String, Object>> entrySet = props.entrySet();
Map<String, Object> renderProps = new ArrayMap<>(4);
for (Map.Entry<String, Object> entry : entrySet) {
Object value = entry.getValue();
String key = entry.getKey();
if (value instanceof JSONObject && (((JSONObject) value).get(ELUtils.BINDING) instanceof Token)) {
JSONObject binding = (JSONObject) value;
Token block = (Token) (binding.get(ELUtils.BINDING));
Object blockValue = block.execute(stack);
renderProps.put(key, blockValue);
} else {
renderProps.put(key, value);
}
}
return renderProps;
}
use of com.taobao.weex.el.parse.Token in project incubator-weex by apache.
the class ELUtils method bindingBlock.
/**
* parse binding code to block, enable fast execute
*/
public static Object bindingBlock(Object value) {
if (value instanceof JSONObject) {
JSONObject object = (JSONObject) value;
if (object.containsKey(BINDING)) {
Object binding = object.get(BINDING);
if (!(binding instanceof Token)) {
object.put(BINDING, Parser.parse(binding.toString()));
}
}
Set<String> keys = object.keySet();
for (Object propsKey : keys) {
if (object.get(propsKey) instanceof JSONObject && ((JSONObject) object.get(propsKey)).containsKey(BINDING)) {
JSONObject propsValue = (JSONObject) object.get(propsKey);
Object binding = propsValue.get(BINDING);
if (!(binding instanceof Token)) {
propsValue.put(BINDING, Parser.parse(binding.toString()));
}
}
}
} else if (value instanceof JSONArray) {
JSONArray array = (JSONArray) value;
for (int i = 0; i < array.size(); i++) {
bindingBlock(array.get(i));
}
}
return value;
}
use of com.taobao.weex.el.parse.Token in project incubator-weex by apache.
the class ParserTest method testOperator.
public void testOperator() {
Parser parser = new Parser("(1 + 3)/3*3");
Token block = parser.parse();
System.out.println(block.execute(null));
System.out.println(block);
Parser parser2 = new Parser("1 + +++");
block = parser2.parse();
System.out.println(block);
String[] values = { null, null };
for (Object value : values) {
System.out.println(value + "ddd");
}
}
use of com.taobao.weex.el.parse.Token in project incubator-weex by apache.
the class ParserTest method testDebug.
public void testDebug() {
System.out.println("execute " + Parser.parse("true ? false : item.name").execute(this.createContext()));
show("true ? false : true xxxx");
show("true ? false : ((item.name))");
Parser.parse("item[1]").execute(this.createContext());
Token block = Parser.parse("{{{item.name}}}");
show("true ? item.name : false");
show("((true) && 2 > 1) && (1) && (1)");
System.out.println(block.execute(createContext()) + " " + Double.parseDouble(".0e6"));
show("1 > -1");
}
use of com.taobao.weex.el.parse.Token in project incubator-weex by apache.
the class Statements method getBindingEventArgs.
public static List<Object> getBindingEventArgs(ArrayStack stack, Object bindings) {
List<Object> params = new ArrayList<>(4);
if (bindings instanceof JSONArray) {
JSONArray array = (JSONArray) bindings;
for (int i = 0; i < array.size(); i++) {
Object value = array.get(i);
if (value instanceof JSONObject && (((JSONObject) value).get(ELUtils.BINDING) instanceof Token)) {
Token block = (Token) (((JSONObject) value).get(ELUtils.BINDING));
Object blockValue = block.execute(stack);
params.add(blockValue);
} else {
params.add(value);
}
}
} else if (bindings instanceof JSONObject) {
JSONObject binding = (JSONObject) bindings;
if (binding.get(ELUtils.BINDING) instanceof Token) {
Token block = (Token) binding.get(ELUtils.BINDING);
Object blockValue = block.execute(stack);
params.add(blockValue);
} else {
params.add(bindings.toString());
}
} else {
params.add(bindings.toString());
}
return params;
}
Aggregations