push(new PropertyOrFieldReference(false, newToken.stringValue(), newToken.startPos, newToken.endPos)); return true;
@Override public TypedValue getValueInternal(ExpressionState expressionState) throws EvaluationException { if (this.constant != null) { return this.constant; } else { Map<Object, Object> returnValue = new LinkedHashMap<>(); int childcount = getChildCount(); for (int c = 0; c < childcount; c++) { // TODO allow for key being PropertyOrFieldReference like Indexer on maps SpelNode keyChild = getChild(c++); Object key = null; if (keyChild instanceof PropertyOrFieldReference) { PropertyOrFieldReference reference = (PropertyOrFieldReference) keyChild; key = reference.getName(); } else { key = keyChild.getValue(expressionState); } Object value = getChild(c).getValue(expressionState); returnValue.put(key, value); } return new TypedValue(returnValue); } }
throw new SpelEvaluationException(getStartPosition(), SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL, name); getPropertyAccessorsToTry(contextObject.getValue(), evalContext.getPropertyAccessors()); try { for (PropertyAccessor accessor : accessorsToTry) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_PROPERTY_WRITE, name, ex.getMessage()); throw new SpelEvaluationException(getStartPosition(), SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE, name, FormatHelper.formatClassNameForMessage(getObjectClass(contextObject.getValue())));
TypedValue result = readProperty(contextObject, evalContext, this.name); nextChildIs(Indexer.class, PropertyOrFieldReference.class)) { TypeDescriptor resultDescriptor = result.getTypeDescriptor(); Assert.state(resultDescriptor != null, "No result type"); if (isWritableProperty(this.name, contextObject, evalContext)) { List<?> newList = new ArrayList<>(); writeProperty(contextObject, evalContext, this.name, newList); result = readProperty(contextObject, evalContext, this.name); if (isWritableProperty(this.name,contextObject, evalContext)) { Map<?,?> newMap = new HashMap<>(); writeProperty(contextObject, evalContext, this.name, newMap); result = readProperty(contextObject, evalContext, this.name); if (isWritableProperty(this.name,contextObject, evalContext)) { Class<?> clazz = result.getTypeDescriptor().getType(); Object newObject = ReflectionUtils.accessibleConstructor(clazz).newInstance(); writeProperty(contextObject, evalContext, this.name, newObject); result = readProperty(contextObject, evalContext, this.name); throw new SpelEvaluationException(getStartPosition(), ex.getTargetException(), SpelMessage.UNABLE_TO_DYNAMICALLY_CREATE_OBJECT, result.getTypeDescriptor().getType()); throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.UNABLE_TO_DYNAMICALLY_CREATE_OBJECT, result.getTypeDescriptor().getType());
@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 boolean isWritable() { return this.ref.isWritableProperty(this.ref.name, this.contextObject, this.evalContext); } }
@Override public TypedValue getValue() { TypedValue value = this.ref.getValueInternal(this.contextObject, this.evalContext, this.autoGrowNullReferences); PropertyAccessor accessorToUse = this.ref.cachedReadAccessor; if (accessorToUse instanceof CompilablePropertyAccessor) { this.ref.setExitTypeDescriptor(CodeFlow.toDescriptor(((CompilablePropertyAccessor) accessorToUse).getPropertyType())); } return value; }
public boolean isWritableProperty(String name, TypedValue contextObject, EvaluationContext evalContext) throws EvaluationException { Object value = contextObject.getValue(); if (value != null) { List<PropertyAccessor> accessorsToTry = getPropertyAccessorsToTry(contextObject.getValue(), evalContext.getPropertyAccessors()); for (PropertyAccessor accessor : accessorsToTry) { try { if (accessor.canWrite(evalContext, value, name)) { return true; } } catch (AccessException ex) { // let others try } } } return false; }
TypedValue result = readProperty(contextObject, evalContext, this.name); nextChildIs(Indexer.class, PropertyOrFieldReference.class)) { TypeDescriptor resultDescriptor = result.getTypeDescriptor(); Assert.state(resultDescriptor != null, "No result type"); if (isWritableProperty(this.name, contextObject, evalContext)) { List<?> newList = new ArrayList<>(); writeProperty(contextObject, evalContext, this.name, newList); result = readProperty(contextObject, evalContext, this.name); if (isWritableProperty(this.name,contextObject, evalContext)) { Map<?,?> newMap = new HashMap<>(); writeProperty(contextObject, evalContext, this.name, newMap); result = readProperty(contextObject, evalContext, this.name); if (isWritableProperty(this.name,contextObject, evalContext)) { Class<?> clazz = result.getTypeDescriptor().getType(); Object newObject = ReflectionUtils.accessibleConstructor(clazz).newInstance(); writeProperty(contextObject, evalContext, this.name, newObject); result = readProperty(contextObject, evalContext, this.name); throw new SpelEvaluationException(getStartPosition(), ex.getTargetException(), SpelMessage.UNABLE_TO_DYNAMICALLY_CREATE_OBJECT, result.getTypeDescriptor().getType()); throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.UNABLE_TO_DYNAMICALLY_CREATE_OBJECT, result.getTypeDescriptor().getType());
@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 boolean isWritable() { return this.ref.isWritableProperty(this.ref.name, this.contextObject, this.evalContext); } }
@Override public TypedValue getValue() { TypedValue value = this.ref.getValueInternal(this.contextObject, this.evalContext, this.autoGrowNullReferences); PropertyAccessor accessorToUse = this.ref.cachedReadAccessor; if (accessorToUse instanceof CompilablePropertyAccessor) { this.ref.setExitTypeDescriptor(CodeFlow.toDescriptor(((CompilablePropertyAccessor) accessorToUse).getPropertyType())); } return value; }
public boolean isWritableProperty(String name, TypedValue contextObject, EvaluationContext evalContext) throws EvaluationException { Object value = contextObject.getValue(); if (value != null) { List<PropertyAccessor> accessorsToTry = getPropertyAccessorsToTry(contextObject.getValue(), evalContext.getPropertyAccessors()); for (PropertyAccessor accessor : accessorsToTry) { try { if (accessor.canWrite(evalContext, value, name)) { return true; } } catch (AccessException ex) { // let others try } } } return false; }
TypedValue result = readProperty(contextObject, evalContext, this.name); nextChildIs(Indexer.class, PropertyOrFieldReference.class)) { TypeDescriptor resultDescriptor = result.getTypeDescriptor(); Assert.state(resultDescriptor != null, "No result type"); if (isWritableProperty(this.name, contextObject, evalContext)) { List<?> newList = new ArrayList<>(); writeProperty(contextObject, evalContext, this.name, newList); result = readProperty(contextObject, evalContext, this.name); if (isWritableProperty(this.name,contextObject, evalContext)) { Map<?,?> newMap = new HashMap<>(); writeProperty(contextObject, evalContext, this.name, newMap); result = readProperty(contextObject, evalContext, this.name); if (isWritableProperty(this.name,contextObject, evalContext)) { Class<?> clazz = result.getTypeDescriptor().getType(); Object newObject = ReflectionUtils.accessibleConstructor(clazz).newInstance(); writeProperty(contextObject, evalContext, this.name, newObject); result = readProperty(contextObject, evalContext, this.name); throw new SpelEvaluationException(getStartPosition(), ex.getTargetException(), SpelMessage.UNABLE_TO_DYNAMICALLY_CREATE_OBJECT, result.getTypeDescriptor().getType()); throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.UNABLE_TO_DYNAMICALLY_CREATE_OBJECT, result.getTypeDescriptor().getType());
getPropertyAccessorsToTry(contextObject.getValue(), evalContext.getPropertyAccessors()); throw new SpelEvaluationException(getStartPosition(), SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE, name, FormatHelper.formatClassNameForMessage(getObjectClass(contextObject.getValue())));
@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; }
String mapKeyName = reference.getName(); mv.visitLdcInsn(mapKeyName);
private boolean maybeEatTypeReference() { if (peekToken(TokenKind.IDENTIFIER)) { Token typeName = peekToken(); Assert.state(typeName != null, "Expected token"); if (!"T".equals(typeName.stringValue())) { return false; } // It looks like a type reference but is T being used as a map key? Token t = takeToken(); if (peekToken(TokenKind.RSQUARE)) { // looks like 'T]' (T is map key) push(new PropertyOrFieldReference(false, t.stringValue(), t.startPos, t.endPos)); return true; } eatToken(TokenKind.LPAREN); SpelNodeImpl node = eatPossiblyQualifiedId(); // dotted qualified id // Are there array dimensions? int dims = 0; while (peekToken(TokenKind.LSQUARE, true)) { eatToken(TokenKind.RSQUARE); dims++; } eatToken(TokenKind.RPAREN); this.constructedNodes.push(new TypeReference(typeName.startPos, typeName.endPos, node, dims)); return true; } return false; }
@Override public boolean isWritable(ExpressionState state) throws EvaluationException { return isWritableProperty(this.name, state.getActiveContextObject(), state.getEvaluationContext()); }
@Override public TypedValue getValue() { TypedValue value = this.ref.getValueInternal(this.contextObject, this.evalContext, this.autoGrowNullReferences); PropertyAccessor accessorToUse = this.ref.cachedReadAccessor; if (accessorToUse instanceof CompilablePropertyAccessor) { this.ref.setExitTypeDescriptor(CodeFlow.toDescriptor(((CompilablePropertyAccessor) accessorToUse).getPropertyType())); } return value; }