public MethodValueRef(ExpressionState state, Object[] arguments) { this.evaluationContext = state.getEvaluationContext(); this.value = state.getActiveContextObject().getValue(); this.targetType = state.getActiveContextObject().getTypeDescriptor(); this.arguments = arguments; }
@Override public void setValue(ExpressionState state, @Nullable Object newValue) throws EvaluationException { writeProperty(state.getActiveContextObject(), state.getEvaluationContext(), this.name, newValue); }
public void enterScope() { initVariableScopes().push(new VariableScope(Collections.emptyMap())); initScopeRootObjects().push(getActiveContextObject()); }
@Override public boolean isWritable(ExpressionState state) throws EvaluationException { return isWritableProperty(this.name, state.getActiveContextObject(), state.getEvaluationContext()); }
public void enterScope(String name, Object value) { initVariableScopes().push(new VariableScope(name, value)); initScopeRootObjects().push(getActiveContextObject()); }
public void enterScope(Map<String, Object> argMap) { initVariableScopes().push(new VariableScope(argMap)); initScopeRootObjects().push(getActiveContextObject()); }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { EvaluationContext evaluationContext = state.getEvaluationContext(); Object value = state.getActiveContextObject().getValue(); TypeDescriptor targetType = state.getActiveContextObject().getTypeDescriptor(); Object[] arguments = getArguments(state); TypedValue result = getValueInternal(evaluationContext, value, targetType, arguments); updateExitTypeDescriptor(); return result; }
@Override public ValueRef getValueRef(ExpressionState state) throws SpelEvaluationException { if (this.name.equals(THIS)) { return new ValueRef.TypedValueHolderValueRef(state.getActiveContextObject(),this); } if (this.name.equals(ROOT)) { return new ValueRef.TypedValueHolderValueRef(state.getRootContextObject(),this); } TypedValue result = state.lookupVariable(this.name); // a null value will mean either the value was null or the variable was not found return new VariableRef(this.name,result,state.getEvaluationContext()); }
@Override public TypedValue getValueInternal(ExpressionState state) throws SpelEvaluationException { if (this.name.equals(THIS)) { return state.getActiveContextObject(); } if (this.name.equals(ROOT)) { TypedValue result = state.getRootContextObject(); this.exitTypeDescriptor = CodeFlow.toDescriptorFromObject(result.getValue()); return result; } TypedValue result = state.lookupVariable(this.name); Object value = result.getValue(); if (value == null || !Modifier.isPublic(value.getClass().getModifiers())) { // If the type is not public then when generateCode produces a checkcast to it // then an IllegalAccessError will occur. // If resorting to Object isn't sufficient, the hierarchy could be traversed for // the first public type. this.exitTypeDescriptor = "Ljava/lang/Object"; } else { this.exitTypeDescriptor = CodeFlow.toDescriptorFromObject(value); } // a null value will mean either the value was null or the variable was not found return result; }
public void enterScope() { initVariableScopes().push(new VariableScope(Collections.emptyMap())); initScopeRootObjects().push(getActiveContextObject()); }
@Override public ValueRef getValueRef(ExpressionState state) throws EvaluationException { return new AccessorLValue(this, state.getActiveContextObject(), state.getEvaluationContext(), state.getConfiguration().isAutoGrowNullReferences()); }
@Override protected ValueRef getValueRef(ExpressionState state) throws EvaluationException { Object[] arguments = getArguments(state); if (state.getActiveContextObject().getValue() == null) { throwIfNotNullSafe(getArgumentTypes(arguments)); return ValueRef.NullValueRef.INSTANCE; } return new MethodValueRef(state, arguments); }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { EvaluationContext evaluationContext = state.getEvaluationContext(); Object value = state.getActiveContextObject().getValue(); TypeDescriptor targetType = state.getActiveContextObject().getTypeDescriptor(); Object[] arguments = getArguments(state); TypedValue result = getValueInternal(evaluationContext, value, targetType, arguments); updateExitTypeDescriptor(); return result; }
@Override public ValueRef getValueRef(ExpressionState state) throws SpelEvaluationException { if (this.name.equals(THIS)) { return new ValueRef.TypedValueHolderValueRef(state.getActiveContextObject(),this); } if (this.name.equals(ROOT)) { return new ValueRef.TypedValueHolderValueRef(state.getRootContextObject(),this); } TypedValue result = state.lookupVariable(this.name); // a null value will mean either the value was null or the variable was not found return new VariableRef(this.name,result,state.getEvaluationContext()); }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue tv = getValueInternal(state.getActiveContextObject(), state.getEvaluationContext(), state.getConfiguration().isAutoGrowNullReferences()); PropertyAccessor accessorToUse = this.cachedReadAccessor; if (accessorToUse instanceof CompilablePropertyAccessor) { CompilablePropertyAccessor accessor = (CompilablePropertyAccessor) accessorToUse; setExitTypeDescriptor(CodeFlow.toDescriptor(accessor.getPropertyType())); } return tv; }
@Override public ValueRef getValueRef(ExpressionState state) throws EvaluationException { return new AccessorLValue(this, state.getActiveContextObject(), state.getEvaluationContext(), state.getConfiguration().isAutoGrowNullReferences()); }
@Override protected ValueRef getValueRef(ExpressionState state) throws EvaluationException { TypedValue op = state.getActiveContextObject();
@Override protected ValueRef getValueRef(ExpressionState state) throws EvaluationException { Object[] arguments = getArguments(state); if (state.getActiveContextObject().getValue() == null) { throwIfNotNullSafe(getArgumentTypes(arguments)); return ValueRef.NullValueRef.INSTANCE; } return new MethodValueRef(state, arguments); }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue tv = getValueInternal(state.getActiveContextObject(), state.getEvaluationContext(), state.getConfiguration().isAutoGrowNullReferences()); PropertyAccessor accessorToUse = this.cachedReadAccessor; if (accessorToUse instanceof CompilablePropertyAccessor) { CompilablePropertyAccessor accessor = (CompilablePropertyAccessor) accessorToUse; setExitTypeDescriptor(CodeFlow.toDescriptor(accessor.getPropertyType())); } return tv; }
@Test public void testActiveContextObject() { ExpressionState state = getState(); assertEquals(state.getRootContextObject().getValue(), state.getActiveContextObject().getValue()); try { state.popActiveContextObject(); fail("stack should be empty..."); } catch (IllegalStateException ese) { // success } state.pushActiveContextObject(new TypedValue(34)); assertEquals(34, state.getActiveContextObject().getValue()); state.pushActiveContextObject(new TypedValue("hello")); assertEquals("hello", state.getActiveContextObject().getValue()); state.popActiveContextObject(); assertEquals(34, state.getActiveContextObject().getValue()); state.popActiveContextObject(); assertEquals(state.getRootContextObject().getValue(), state.getActiveContextObject().getValue()); state = new ExpressionState(new StandardEvaluationContext()); assertEquals(TypedValue.NULL, state.getActiveContextObject()); }