@Override public final TypedValue getTypedValue(ExpressionState expressionState) throws EvaluationException { return getValueInternal(expressionState); }
@Override @Nullable public final Object getValue(ExpressionState expressionState) throws EvaluationException { return getValueInternal(expressionState).getValue(); }
/** * Evaluate the condition and if not null, return it. * If it is null, return the other value. * @param state the expression state * @throws EvaluationException if the condition does not evaluate correctly * to a boolean or there is a problem executing the chosen alternative */ @Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue value = this.children[0].getValueInternal(state); // If this check is changed, the generateCode method will need changing too if (!StringUtils.isEmpty(value.getValue())) { return value; } else { TypedValue result = this.children[1].getValueInternal(state); computeExitTypeDescriptor(); return result; } }
@Override @Nullable public TypeDescriptor getValueTypeDescriptor(EvaluationContext context) throws EvaluationException { Assert.notNull(context, "EvaluationContext is required"); ExpressionState expressionState = new ExpressionState(context, this.configuration); return this.ast.getValueInternal(expressionState).getTypeDescriptor(); }
@Nullable protected final <T> T getValue(ExpressionState state, Class<T> desiredReturnType) throws EvaluationException { return ExpressionUtils.convertTypedValue(state.getEvaluationContext(), getValueInternal(state), desiredReturnType); }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { // Cache the concatenation of child identifiers if (this.value == null) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < getChildCount(); i++) { Object value = this.children[i].getValueInternal(state).getValue(); if (i > 0 && (value == null || !value.toString().startsWith("$"))) { sb.append("."); } sb.append(value); } this.value = new TypedValue(sb.toString()); } return this.value; }
/** * Compute the arguments to the function, they are the children of this expression node. * @return an array of argument values for the function call */ private Object[] getArguments(ExpressionState state) throws EvaluationException { // Compute arguments to the function Object[] arguments = new Object[getChildCount()]; for (int i = 0; i < arguments.length; i++) { arguments[i] = this.children[i].getValueInternal(state).getValue(); } return arguments; }
@Override @Nullable public Class<?> getValueType(EvaluationContext context) throws EvaluationException { Assert.notNull(context, "EvaluationContext is required"); ExpressionState expressionState = new ExpressionState(context, this.configuration); TypeDescriptor typeDescriptor = this.ast.getValueInternal(expressionState).getTypeDescriptor(); return (typeDescriptor != null ? typeDescriptor.getType() : null); }
@Override @Nullable public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject) throws EvaluationException { Assert.notNull(context, "EvaluationContext is required"); ExpressionState expressionState = new ExpressionState(context, toTypedValue(rootObject), this.configuration); return this.ast.getValueInternal(expressionState).getTypeDescriptor(); }
@Override @Nullable public Class<?> getValueType(EvaluationContext context, Object rootObject) throws EvaluationException { ExpressionState expressionState = new ExpressionState(context, toTypedValue(rootObject), this.configuration); TypeDescriptor typeDescriptor = this.ast.getValueInternal(expressionState).getTypeDescriptor(); return (typeDescriptor != null ? typeDescriptor.getType() : null); }
@Override @Nullable public TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException { ExpressionState expressionState = new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration); return this.ast.getValueInternal(expressionState).getTypeDescriptor(); }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue newValue = this.children[1].getValueInternal(state); getChild(0).setValue(state, newValue.getValue()); return newValue; }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { // TODO possible optimization here if we cache the discovered type reference, but can we do that? String typeName = (String) this.children[0].getValueInternal(state).getValue(); Assert.state(typeName != null, "No type name"); if (!typeName.contains(".") && Character.isLowerCase(typeName.charAt(0))) { TypeCode tc = TypeCode.valueOf(typeName.toUpperCase()); if (tc != TypeCode.OBJECT) { // It is a primitive type Class<?> clazz = makeArrayIfNecessary(tc.getType()); this.exitTypeDescriptor = "Ljava/lang/Class"; this.type = clazz; return new TypedValue(clazz); } } Class<?> clazz = state.findType(typeName); clazz = makeArrayIfNecessary(clazz); this.exitTypeDescriptor = "Ljava/lang/Class"; this.type = clazz; return new TypedValue(clazz); }
SpelNodeImpl rightOp = getRightOperand(); Object leftOperand = leftOp.getValueInternal(state).getValue(); Object rightOperand = rightOp.getValueInternal(state).getValue();
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object leftValue = getLeftOperand().getValueInternal(state).getValue(); Object rightValue = getRightOperand().getValueInternal(state).getValue(); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(leftValue); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(rightValue); return BooleanTypedValue.forValue(!equalityCheck(state.getEvaluationContext(), leftValue, rightValue)); }
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object left = getLeftOperand().getValueInternal(state).getValue(); Object right = getRightOperand().getValueInternal(state).getValue(); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right); return BooleanTypedValue.forValue(equalityCheck(state.getEvaluationContext(), left, right)); }
private Object[] getArguments(ExpressionState state) { Object[] arguments = new Object[getChildCount()]; for (int i = 0; i < arguments.length; i++) { // Make the root object the active context again for evaluating the parameter expressions try { state.pushActiveContextObject(state.getScopeRootContextObject()); arguments[i] = this.children[i].getValueInternal(state).getValue(); } finally { state.popActiveContextObject(); } } return arguments; }
/** * Evaluate the condition and if true evaluate the first alternative, otherwise * evaluate the second alternative. * @param state the expression state * @throws EvaluationException if the condition does not evaluate correctly to * a boolean or there is a problem executing the chosen alternative */ @Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { Boolean value = this.children[0].getValue(state, Boolean.class); if (value == null) { throw new SpelEvaluationException(getChild(0).getStartPosition(), SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean"); } TypedValue result = this.children[value ? 1 : 2].getValueInternal(state); computeExitTypeDescriptor(); return result; }
/** * Returns a boolean based on whether a value is in the range expressed. The first * operand is any value whilst the second is a list of two values - those two values * being the bounds allowed for the first operand (inclusive). * @param state the expression state * @return true if the left operand is in the range specified, false otherwise * @throws EvaluationException if there is a problem evaluating the expression */ @Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object left = getLeftOperand().getValueInternal(state).getValue(); Object right = getRightOperand().getValueInternal(state).getValue(); if (!(right instanceof List) || ((List<?>) right).size() != 2) { throw new SpelEvaluationException(getRightOperand().getStartPosition(), SpelMessage.BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST); } List<?> list = (List<?>) right; Object low = list.get(0); Object high = list.get(1); TypeComparator comp = state.getTypeComparator(); try { return BooleanTypedValue.forValue(comp.compare(left, low) >= 0 && comp.compare(left, high) <= 0); } catch (SpelEvaluationException ex) { ex.setPosition(getStartPosition()); throw ex; } }
TypedValue result = nextNode.getValueInternal(state); int cc = getChildCount(); for (int i = 1; i < cc - 1; i++) { state.pushActiveContextObject(result); nextNode = this.children[i]; result = nextNode.getValueInternal(state);