Search in sources :

Example 1 with CollectionKeyArray

use of lucee.transformer.bytecode.expression.type.CollectionKeyArray in project Lucee by lucee.

the class IsDefined method execute.

@Override
public void execute(BIF bif, FunctionLibFunction flf) throws TemplateException {
    Argument arg = bif.getArguments()[0];
    Expression value = arg.getValue();
    if (value instanceof LitString) {
        String str = ((LitString) value).getString();
        StringList sl = VariableInterpreter.parse(str, false);
        if (sl != null) {
            // scope
            str = sl.next();
            int scope = VariableInterpreter.scopeString2Int(bif.ts.ignoreScopes, str);
            if (scope == Scope.SCOPE_UNDEFINED)
                sl.reset();
            // keys
            String[] arr = sl.toArray();
            ArrayUtil.trim(arr);
            // update first arg
            arg.setValue(bif.getFactory().createLitDouble(scope), "number");
            if (arr.length == 1) {
                // LitString.toExprString(str);
                Expression expr = new CollectionKey(bif.getFactory(), arr[0]);
                arg = new Argument(expr, Collection.Key.class.getName());
                bif.addArgument(arg);
            } else {
                CollectionKeyArray expr = new CollectionKeyArray(bif.getFactory(), arr);
                // LiteralStringArray expr = new LiteralStringArray(arr);
                arg = new Argument(expr, Collection.Key[].class.getName());
                bif.addArgument(arg);
            }
        }
    }
// print.out("bif:"+arg.getValue().getClass().getName());
}
Also used : LitString(lucee.transformer.expression.literal.LitString) CollectionKeyArray(lucee.transformer.bytecode.expression.type.CollectionKeyArray) Argument(lucee.transformer.bytecode.expression.var.Argument) Expression(lucee.transformer.expression.Expression) StringList(lucee.commons.lang.StringList) Collection(lucee.runtime.type.Collection) CollectionKey(lucee.transformer.bytecode.expression.type.CollectionKey) LitString(lucee.transformer.expression.literal.LitString) CollectionKey(lucee.transformer.bytecode.expression.type.CollectionKey)

Aggregations

StringList (lucee.commons.lang.StringList)1 Collection (lucee.runtime.type.Collection)1 CollectionKey (lucee.transformer.bytecode.expression.type.CollectionKey)1 CollectionKeyArray (lucee.transformer.bytecode.expression.type.CollectionKeyArray)1 Argument (lucee.transformer.bytecode.expression.var.Argument)1 Expression (lucee.transformer.expression.Expression)1 LitString (lucee.transformer.expression.literal.LitString)1