protected Object _doEvaluate(XBlockExpression literal, IEvaluationContext context, CancelIndicator indicator) { List<XExpression> expressions = literal.getExpressions(); Object result = null; IEvaluationContext forkedContext = context.fork(); for (int i = 0; i < expressions.size(); i++) { result = internalEvaluate(expressions.get(i), forkedContext, indicator); } return result; }
protected Object _doEvaluate(XForLoopExpression forLoop, IEvaluationContext context, CancelIndicator indicator) { Object iterableOrIterator = internalEvaluate(forLoop.getForExpression(), context, indicator); if (iterableOrIterator == null) return throwNullPointerException(forLoop.getForExpression(), "iterable evaluated to 'null'"); Iterator<?> iter = null; if (iterableOrIterator instanceof Iterable<?>) { iter = ((Iterable<?>) iterableOrIterator).iterator(); } else if (iterableOrIterator.getClass().isArray()) { iter = ((Iterable<?>) Conversions.doWrapArray(iterableOrIterator)).iterator(); } else { return throwClassCastException(forLoop.getForExpression(), iterableOrIterator, java.lang.Iterable.class); } IEvaluationContext forkedContext = context.fork(); QualifiedName paramName = QualifiedName.create(forLoop.getDeclaredParam().getName()); forkedContext.newValue(paramName, null); while (iter.hasNext()) { Object next = iter.next(); forkedContext.assignValue(paramName, next); internalEvaluate(forLoop.getEachExpression(), forkedContext, indicator); } return null; }
protected Object _doEvaluate(XBasicForLoopExpression forLoop, IEvaluationContext context, CancelIndicator indicator) { IEvaluationContext forkedContext = context.fork(); for (XExpression initExpression : forLoop.getInitExpressions()) { internalEvaluate(initExpression, forkedContext, indicator); } XExpression expression = forLoop.getExpression(); Object condition = expression == null ? Boolean.TRUE : internalEvaluate(expression, forkedContext, indicator); while (Boolean.TRUE.equals(condition)) { internalEvaluate(forLoop.getEachExpression(), forkedContext, indicator); for (XExpression updateExpression : forLoop.getUpdateExpressions()) { internalEvaluate(updateExpression, forkedContext, indicator); } condition = expression == null ? Boolean.TRUE : internalEvaluate(expression, forkedContext, indicator); } return null; }
@Override protected Object doInvoke(Method method, Object[] args) throws Throwable { IEvaluationContext forkedContext = context.fork(); if (args != null) { initializeClosureParameters(forkedContext, args); } IEvaluationResult result = interpreter.evaluate(closure.getExpression(), forkedContext, indicator); if (indicator.isCanceled()) throw new InterpreterCanceledException(); if (result.getException() != null) throw result.getException(); return result.getResult(); }
protected Object _doEvaluate(XSwitchExpression switchExpression, IEvaluationContext context, CancelIndicator indicator) { IEvaluationContext forkedContext = context.fork(); Object conditionResult = internalEvaluate(switchExpression.getSwitch(), forkedContext, indicator); String simpleName = featureNameProvider.getSimpleName(switchExpression.getDeclaredParam()); if (simpleName != null) { forkedContext.newValue(QualifiedName.create(simpleName), conditionResult); } for (XCasePart casePart : switchExpression.getCases()) { JvmTypeReference typeGuard = casePart.getTypeGuard(); if (typeGuard != null && switchExpression.getSwitch() == null) throw new IllegalStateException("Switch without expression or implicit 'this' may not use type guards"); if (typeGuard == null || isInstanceoOf(conditionResult, typeGuard)) { if (casePart.getCase() != null) { Object casePartResult = internalEvaluate(casePart.getCase(), forkedContext, indicator); if (Boolean.TRUE.equals(casePartResult) || eq(conditionResult, casePartResult)) { XExpression then = switchExpressions.getThen(casePart, switchExpression); return internalEvaluate(then, forkedContext, indicator); } } else { XExpression then = switchExpressions.getThen(casePart, switchExpression); return internalEvaluate(then, forkedContext, indicator); } } } if (switchExpression.getDefault() != null) { Object defaultResult = internalEvaluate(switchExpression.getDefault(), forkedContext, indicator); return defaultResult; } return getDefaultObjectValue(typeResolver.resolveTypes(switchExpression).getActualType(switchExpression)); }
protected Object _doEvaluate(XTryCatchFinallyExpression tryCatchFinally, IEvaluationContext context, CancelIndicator indicator) { Object result = null; try { result = internalEvaluate(tryCatchFinally.getExpression(), context, indicator); } catch (EvaluationException evaluationException) { Throwable cause = evaluationException.getCause(); for (XCatchClause catchClause : tryCatchFinally.getCatchClauses()) { JvmFormalParameter exception = catchClause.getDeclaredParam(); JvmTypeReference catchParameterType = exception.getParameterType(); if (!isInstanceoOf(cause, catchParameterType)) { continue; } IEvaluationContext forked = context.fork(); forked.newValue(QualifiedName.create(exception.getName()), cause); result = internalEvaluate(catchClause.getExpression(), forked, indicator); break; } } if (tryCatchFinally.getFinallyExpression() != null) { try { internalEvaluate(tryCatchFinally.getFinallyExpression(), context, indicator); } catch (EvaluationException e) { throw new EvaluationException(new FinallyDidNotCompleteException(e)); } } return result; }