simplified TypeDescriptor usage and updated use of the API across BeanWrapper and SpEL; collapsed PropertyTypeDescriptor into TypeDescriptor for simplicity and ease of use; improved docs
This commit is contained in:
@@ -90,10 +90,13 @@ public class Indexer extends SpelNodeImpl {
|
||||
|
||||
// Indexing into a Map
|
||||
if (targetObject instanceof Map) {
|
||||
Object possiblyConvertedKey = index;
|
||||
possiblyConvertedKey = state.convertValue(index, targetObjectTypeDescriptor.getMapKeyTypeDescriptor());
|
||||
Object o = ((Map<?, ?>) targetObject).get(possiblyConvertedKey);
|
||||
return new TypedValue(o, targetObjectTypeDescriptor.getMapValueTypeDescriptor());
|
||||
if (targetObjectTypeDescriptor.isMap()) {
|
||||
Object possiblyConvertedKey = state.convertValue(index, targetObjectTypeDescriptor.getMapKeyTypeDescriptor());
|
||||
Object o = ((Map<?, ?>) targetObject).get(possiblyConvertedKey);
|
||||
return new TypedValue(o, targetObjectTypeDescriptor.getMapValueTypeDescriptor());
|
||||
} else {
|
||||
return new TypedValue(((Map<?, ?>) targetObject).get(index));
|
||||
}
|
||||
}
|
||||
|
||||
if (targetObject == null) {
|
||||
@@ -158,11 +161,11 @@ public class Indexer extends SpelNodeImpl {
|
||||
}
|
||||
}
|
||||
} catch (AccessException e) {
|
||||
throw new SpelEvaluationException(getStartPosition(), e, SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, targetObjectTypeDescriptor.asString());
|
||||
throw new SpelEvaluationException(getStartPosition(), e, SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, targetObjectTypeDescriptor.toString());
|
||||
}
|
||||
}
|
||||
|
||||
throw new SpelEvaluationException(getStartPosition(),SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, targetObjectTypeDescriptor.asString());
|
||||
throw new SpelEvaluationException(getStartPosition(),SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, targetObjectTypeDescriptor.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -212,7 +215,7 @@ public class Indexer extends SpelNodeImpl {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
throw new SpelEvaluationException(getStartPosition(),SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, targetObjectTypeDescriptor.asString());
|
||||
throw new SpelEvaluationException(getStartPosition(),SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, targetObjectTypeDescriptor.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +251,7 @@ public class Indexer extends SpelNodeImpl {
|
||||
|
||||
}
|
||||
|
||||
throw new SpelEvaluationException(getStartPosition(),SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, targetObjectTypeDescriptor.asString());
|
||||
throw new SpelEvaluationException(getStartPosition(),SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, targetObjectTypeDescriptor.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.expression.spel.SpelEvaluationException;
|
||||
import org.springframework.expression.spel.SpelMessage;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.MethodInvoker;
|
||||
|
||||
/**
|
||||
* Utility methods used by the reflection resolver code to discover the appropriate
|
||||
@@ -104,7 +105,7 @@ public class ReflectionHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on {@link MethodInvoker.getTypeDifferenceWeight} but operates on TypeDescriptors.
|
||||
* Based on {@link MethodInvoker#getTypeDifferenceWeight(Class[], Object[])} but operates on TypeDescriptors.
|
||||
*/
|
||||
public static int getTypeDifferenceWeight(List<TypeDescriptor> paramTypes, List<TypeDescriptor> argTypes) {
|
||||
int result = 0;
|
||||
@@ -279,7 +280,7 @@ public class ReflectionHelper {
|
||||
TypeDescriptor targetType;
|
||||
if (varargsPosition != null && argPosition >= varargsPosition) {
|
||||
MethodParameter methodParam = MethodParameter.forMethodOrConstructor(methodOrCtor, varargsPosition);
|
||||
targetType = TypeDescriptor.forNestedType(methodParam);
|
||||
targetType = TypeDescriptor.nested(methodParam, 1);
|
||||
}
|
||||
else {
|
||||
targetType = new TypeDescriptor(MethodParameter.forMethodOrConstructor(methodOrCtor, argPosition));
|
||||
@@ -311,7 +312,7 @@ public class ReflectionHelper {
|
||||
TypeDescriptor targetType;
|
||||
if (varargsPosition != null && argPosition >= varargsPosition) {
|
||||
MethodParameter methodParam = new MethodParameter(method, varargsPosition);
|
||||
targetType = TypeDescriptor.forNestedType(methodParam);
|
||||
targetType = TypeDescriptor.nested(methodParam, 1);
|
||||
}
|
||||
else {
|
||||
targetType = new TypeDescriptor(new MethodParameter(method, argPosition));
|
||||
|
||||
@@ -28,7 +28,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.support.PropertyTypeDescriptor;
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
@@ -79,8 +78,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
|
||||
try {
|
||||
// The readerCache will only contain gettable properties (let's not worry about setters for now)
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(name, method, null);
|
||||
TypeDescriptor typeDescriptor =
|
||||
new PropertyTypeDescriptor(new MethodParameter(method, -1), propertyDescriptor);
|
||||
TypeDescriptor typeDescriptor = new TypeDescriptor(type, propertyDescriptor);
|
||||
this.readerCache.put(cacheKey, new InvokerPair(method, typeDescriptor));
|
||||
this.typeDescriptorCache.put(cacheKey, typeDescriptor);
|
||||
return true;
|
||||
@@ -127,8 +125,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
|
||||
try {
|
||||
// The readerCache will only contain gettable properties (let's not worry about setters for now)
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(name, method, null);
|
||||
TypeDescriptor typeDescriptor =
|
||||
new PropertyTypeDescriptor(new MethodParameter(method, -1), propertyDescriptor);
|
||||
TypeDescriptor typeDescriptor = new TypeDescriptor(type, propertyDescriptor);
|
||||
invoker = new InvokerPair(method, typeDescriptor);
|
||||
this.readerCache.put(cacheKey, invoker);
|
||||
}
|
||||
@@ -191,8 +188,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
|
||||
catch (IntrospectionException ex) {
|
||||
throw new AccessException("Unable to access property '" + name + "' through setter "+method, ex);
|
||||
}
|
||||
MethodParameter mp = new MethodParameter(method,0);
|
||||
TypeDescriptor typeDescriptor = new PropertyTypeDescriptor(mp, propertyDescriptor);
|
||||
TypeDescriptor typeDescriptor = new TypeDescriptor(type, propertyDescriptor);
|
||||
this.writerCache.put(cacheKey, method);
|
||||
this.typeDescriptorCache.put(cacheKey, typeDescriptor);
|
||||
return true;
|
||||
|
||||
@@ -66,12 +66,10 @@ public class StandardTypeConverter implements TypeConverter {
|
||||
return this.conversionService.convert(value, sourceType, targetType);
|
||||
}
|
||||
catch (ConverterNotFoundException cenfe) {
|
||||
throw new SpelEvaluationException(cenfe, SpelMessage.TYPE_CONVERSION_ERROR,
|
||||
sourceType.toString(), targetType.asString());
|
||||
throw new SpelEvaluationException(cenfe, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString());
|
||||
}
|
||||
catch (ConversionException ce) {
|
||||
throw new SpelEvaluationException(ce, SpelMessage.TYPE_CONVERSION_ERROR,
|
||||
sourceType.toString(), targetType.asString());
|
||||
throw new SpelEvaluationException(ce, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
public List Members2 = new ArrayList();
|
||||
public Map<String,Object> officers = new HashMap<String,Object>();
|
||||
|
||||
public List reverse = new ArrayList<Map<String, Object>>();
|
||||
public List<Map<String, Object>> reverse = new ArrayList<Map<String, Object>>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
IEEE() {
|
||||
|
||||
Reference in New Issue
Block a user