Revision 44139 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/DefaultInterpreter.java

View differences:

DefaultInterpreter.java
13 13
import org.gvsig.expressionevaluator.Code.Constant;
14 14
import org.gvsig.expressionevaluator.Code.Identifier;
15 15
import org.gvsig.expressionevaluator.Code.Caller;
16
import org.gvsig.expressionevaluator.Code.Caller.Arguments;
17 16
import org.gvsig.expressionevaluator.Code.Method;
17
import org.gvsig.expressionevaluator.Codes;
18 18
import org.gvsig.expressionevaluator.ExpressionRuntimeException;
19 19
import org.gvsig.expressionevaluator.Function;
20 20
import org.gvsig.expressionevaluator.impl.function.operator.BinaryOperator;
21
import org.gvsig.expressionevaluator.impl.function.obj.InvokeMethodFunction;
21
import org.gvsig.expressionevaluator.impl.function.programming.CallMethodFunction;
22 22
import org.gvsig.expressionevaluator.impl.function.operator.UnaryOperator;
23
import org.gvsig.expressionevaluator.impl.function.programming.ReturnFunction.ReturnException;
23 24

  
24 25
public class DefaultInterpreter implements Interpreter {
25 26

  
......
34 35
        @Override
35 36
        public Object get(Object context, Object key) {
36 37
            Pair<Object, Long> v = this.data.get( Pair.of(context, key) );
38
            if( v == null ) {
39
                return null;
40
            }
37 41
            return v.getLeft();
38 42
        }
39 43

  
......
126 130
    public Object run(Code code) {
127 131
        try {
128 132
            return this.runCode(code);
133
        } catch(ReturnException ex) {
134
            return ex.getValue();
129 135
        } catch(RuntimeException ex) {
130 136
            throw ex;
131 137
        } catch(Exception ex) {
......
152 158
        }
153 159
    }
154 160

  
155
    private Object runCode(Code code) throws Exception {
161
    public Object runCode(Code code) throws Exception {
156 162
        this.currentCode = code;
157 163
        Object value = null;
158 164
        switch( code.code() ) {
......
180 186
                    if( obj == null ) {
181 187
                        throw new NullPointerException("An object pointer was expected to invoke method "+method.methodname()+" and a null was received");
182 188
                    }
183
                    method.function(new InvokeMethodFunction(obj, method.methodname()));
189
                    method.function(new CallMethodFunction(obj, method.methodname()));
184 190
                }
185 191
            }
186 192
        case Code.CALLER:
......
193 199
                }
194 200
                caller.function(function);
195 201
            }
196
            Arguments args = caller.args();
202
            Codes args = caller.args();
197 203
            try {
198 204
                switch( caller.type() ) {
199 205
                case Caller.UNARY_OPERATOR:
200
                    if( args == null || args.count() != 1 ) {
201
                        throw new ExpressionRuntimeException(code, I18N.Number_of_argument_mistmatch_in_operator_XIdentifierX_expected_1_got_XargcX(function.name(),args==null?0:args.count()));
206
                    if( args == null || args.size() != 1 ) {
207
                        throw new ExpressionRuntimeException(code, I18N.Number_of_argument_mistmatch_in_operator_XIdentifierX_expected_1_got_XargcX(function.name(),args==null?0:args.size()));
202 208
                    }
203 209
                    value = ((UnaryOperator) function).call(this, runCode(args.get(0)));
204 210
                    break;
205 211

  
206 212
                case Caller.BINARY_OPERATOR:
207
                    if( args == null || args.count() != 2 ) {
208
                        throw new ExpressionRuntimeException(code, I18N.Number_of_argument_mistmatch_in_operator_XIdentifierX_expected_2_got_XargcX(function.name(),args==null?0:args.count()));
213
                    if( args == null || args.size() != 2 ) {
214
                        throw new ExpressionRuntimeException(code, I18N.Number_of_argument_mistmatch_in_operator_XIdentifierX_expected_2_got_XargcX(function.name(),args==null?0:args.size()));
209 215
                    }
210 216
                    value = ((BinaryOperator) function).call(this, runCode(args.get(0)), runCode(args.get(1)));
211 217
                    break;
212 218

  
213 219
                case Caller.FUNCTION:
214
                    int argc = (args == null) ? 0 : args.count();
220
                    int argc = (args == null) ? 0 : args.size();
215 221
                    if( !function.argc().contains(argc) ) {
216 222
                        throw new ExpressionRuntimeException(code, I18N.Number_of_argument_mistmatch_in_function_XIdentifierX_expected_XexpectedX_got_XfoundX(function.name(),function.argc(),argc));
217 223
                    }

Also available in: Unified diff