Search in sources :

Example 6 with VariableReference

use of lucee.runtime.type.ref.VariableReference in project Lucee by lucee.

the class ValueList method toColumn.

protected static QueryColumn toColumn(PageContext pc, String strQueryColumn) throws PageException {
    // if(strQueryColumn.indexOf('.')<1)
    // throw new ExpressionException("invalid query column definition ["+strQueryColumn+"]");
    VariableReference ref = ((PageContextImpl) pc).getVariableReference(strQueryColumn);
    if (ref.getParent() instanceof Scope)
        throw new ExpressionException("invalid query column definition [" + strQueryColumn + "]");
    Query query = Caster.toQuery(ref.getParent());
    return query.getColumn(ref.getKey());
}
Also used : VariableReference(lucee.runtime.type.ref.VariableReference) Scope(lucee.runtime.type.scope.Scope) Query(lucee.runtime.type.Query) PageContextImpl(lucee.runtime.PageContextImpl) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 7 with VariableReference

use of lucee.runtime.type.ref.VariableReference in project Lucee by lucee.

the class VariableInterpreter method getVariableReference.

/**
 * return a variable reference by string syntax ("scopename.key.key" -> "url.name")
 * a variable reference, references to variable, to modifed it, with global effect.
 * @param pc
 * @param var variable name to get
 * @return variable as Reference
 * @throws PageException
 */
public static VariableReference getVariableReference(PageContext pc, String var) throws PageException {
    StringList list = parse(pc, new ParserString(var), false);
    if (list == null)
        throw new InterpreterException("invalid variable declaration [" + var + "]");
    if (list.size() == 1) {
        return new VariableReference(pc.undefinedScope(), list.next());
    }
    int scope = scopeString2Int(pc.ignoreScopes(), list.next());
    Object coll;
    if (scope == Scope.SCOPE_UNDEFINED) {
        coll = pc.touch(pc.undefinedScope(), KeyImpl.init(list.current()));
    } else {
        coll = VariableInterpreter.scope(pc, scope, list.hasNext());
    // coll=pc.scope(scope);
    }
    while (list.hasNextNext()) {
        coll = pc.touch(coll, KeyImpl.init(list.next()));
    }
    if (!(coll instanceof Collection))
        throw new InterpreterException("invalid variable [" + var + "]");
    return new VariableReference((Collection) coll, list.next());
}
Also used : VariableReference(lucee.runtime.type.ref.VariableReference) StringList(lucee.commons.lang.StringList) ParserString(lucee.commons.lang.ParserString) Collection(lucee.runtime.type.Collection)

Example 8 with VariableReference

use of lucee.runtime.type.ref.VariableReference in project Lucee by lucee.

the class VariableInterpreter method getVariableReference.

public static VariableReference getVariableReference(PageContext pc, Collection.Key[] keys, boolean keepScope) throws PageException {
    if (keys.length == 1) {
        if (keepScope) {
            Collection coll = ((UndefinedImpl) pc.undefinedScope()).getScopeFor(keys[0], null);
            if (coll != null)
                return new VariableReference(coll, keys[0]);
        }
        return new VariableReference(pc.undefinedScope(), keys[0]);
    }
    int scope = scopeKey2Int(keys[0]);
    Object coll;
    if (scope == Scope.SCOPE_UNDEFINED) {
        coll = pc.touch(pc.undefinedScope(), keys[0]);
    } else {
        coll = VariableInterpreter.scope(pc, scope, keys.length > 1);
    }
    for (int i = 1; i < (keys.length - 1); i++) {
        coll = pc.touch(coll, keys[i]);
    }
    if (!(coll instanceof Collection))
        throw new InterpreterException("invalid variable [" + ListUtil.arrayToList(keys, ".") + "]");
    return new VariableReference((Collection) coll, keys[keys.length - 1]);
}
Also used : UndefinedImpl(lucee.runtime.type.scope.UndefinedImpl) VariableReference(lucee.runtime.type.ref.VariableReference) Collection(lucee.runtime.type.Collection)

Example 9 with VariableReference

use of lucee.runtime.type.ref.VariableReference in project Lucee by lucee.

the class Operator method unaryPreMultiply.

// pre multiply
public static Double unaryPreMultiply(PageContext pc, Collection.Key[] keys, double value) throws PageException {
    VariableReference ref = VariableInterpreter.getVariableReference(pc, keys, true);
    double rtn = Caster.toDoubleValue(ref.get(pc)) * value;
    ref.set(rtn);
    return rtn;
}
Also used : VariableReference(lucee.runtime.type.ref.VariableReference)

Example 10 with VariableReference

use of lucee.runtime.type.ref.VariableReference in project Lucee by lucee.

the class Operator method unaryPrMi.

public static double unaryPrMi(PageContext pc, Collection.Key[] keys, double value) throws PageException {
    VariableReference ref = VariableInterpreter.getVariableReference(pc, keys, true);
    double rtn = Caster.toDoubleValue(ref.get(pc)) - value;
    ref.set(rtn);
    return rtn;
}
Also used : VariableReference(lucee.runtime.type.ref.VariableReference)

Aggregations

VariableReference (lucee.runtime.type.ref.VariableReference)17 Collection (lucee.runtime.type.Collection)2 ParserString (lucee.commons.lang.ParserString)1 StringList (lucee.commons.lang.StringList)1 PageContextImpl (lucee.runtime.PageContextImpl)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 Query (lucee.runtime.type.Query)1 Scope (lucee.runtime.type.scope.Scope)1 UndefinedImpl (lucee.runtime.type.scope.UndefinedImpl)1