Search in sources :

Example 1 with CollectionKey

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

the class StructKeyExists method execute.

@Override
public void execute(BIF bif, FunctionLibFunction flf) throws TemplateException {
    Argument arg = bif.getArguments()[1];
    Expression value = arg.getValue();
    if (value instanceof LitString) {
        String str = ((LitString) value).getString();
        // update first arg
        arg.setValue(new CollectionKey(bif.getFactory(), str), Collection.Key.class.getName());
    }
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Argument(lucee.transformer.bytecode.expression.var.Argument) Expression(lucee.transformer.expression.Expression) CollectionKey(lucee.transformer.bytecode.expression.type.CollectionKey) LitString(lucee.transformer.expression.literal.LitString) CollectionKey(lucee.transformer.bytecode.expression.type.CollectionKey)

Example 2 with CollectionKey

use of lucee.transformer.bytecode.expression.type.CollectionKey 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

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