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