restored TypeDescriptor getElementType, getMapKeyType, and getMapValueType compatibility; StringToCollection and Array Converters are now conditional and check targetElementType if present; TypeDesciptor#isAssignable no longer bothers with element type and map key/value types in checking assignability for consistency elsewhere; improved javadoc

This commit is contained in:
Keith Donald
2011-06-07 02:51:44 +00:00
parent a1a7c32052
commit 5e3a5202fb
21 changed files with 244 additions and 230 deletions

View File

@@ -91,11 +91,11 @@ public class Indexer extends SpelNodeImpl {
// Indexing into a Map
if (targetObject instanceof Map) {
Object key = index;
if (targetObjectTypeDescriptor.getMapKeyType() != null) {
key = state.convertValue(key, targetObjectTypeDescriptor.getMapKeyType());
if (targetObjectTypeDescriptor.getMapKeyTypeDescriptor() != null) {
key = state.convertValue(key, targetObjectTypeDescriptor.getMapKeyTypeDescriptor());
}
Object value = ((Map<?, ?>) targetObject).get(key);
return new TypedValue(value, targetObjectTypeDescriptor.mapValueType(value));
return new TypedValue(value, targetObjectTypeDescriptor.mapValueTypeDescriptor(value));
}
if (targetObject == null) {
@@ -107,7 +107,7 @@ public class Indexer extends SpelNodeImpl {
int idx = (Integer) state.convertValue(index, TypeDescriptor.valueOf(Integer.class));
if (targetObject.getClass().isArray()) {
Object arrayElement = accessArrayElement(targetObject, idx);
return new TypedValue(arrayElement, targetObjectTypeDescriptor.elementType(arrayElement));
return new TypedValue(arrayElement, targetObjectTypeDescriptor.elementTypeDescriptor(arrayElement));
} else if (targetObject instanceof Collection) {
Collection c = (Collection) targetObject;
if (idx >= c.size()) {
@@ -118,7 +118,7 @@ public class Indexer extends SpelNodeImpl {
int pos = 0;
for (Object o : c) {
if (pos == idx) {
return new TypedValue(o, targetObjectTypeDescriptor.elementType(o));
return new TypedValue(o, targetObjectTypeDescriptor.elementTypeDescriptor(o));
}
pos++;
}
@@ -187,11 +187,11 @@ public class Indexer extends SpelNodeImpl {
if (targetObject instanceof Map) {
Map map = (Map) targetObject;
Object key = index.getValue();
if (targetObjectTypeDescriptor.getMapKeyType() != null) {
key = state.convertValue(index, targetObjectTypeDescriptor.getMapKeyType());
if (targetObjectTypeDescriptor.getMapKeyTypeDescriptor() != null) {
key = state.convertValue(index, targetObjectTypeDescriptor.getMapKeyTypeDescriptor());
}
if (targetObjectTypeDescriptor.getMapValueType() != null) {
newValue = state.convertValue(newValue, targetObjectTypeDescriptor.getMapValueType());
if (targetObjectTypeDescriptor.getMapValueTypeDescriptor() != null) {
newValue = state.convertValue(newValue, targetObjectTypeDescriptor.getMapValueTypeDescriptor());
}
map.put(key, newValue);
return;
@@ -199,7 +199,7 @@ public class Indexer extends SpelNodeImpl {
if (targetObjectTypeDescriptor.isArray()) {
int idx = (Integer)state.convertValue(index, TypeDescriptor.valueOf(Integer.class));
setArrayElement(state, contextObject.getValue(), idx, newValue, targetObjectTypeDescriptor.getElementType().getType());
setArrayElement(state, contextObject.getValue(), idx, newValue, targetObjectTypeDescriptor.getElementTypeDescriptor().getType());
return;
}
else if (targetObject instanceof Collection) {
@@ -212,8 +212,8 @@ public class Indexer extends SpelNodeImpl {
}
if (targetObject instanceof List) {
List list = (List) targetObject;
if (targetObjectTypeDescriptor.getElementType() != null) {
newValue = state.convertValue(newValue, targetObjectTypeDescriptor.getElementType());
if (targetObjectTypeDescriptor.getElementTypeDescriptor() != null) {
newValue = state.convertValue(newValue, targetObjectTypeDescriptor.getElementTypeDescriptor());
}
list.set(idx, newValue);
return;
@@ -271,10 +271,10 @@ public class Indexer extends SpelNodeImpl {
private boolean growCollection(ExpressionState state, TypeDescriptor targetType, int index,
Collection collection) {
if (state.getConfiguration().isAutoGrowCollections()) {
if (targetType.getElementType() == null) {
if (targetType.getElementTypeDescriptor() == null) {
throw new SpelEvaluationException(getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION_UNKNOWN_ELEMENT_TYPE);
}
TypeDescriptor elementType = targetType.getElementType();
TypeDescriptor elementType = targetType.getElementTypeDescriptor();
Object newCollectionElement = null;
try {
int newElements = index - collection.size();

View File

@@ -142,7 +142,7 @@ public class Selection extends SpelNodeImpl {
return new TypedValue(result);
}
else {
Class<?> elementType = ClassUtils.resolvePrimitiveIfNecessary(op.getTypeDescriptor().getElementType().getType());
Class<?> elementType = ClassUtils.resolvePrimitiveIfNecessary(op.getTypeDescriptor().getElementTypeDescriptor().getType());
Object resultArray = Array.newInstance(elementType, result.size());
System.arraycopy(result.toArray(), 0, resultArray, 0, result.size());
return new TypedValue(resultArray);

View File

@@ -213,7 +213,7 @@ public class ReflectionHelper {
else {
// Now... we have the final argument in the method we are checking as a match and we have 0 or more other
// arguments left to pass to it.
Class varargsParameterType = expectedArgTypes.get(expectedArgTypes.size() - 1).getElementType().getType();
Class varargsParameterType = expectedArgTypes.get(expectedArgTypes.size() - 1).getElementTypeDescriptor().getType();
// All remaining parameters must be of this type or convertable to this type
for (int i = expectedArgTypes.size() - 1; i < suppliedArgTypes.size(); i++) {

View File

@@ -74,13 +74,13 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
TypeConvertorUsingConversionService tcs = new TypeConvertorUsingConversionService();
// ArrayList containing List<Integer> to List<String>
Class<?> clazz = typeDescriptorForListOfString.getElementType().getType();
Class<?> clazz = typeDescriptorForListOfString.getElementTypeDescriptor().getType();
assertEquals(String.class,clazz);
List l = (List) tcs.convertValue(listOfInteger, TypeDescriptor.forObject(listOfInteger), typeDescriptorForListOfString);
assertNotNull(l);
// ArrayList containing List<String> to List<Integer>
clazz = typeDescriptorForListOfInteger.getElementType().getType();
clazz = typeDescriptorForListOfInteger.getElementTypeDescriptor().getType();
assertEquals(Integer.class,clazz);
l = (List) tcs.convertValue(listOfString, TypeDescriptor.forObject(listOfString), typeDescriptorForListOfString);

View File

@@ -113,7 +113,7 @@ public class SelectionAndProjectionTests {
Object value = expression.getValue(context);
assertTrue(value.getClass().isArray());
TypedValue typedValue = new TypedValue(value);
assertEquals(Integer.class, typedValue.getTypeDescriptor().getElementType().getType());
assertEquals(Integer.class, typedValue.getTypeDescriptor().getElementTypeDescriptor().getType());
Integer[] array = (Integer[]) value;
assertEquals(5, array.length);
assertEquals(new Integer(0), array[0]);
@@ -148,7 +148,7 @@ public class SelectionAndProjectionTests {
Object value = expression.getValue(context);
assertTrue(value.getClass().isArray());
TypedValue typedValue = new TypedValue(value);
assertEquals(Integer.class, typedValue.getTypeDescriptor().getElementType().getType());
assertEquals(Integer.class, typedValue.getTypeDescriptor().getElementTypeDescriptor().getType());
Integer[] array = (Integer[]) value;
assertEquals(5, array.length);
assertEquals(new Integer(0), array[0]);
@@ -250,7 +250,7 @@ public class SelectionAndProjectionTests {
Object value = expression.getValue(context);
assertTrue(value.getClass().isArray());
TypedValue typedValue = new TypedValue(value);
assertEquals(Number.class, typedValue.getTypeDescriptor().getElementType().getType());
assertEquals(Number.class, typedValue.getTypeDescriptor().getElementTypeDescriptor().getType());
Number[] array = (Number[]) value;
assertEquals(3, array.length);
assertEquals(new Integer(5), array[0]);

View File

@@ -729,7 +729,7 @@ public class SpringEL300Tests extends ExpressionTestCase {
// value is list containing [true,false]
Assert.assertEquals(Boolean.class,value.get(0).getClass());
TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
Assert.assertEquals(null, evaluated.getElementType());
Assert.assertEquals(null, evaluated.getElementTypeDescriptor());
}
@Test
@@ -742,7 +742,7 @@ public class SpringEL300Tests extends ExpressionTestCase {
// value is array containing [true,false]
Assert.assertEquals(Boolean.class,value[0].getClass());
TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
Assert.assertEquals(Boolean.class, evaluated.getElementType().getType());
Assert.assertEquals(Boolean.class, evaluated.getElementTypeDescriptor().getType());
}
@Test
@@ -755,7 +755,7 @@ public class SpringEL300Tests extends ExpressionTestCase {
// value is list containing [true,false]
Assert.assertEquals(Boolean.class,value.get(0).getClass());
TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
Assert.assertEquals(null, evaluated.getElementType());
Assert.assertEquals(null, evaluated.getElementTypeDescriptor());
}
static class C {