From 1cea52b66b3a6cbfe0109d71e375c323be8c8faf Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Oct 2011 16:55:07 +0000 Subject: [PATCH] renamed mapKey/ValueTypeDescriptor methods back to getMapKey/ValueTypeDescriptor (for Spring 3.0.x compatibility) --- .../core/convert/TypeDescriptor.java | 234 +++++++++--------- .../convert/support/MapToMapConverter.java | 4 +- .../core/convert/TypeDescriptorTests.java | 8 +- .../expression/spel/ast/Indexer.java | 2 +- 4 files changed, 125 insertions(+), 123 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index 02e26089921..12a4b02e54f 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -382,7 +382,7 @@ public class TypeDescriptor { * @throws IllegalStateException if this type is not a java.util.Map. * @see #narrow(Object) */ - public TypeDescriptor mapKeyTypeDescriptor(Object mapKey) { + public TypeDescriptor getMapKeyTypeDescriptor(Object mapKey) { return narrow(mapKey, getMapKeyTypeDescriptor()); } @@ -407,11 +407,126 @@ public class TypeDescriptor { * @return the map value type descriptor * @throws IllegalStateException if this type is not a java.util.Map. */ - public TypeDescriptor mapValueTypeDescriptor(Object mapValue) { + public TypeDescriptor getMapValueTypeDescriptor(Object mapValue) { return narrow(mapValue, getMapValueTypeDescriptor()); } - // extending Object + + // deprecations in Spring 3.1 + + /** + * Returns the value of {@link TypeDescriptor#getType() getType()} for the {@link #getElementTypeDescriptor() elementTypeDescriptor}. + * @deprecated in Spring 3.1 in favor of {@link #getElementTypeDescriptor()}. + * @throws IllegalStateException if this type is not a java.util.Collection or Array type + */ + @Deprecated + public Class getElementType() { + return getElementTypeDescriptor().getType(); + } + + /** + * Returns the value of {@link TypeDescriptor#getType() getType()} for the {@link #getMapKeyTypeDescriptor() getMapKeyTypeDescriptor}. + * @deprecated in Spring 3.1 in favor of {@link #getMapKeyTypeDescriptor()}. + * @throws IllegalStateException if this type is not a java.util.Map. + */ + @Deprecated + public Class getMapKeyType() { + return getMapKeyTypeDescriptor().getType(); + } + + /** + * Returns the value of {@link TypeDescriptor#getType() getType()} for the {@link #getMapValueTypeDescriptor() getMapValueTypeDescriptor}. + * @deprecated in Spring 3.1 in favor of {@link #getMapValueTypeDescriptor()}. + * @throws IllegalStateException if this type is not a java.util.Map. + */ + @Deprecated + public Class getMapValueType() { + return getMapValueTypeDescriptor().getType(); + } + + // package private helpers + + TypeDescriptor(AbstractDescriptor descriptor) { + this.type = descriptor.getType(); + this.elementTypeDescriptor = descriptor.getElementTypeDescriptor(); + this.mapKeyTypeDescriptor = descriptor.getMapKeyTypeDescriptor(); + this.mapValueTypeDescriptor = descriptor.getMapValueTypeDescriptor(); + this.annotations = descriptor.getAnnotations(); + } + + static Annotation[] nullSafeAnnotations(Annotation[] annotations) { + return annotations != null ? annotations : EMPTY_ANNOTATION_ARRAY; + } + + + // internal constructors + + private TypeDescriptor(Class type) { + this(new ClassDescriptor(type)); + } + + private TypeDescriptor(Class collectionType, TypeDescriptor elementTypeDescriptor) { + this(collectionType, elementTypeDescriptor, null, null, EMPTY_ANNOTATION_ARRAY); + } + + private TypeDescriptor(Class mapType, TypeDescriptor keyTypeDescriptor, TypeDescriptor valueTypeDescriptor) { + this(mapType, null, keyTypeDescriptor, valueTypeDescriptor, EMPTY_ANNOTATION_ARRAY); + } + + private TypeDescriptor(Class type, TypeDescriptor elementTypeDescriptor, TypeDescriptor mapKeyTypeDescriptor, + TypeDescriptor mapValueTypeDescriptor, Annotation[] annotations) { + this.type = type; + this.elementTypeDescriptor = elementTypeDescriptor; + this.mapKeyTypeDescriptor = mapKeyTypeDescriptor; + this.mapValueTypeDescriptor = mapValueTypeDescriptor; + this.annotations = annotations; + } + + private static TypeDescriptor nested(AbstractDescriptor descriptor, int nestingLevel) { + for (int i = 0; i < nestingLevel; i++) { + descriptor = descriptor.nested(); + if (descriptor == null) { + return null; + } + } + return new TypeDescriptor(descriptor); + } + + + // internal helpers + + private void assertCollectionOrArray() { + if (!isCollection() && !isArray()) { + throw new IllegalStateException("Not a java.util.Collection or Array"); + } + } + + private void assertMap() { + if (!isMap()) { + throw new IllegalStateException("Not a java.util.Map"); + } + } + + private TypeDescriptor narrow(Object value, TypeDescriptor typeDescriptor) { + if (typeDescriptor != null) { + return typeDescriptor.narrow(value); + } + else { + return value != null ? new TypeDescriptor(value.getClass(), null, null, null, annotations) : null; + } + } + + private boolean isNestedAssignable(TypeDescriptor nestedTypeDescriptor, TypeDescriptor otherNestedTypeDescriptor) { + if (nestedTypeDescriptor == null || otherNestedTypeDescriptor == null) { + return true; + } + return nestedTypeDescriptor.isAssignableTo(otherNestedTypeDescriptor); + } + + private String wildcard(TypeDescriptor typeDescriptor) { + return typeDescriptor != null ? typeDescriptor.toString() : "?"; + } + public boolean equals(Object obj) { if (this == obj) { @@ -457,117 +572,4 @@ public class TypeDescriptor { return builder.toString(); } - // deprecations in Spring 3.1 - - /** - * Returns the value of {@link TypeDescriptor#getType() getType()} for the {@link #getElementTypeDescriptor() elementTypeDescriptor}. - * @deprecated in Spring 3.1 in favor of {@link #getElementTypeDescriptor()}. - * @throws IllegalStateException if this type is not a java.util.Collection or Array type - */ - @Deprecated - public Class getElementType() { - return getElementTypeDescriptor().getType(); - } - - /** - * Returns the value of {@link TypeDescriptor#getType() getType()} for the {@link #getMapKeyTypeDescriptor() mapKeyTypeDescriptor}. - * @deprecated in Spring 3.1 in favor of {@link #getMapKeyTypeDescriptor()}. - * @throws IllegalStateException if this type is not a java.util.Map. - */ - @Deprecated - public Class getMapKeyType() { - return getMapKeyTypeDescriptor().getType(); - } - - /** - * Returns the value of {@link TypeDescriptor#getType() getType()} for the {@link #getMapValueTypeDescriptor() mapValueTypeDescriptor}. - * @deprecated in Spring 3.1 in favor of {@link #getMapValueTypeDescriptor()}. - * @throws IllegalStateException if this type is not a java.util.Map. - */ - @Deprecated - public Class getMapValueType() { - return getMapValueTypeDescriptor().getType(); - } - - // package private helpers - - TypeDescriptor(AbstractDescriptor descriptor) { - this.type = descriptor.getType(); - this.elementTypeDescriptor = descriptor.getElementTypeDescriptor(); - this.mapKeyTypeDescriptor = descriptor.getMapKeyTypeDescriptor(); - this.mapValueTypeDescriptor = descriptor.getMapValueTypeDescriptor(); - this.annotations = descriptor.getAnnotations(); - } - - static Annotation[] nullSafeAnnotations(Annotation[] annotations) { - return annotations != null ? annotations : EMPTY_ANNOTATION_ARRAY; - } - - // internal constructors - - private TypeDescriptor(Class type) { - this(new ClassDescriptor(type)); - } - - private TypeDescriptor(Class collectionType, TypeDescriptor elementTypeDescriptor) { - this(collectionType, elementTypeDescriptor, null, null, EMPTY_ANNOTATION_ARRAY); - } - - private TypeDescriptor(Class mapType, TypeDescriptor keyTypeDescriptor, TypeDescriptor valueTypeDescriptor) { - this(mapType, null, keyTypeDescriptor, valueTypeDescriptor, EMPTY_ANNOTATION_ARRAY); - } - - private TypeDescriptor(Class type, TypeDescriptor elementTypeDescriptor, TypeDescriptor mapKeyTypeDescriptor, - TypeDescriptor mapValueTypeDescriptor, Annotation[] annotations) { - this.type = type; - this.elementTypeDescriptor = elementTypeDescriptor; - this.mapKeyTypeDescriptor = mapKeyTypeDescriptor; - this.mapValueTypeDescriptor = mapValueTypeDescriptor; - this.annotations = annotations; - } - - private static TypeDescriptor nested(AbstractDescriptor descriptor, int nestingLevel) { - for (int i = 0; i < nestingLevel; i++) { - descriptor = descriptor.nested(); - if (descriptor == null) { - return null; - } - } - return new TypeDescriptor(descriptor); - } - - // internal helpers - - private void assertCollectionOrArray() { - if (!isCollection() && !isArray()) { - throw new IllegalStateException("Not a java.util.Collection or Array"); - } - } - - private void assertMap() { - if (!isMap()) { - throw new IllegalStateException("Not a java.util.Map"); - } - } - - private TypeDescriptor narrow(Object value, TypeDescriptor typeDescriptor) { - if (typeDescriptor != null) { - return typeDescriptor.narrow(value); - } - else { - return value != null ? new TypeDescriptor(value.getClass(), null, null, null, annotations) : null; - } - } - - private boolean isNestedAssignable(TypeDescriptor nestedTypeDescriptor, TypeDescriptor otherNestedTypeDescriptor) { - if (nestedTypeDescriptor == null || otherNestedTypeDescriptor == null) { - return true; - } - return nestedTypeDescriptor.isAssignableTo(otherNestedTypeDescriptor); - } - - private String wildcard(TypeDescriptor typeDescriptor) { - return typeDescriptor != null ? typeDescriptor.toString() : "?"; - } - } diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java index 810a384abf4..f7b5c28ed46 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java @@ -87,14 +87,14 @@ final class MapToMapConverter implements ConditionalGenericConverter { if (targetType == null) { return sourceKey; } - return this.conversionService.convert(sourceKey, sourceType.mapKeyTypeDescriptor(sourceKey), targetType); + return this.conversionService.convert(sourceKey, sourceType.getMapKeyTypeDescriptor(sourceKey), targetType); } private Object convertValue(Object sourceValue, TypeDescriptor sourceType, TypeDescriptor targetType) { if (targetType == null) { return sourceValue; } - return this.conversionService.convert(sourceValue, sourceType.mapValueTypeDescriptor(sourceValue), targetType); + return this.conversionService.convert(sourceValue, sourceType.getMapValueTypeDescriptor(sourceValue), targetType); } } diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java index d3028551190..4e5dd880ea5 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java @@ -706,7 +706,7 @@ public class TypeDescriptorTests { public void mapKeyType() { TypeDescriptor desc = TypeDescriptor.valueOf(Map.class); Integer value = new Integer(3); - desc = desc.mapKeyTypeDescriptor(value); + desc = desc.getMapKeyTypeDescriptor(value); assertEquals(Integer.class, desc.getType()); } @@ -715,7 +715,7 @@ public class TypeDescriptorTests { TypeDescriptor desc = new TypeDescriptor(getClass().getField("mapPreserveContext")); assertEquals(Integer.class, desc.getMapKeyTypeDescriptor().getElementTypeDescriptor().getType()); List value = new ArrayList(3); - desc = desc.mapKeyTypeDescriptor(value); + desc = desc.getMapKeyTypeDescriptor(value); assertEquals(Integer.class, desc.getElementTypeDescriptor().getType()); assertNotNull(desc.getAnnotation(FieldAnnotation.class)); } @@ -727,7 +727,7 @@ public class TypeDescriptorTests { public void mapValueType() { TypeDescriptor desc = TypeDescriptor.valueOf(Map.class); Integer value = new Integer(3); - desc = desc.mapValueTypeDescriptor(value); + desc = desc.getMapValueTypeDescriptor(value); assertEquals(Integer.class, desc.getType()); } @@ -736,7 +736,7 @@ public class TypeDescriptorTests { TypeDescriptor desc = new TypeDescriptor(getClass().getField("mapPreserveContext")); assertEquals(Integer.class, desc.getMapValueTypeDescriptor().getElementTypeDescriptor().getType()); List value = new ArrayList(3); - desc = desc.mapValueTypeDescriptor(value); + desc = desc.getMapValueTypeDescriptor(value); assertEquals(Integer.class, desc.getElementTypeDescriptor().getType()); assertNotNull(desc.getAnnotation(FieldAnnotation.class)); } diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java index b12c5d5c6a2..ec3e6eb7737 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java @@ -95,7 +95,7 @@ public class Indexer extends SpelNodeImpl { key = state.convertValue(key, targetObjectTypeDescriptor.getMapKeyTypeDescriptor()); } Object value = ((Map) targetObject).get(key); - return new TypedValue(value, targetObjectTypeDescriptor.mapValueTypeDescriptor(value)); + return new TypedValue(value, targetObjectTypeDescriptor.getMapValueTypeDescriptor(value)); } if (targetObject == null) {