Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / programming / LetFunction.java @ 44207

History | View | Annotate | Download (1.72 KB)

1 44138 jjdelcerro
package org.gvsig.expressionevaluator.impl.function.programming;
2 43512 jjdelcerro
3
import org.apache.commons.lang3.Range;
4 43939 jjdelcerro
import org.gvsig.expressionevaluator.Function;
5 43521 jjdelcerro
import org.gvsig.expressionevaluator.Interpreter;
6 43939 jjdelcerro
import org.gvsig.expressionevaluator.MutableSymbolTable;
7
import org.gvsig.expressionevaluator.SymbolTable;
8 43512 jjdelcerro
import org.gvsig.expressionevaluator.spi.AbstractFunction;
9
10 43939 jjdelcerro
public class LetFunction extends AbstractFunction {
11 43512 jjdelcerro
12 44138 jjdelcerro
    public static final String NAME = "LET";
13
14 43939 jjdelcerro
    public LetFunction() {
15 44138 jjdelcerro
        super(Function.GROUP_PROGRAMMING,
16
            NAME,
17 44098 jjdelcerro
            Range.is(2),
18
            "Assigns the value indicated in the second argument to the variable indicated in the first argument.",
19 44138 jjdelcerro
            NAME+"({{identifier_name}},value)",
20 44098 jjdelcerro
            new String[]{
21
                "identifier_name - Name of the variable",
22
                "value - Value to assign to the variable"
23
            },
24
            "Object",
25
            false
26
        );
27 44138 jjdelcerro
        this.addAlias("SET");
28 43512 jjdelcerro
    }
29 44138 jjdelcerro
30 43512 jjdelcerro
    @Override
31 44138 jjdelcerro
    public boolean allowConstantFolding() {
32
        return false;
33
    }
34
35
    @Override
36 43521 jjdelcerro
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
37 43939 jjdelcerro
        String name = getStr(args,0);
38
        Object obj = getObject(args, 1);
39
        if( name == null ) {
40
            throw new NullPointerException("A string with a variable name was expected and a null was received");
41 43512 jjdelcerro
        }
42 43939 jjdelcerro
        SymbolTable symbolTable = interpreter.getSymbolTable();
43
        if( symbolTable instanceof MutableSymbolTable ) {
44
            ((MutableSymbolTable)symbolTable).setVar(name, obj);
45
        } else {
46
            throw new RuntimeException("A MutableSymbolTable is required for use let function.");
47
        }
48
        return obj;
49 43512 jjdelcerro
    }
50
51
}