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 | 44138 | jjdelcerro | package org.gvsig.expressionevaluator.impl.function.programming; |
---|---|---|---|
2 | 43512 | jjdelcerro | |
3 | import org.apache.commons.lang3.Range; |
||
4 | 45153 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionBuilder; |
5 | 43939 | jjdelcerro | import org.gvsig.expressionevaluator.Function; |
6 | 43521 | jjdelcerro | import org.gvsig.expressionevaluator.Interpreter; |
7 | 43939 | jjdelcerro | import org.gvsig.expressionevaluator.MutableSymbolTable; |
8 | import org.gvsig.expressionevaluator.SymbolTable; |
||
9 | 43512 | jjdelcerro | import org.gvsig.expressionevaluator.spi.AbstractFunction; |
10 | |||
11 | 43939 | jjdelcerro | public class LetFunction extends AbstractFunction { |
12 | 43512 | jjdelcerro | |
13 | 43939 | jjdelcerro | public LetFunction() {
|
14 | 44138 | jjdelcerro | super(Function.GROUP_PROGRAMMING,
|
15 | 45153 | jjdelcerro | ExpressionBuilder.FUNCTION_LET, |
16 | 44098 | jjdelcerro | Range.is(2),
|
17 | "Assigns the value indicated in the second argument to the variable indicated in the first argument.",
|
||
18 | 44924 | jjdelcerro | "SET {{identifier}} = expression",
|
19 | 44098 | jjdelcerro | new String[]{ |
20 | "identifier_name - Name of the variable",
|
||
21 | "value - Value to assign to the variable"
|
||
22 | }, |
||
23 | "Object",
|
||
24 | false
|
||
25 | ); |
||
26 | 44138 | jjdelcerro | this.addAlias("SET"); |
27 | 43512 | jjdelcerro | } |
28 | 44138 | jjdelcerro | |
29 | 43512 | jjdelcerro | @Override
|
30 | 44138 | jjdelcerro | public boolean allowConstantFolding() { |
31 | return false; |
||
32 | } |
||
33 | |||
34 | @Override
|
||
35 | 43521 | jjdelcerro | public Object call(Interpreter interpreter, Object[] args) throws Exception { |
36 | 43939 | jjdelcerro | 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 | 43512 | jjdelcerro | } |
41 | 43939 | jjdelcerro | 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 | 43512 | jjdelcerro | } |
49 | |||
50 | } |