growCollection fails for element type Object as well; prefer use of getElementTypeDescriptor()
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3454 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
52c4834750
commit
54a35be552
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -32,9 +32,9 @@ import org.springframework.expression.spel.SpelMessage;
|
||||||
import org.springframework.expression.spel.support.ReflectivePropertyAccessor;
|
import org.springframework.expression.spel.support.ReflectivePropertyAccessor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An Indexer can index into some proceeding structure to access a particular piece of it. Supported structures are:
|
* An Indexer can index into some proceeding structure to access a particular piece of it.
|
||||||
* strings/collections (lists/sets)/arrays
|
* Supported structures are: strings/collections (lists/sets)/arrays
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
|
|
@ -114,7 +114,7 @@ public class Indexer extends SpelNodeImpl {
|
||||||
if ((targetObject instanceof Collection ) || targetObject.getClass().isArray() || targetObject instanceof String) {
|
if ((targetObject instanceof Collection ) || targetObject.getClass().isArray() || targetObject instanceof String) {
|
||||||
int idx = (Integer)state.convertValue(index, TypeDescriptor.valueOf(Integer.class));
|
int idx = (Integer)state.convertValue(index, TypeDescriptor.valueOf(Integer.class));
|
||||||
if (targetObject.getClass().isArray()) {
|
if (targetObject.getClass().isArray()) {
|
||||||
return new TypedValue(accessArrayElement(targetObject, idx),TypeDescriptor.valueOf(targetObjectTypeDescriptor.getElementType()));
|
return new TypedValue(accessArrayElement(targetObject, idx), targetObjectTypeDescriptor.getElementTypeDescriptor());
|
||||||
} else if (targetObject instanceof Collection) {
|
} else if (targetObject instanceof Collection) {
|
||||||
Collection c = (Collection) targetObject;
|
Collection c = (Collection) targetObject;
|
||||||
if (idx >= c.size()) {
|
if (idx >= c.size()) {
|
||||||
|
|
@ -125,7 +125,7 @@ public class Indexer extends SpelNodeImpl {
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (Object o : c) {
|
for (Object o : c) {
|
||||||
if (pos == idx) {
|
if (pos == idx) {
|
||||||
return new TypedValue(o,TypeDescriptor.valueOf(targetObjectTypeDescriptor.getElementType()));
|
return new TypedValue(o, targetObjectTypeDescriptor.getElementTypeDescriptor());
|
||||||
}
|
}
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
@ -218,7 +218,7 @@ public class Indexer extends SpelNodeImpl {
|
||||||
}
|
}
|
||||||
if (targetObject instanceof List) {
|
if (targetObject instanceof List) {
|
||||||
List list = (List)targetObject;
|
List list = (List)targetObject;
|
||||||
Object possiblyConvertedValue = state.convertValue(newValue,TypeDescriptor.valueOf(targetObjectTypeDescriptor.getElementType()));
|
Object possiblyConvertedValue = state.convertValue(newValue, targetObjectTypeDescriptor.getElementTypeDescriptor());
|
||||||
list.set(idx,possiblyConvertedValue);
|
list.set(idx,possiblyConvertedValue);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -278,7 +278,7 @@ public class Indexer extends SpelNodeImpl {
|
||||||
Object newCollectionElement = null;
|
Object newCollectionElement = null;
|
||||||
try {
|
try {
|
||||||
int newElements = index-collection.size();
|
int newElements = index-collection.size();
|
||||||
if (elementType == null) {
|
if (elementType == null || elementType == Object.class) {
|
||||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION_UNKNOWN_ELEMENT_TYPE);
|
throw new SpelEvaluationException(getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION_UNKNOWN_ELEMENT_TYPE);
|
||||||
}
|
}
|
||||||
while (newElements>0) {
|
while (newElements>0) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -34,12 +34,12 @@ import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents selection over a map or collection. For example: {1,2,3,4,5,6,7,8,9,10}.?{#isEven(#this) == 'y'} returns
|
* Represents selection over a map or collection.
|
||||||
* [2, 4, 6, 8, 10]
|
* For example: {1,2,3,4,5,6,7,8,9,10}.?{#isEven(#this) == 'y'} returns [2, 4, 6, 8, 10]
|
||||||
*
|
*
|
||||||
* Basically a subset of the input data is returned based on the evaluation of the expression supplied as selection
|
* <p>Basically a subset of the input data is returned based on the
|
||||||
* criteria.
|
* evaluation of the expression supplied as selection criteria.
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
|
|
@ -112,13 +112,13 @@ public class Selection extends SpelNodeImpl {
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (Object element : data) {
|
for (Object element : data) {
|
||||||
try {
|
try {
|
||||||
state.pushActiveContextObject(new TypedValue(element,TypeDescriptor.valueOf(op.getTypeDescriptor().getElementType())));
|
state.pushActiveContextObject(new TypedValue(element, op.getTypeDescriptor().getElementTypeDescriptor()));
|
||||||
state.enterScope("index", idx);
|
state.enterScope("index", idx);
|
||||||
Object o = selectionCriteria.getValueInternal(state).getValue();
|
Object o = selectionCriteria.getValueInternal(state).getValue();
|
||||||
if (o instanceof Boolean) {
|
if (o instanceof Boolean) {
|
||||||
if (((Boolean) o).booleanValue() == true) {
|
if (((Boolean) o).booleanValue() == true) {
|
||||||
if (variant == FIRST) {
|
if (variant == FIRST) {
|
||||||
return new TypedValue(element,TypeDescriptor.valueOf(op.getTypeDescriptor().getElementType()));
|
return new TypedValue(element, op.getTypeDescriptor().getElementTypeDescriptor());
|
||||||
}
|
}
|
||||||
result.add(element);
|
result.add(element);
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +136,7 @@ public class Selection extends SpelNodeImpl {
|
||||||
return TypedValue.NULL;
|
return TypedValue.NULL;
|
||||||
}
|
}
|
||||||
if (variant == LAST) {
|
if (variant == LAST) {
|
||||||
return new TypedValue(result.get(result.size() - 1),TypeDescriptor.valueOf(op.getTypeDescriptor().getElementType()));
|
return new TypedValue(result.get(result.size() - 1), op.getTypeDescriptor().getElementTypeDescriptor());
|
||||||
}
|
}
|
||||||
if (operand instanceof Collection) {
|
if (operand instanceof Collection) {
|
||||||
return new TypedValue(result,op.getTypeDescriptor());
|
return new TypedValue(result,op.getTypeDescriptor());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue