Search in sources :

Example 6 with Token

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;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) ArrayMap(android.support.v4.util.ArrayMap) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) Token(com.taobao.weex.el.parse.Token) HashMap(java.util.HashMap) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map)

Example 7 with Token

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;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) Token(com.taobao.weex.el.parse.Token)

Example 8 with Token

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");
    }
}
Also used : Token(com.taobao.weex.el.parse.Token) JSONObject(com.alibaba.fastjson.JSONObject) Parser(com.taobao.weex.el.parse.Parser)

Example 9 with Token

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");
}
Also used : Token(com.taobao.weex.el.parse.Token)

Example 10 with Token

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;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson.JSONArray) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) Token(com.taobao.weex.el.parse.Token)

Aggregations

Token (com.taobao.weex.el.parse.Token)10 JSONObject (com.alibaba.fastjson.JSONObject)7 WXDomObject (com.taobao.weex.dom.WXDomObject)4 ArrayMap (android.support.v4.util.ArrayMap)3 JSONArray (com.alibaba.fastjson.JSONArray)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 WXAttr (com.taobao.weex.dom.WXAttr)1 WXStatement (com.taobao.weex.dom.binding.WXStatement)1 ArrayStack (com.taobao.weex.el.parse.ArrayStack)1 Parser (com.taobao.weex.el.parse.Parser)1 WXComponent (com.taobao.weex.ui.component.WXComponent)1 WXVContainer (com.taobao.weex.ui.component.WXVContainer)1 WXRecyclerTemplateList (com.taobao.weex.ui.component.list.template.WXRecyclerTemplateList)1 Collection (java.util.Collection)1 List (java.util.List)1