Polishing

(cherry picked from commit e304290)
This commit is contained in:
Juergen Hoeller
2016-07-07 01:05:25 +02:00
parent 0445ce6c53
commit b02744d42e
7 changed files with 57 additions and 58 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ public class ReaderEditorTests {
@Test(expected = IllegalArgumentException.class)
public void testCtorWithNullResourceEditor() throws Exception {
new InputStreamEditor(null);
new ReaderEditor(null);
}
@Test

View File

@@ -124,7 +124,7 @@ public class DateTimeFormattingTests {
@Test
public void testBindLocalDateArray() {
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("localDate", new String[]{"10/31/09"});
propertyValues.add("localDate", new String[] {"10/31/09"});
binder.bind(propertyValues);
assertEquals(0, binder.getBindingResult().getErrorCount());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -185,9 +185,6 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter {
method = ClassUtils.getStaticMethod(targetClass, "of", sourceClass);
if (method == null) {
method = ClassUtils.getStaticMethod(targetClass, "from", sourceClass);
if (method == null) {
return null;
}
}
}
return method;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,10 +19,10 @@ package org.springframework.core.env;
import org.springframework.core.convert.support.ConfigurableConversionService;
/**
* Configuration interface to be implemented by most if not all {@link PropertyResolver
* PropertyResolver} types. Provides facilities for accessing and customizing the
* {@link org.springframework.core.convert.ConversionService ConversionService} used when
* converting property values from one type to another.
* Configuration interface to be implemented by most if not all {@link PropertyResolver}
* types. Provides facilities for accessing and customizing the
* {@link org.springframework.core.convert.ConversionService ConversionService}
* used when converting property values from one type to another.
*
* @author Chris Beams
* @since 3.1
@@ -30,7 +30,7 @@ import org.springframework.core.convert.support.ConfigurableConversionService;
public interface ConfigurablePropertyResolver extends PropertyResolver {
/**
* @return the {@link ConfigurableConversionService} used when performing type
* Return the {@link ConfigurableConversionService} used when performing type
* conversions on properties.
* <p>The configurable nature of the returned conversion service allows for
* the convenient addition and removal of individual {@code Converter} instances:
@@ -46,10 +46,10 @@ public interface ConfigurablePropertyResolver extends PropertyResolver {
/**
* Set the {@link ConfigurableConversionService} to be used when performing type
* conversions on properties.
* <p><strong>Note:</strong> as an alternative to fully replacing the {@code
* ConversionService}, consider adding or removing individual {@code Converter}
* instances by drilling into {@link #getConversionService()} and calling methods
* such as {@code #addConverter}.
* <p><strong>Note:</strong> as an alternative to fully replacing the
* {@code ConversionService}, consider adding or removing individual
* {@code Converter} instances by drilling into {@link #getConversionService()}
* and calling methods such as {@code #addConverter}.
* @see PropertyResolver#getProperty(String, Class)
* @see #getConversionService()
* @see org.springframework.core.convert.converter.ConverterRegistry#addConverter

View File

@@ -41,8 +41,8 @@ import org.springframework.util.ObjectUtils;
*/
abstract class AnnotationReadingVisitorUtils {
public static AnnotationAttributes convertClassValues(ClassLoader classLoader, AnnotationAttributes original,
boolean classValuesAsString) {
public static AnnotationAttributes convertClassValues(
ClassLoader classLoader, AnnotationAttributes original, boolean classValuesAsString) {
if (original == null) {
return null;
@@ -60,6 +60,7 @@ abstract class AnnotationReadingVisitorUtils {
for (int i = 0; i < values.length; i++) {
values[i] = convertClassValues(classLoader, values[i], classValuesAsString);
}
value = values;
}
else if (value instanceof Type) {
value = (classValuesAsString ? ((Type) value).getClassName() :
@@ -67,7 +68,8 @@ abstract class AnnotationReadingVisitorUtils {
}
else if (value instanceof Type[]) {
Type[] array = (Type[]) value;
Object[] convArray = (classValuesAsString ? new String[array.length] : new Class<?>[array.length]);
Object[] convArray =
(classValuesAsString ? new String[array.length] : new Class<?>[array.length]);
for (int i = 0; i < array.length; i++) {
convArray[i] = (classValuesAsString ? array[i].getClassName() :
classLoader.loadClass(array[i].getClassName()));
@@ -75,11 +77,11 @@ abstract class AnnotationReadingVisitorUtils {
value = convArray;
}
else if (classValuesAsString) {
if (value instanceof Class) {
if (value instanceof Class<?>) {
value = ((Class<?>) value).getName();
}
else if (value instanceof Class[]) {
Class<?>[] clazzArray = (Class[]) value;
else if (value instanceof Class<?>[]) {
Class<?>[] clazzArray = (Class<?>[]) value;
String[] newValue = new String[clazzArray.length];
for (int i = 0; i < clazzArray.length; i++) {
newValue[i] = clazzArray[i].getName();
@@ -94,6 +96,7 @@ abstract class AnnotationReadingVisitorUtils {
result.put(entry.getKey(), ex);
}
}
return result;
}
@@ -123,13 +126,12 @@ abstract class AnnotationReadingVisitorUtils {
return null;
}
// To start with, we populate the results with a copy of all attribute
// values from the target annotation. A copy is necessary so that we do
// not inadvertently mutate the state of the metadata passed to this
// method.
AnnotationAttributes results = new AnnotationAttributes(attributesList.get(0));
// To start with, we populate the result with a copy of all attribute values
// from the target annotation. A copy is necessary so that we do not
// inadvertently mutate the state of the metadata passed to this method.
AnnotationAttributes result = new AnnotationAttributes(attributesList.get(0));
Set<String> overridableAttributeNames = new HashSet<String>(results.keySet());
Set<String> overridableAttributeNames = new HashSet<String>(result.keySet());
overridableAttributeNames.remove(AnnotationUtils.VALUE);
// Since the map is a LinkedMultiValueMap, we depend on the ordering of
@@ -152,14 +154,14 @@ abstract class AnnotationReadingVisitorUtils {
if (value != null) {
// Store the value, potentially overriding a value from an attribute
// of the same name found higher in the annotation hierarchy.
results.put(overridableAttributeName, value);
result.put(overridableAttributeName, value);
}
}
}
}
}
return results;
return result;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -134,7 +134,7 @@ public class StopWatch {
/**
* Stop the current task. The results are undefined if timing
* methods are called without invoking at least one pair
* {@code #start()} / {@code #stop()} methods.
* {@code start()} / {@code stop()} methods.
* @see #start()
*/
public void stop() throws IllegalStateException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@ public class SerializableTypeWrapperTests {
public void forField() throws Exception {
Type type = SerializableTypeWrapper.forField(Fields.class.getField("parameterizedType"));
assertThat(type.toString(), equalTo("java.util.List<java.lang.String>"));
assertSerialzable(type);
assertSerializable(type);
}
@Test
@@ -54,7 +54,7 @@ public class SerializableTypeWrapperTests {
Method method = Methods.class.getDeclaredMethod("method", Class.class, Object.class);
Type type = SerializableTypeWrapper.forMethodParameter(MethodParameter.forMethodOrConstructor(method, 0));
assertThat(type.toString(), equalTo("java.lang.Class<T>"));
assertSerialzable(type);
assertSerializable(type);
}
@Test
@@ -62,62 +62,62 @@ public class SerializableTypeWrapperTests {
Constructor<?> constructor = Constructors.class.getDeclaredConstructor(List.class);
Type type = SerializableTypeWrapper.forMethodParameter(MethodParameter.forMethodOrConstructor(constructor, 0));
assertThat(type.toString(), equalTo("java.util.List<java.lang.String>"));
assertSerialzable(type);
assertSerializable(type);
}
@Test
public void forGenericSuperClass() throws Exception {
Type type = SerializableTypeWrapper.forGenericSuperclass(ArrayList.class);
assertThat(type.toString(), equalTo("java.util.AbstractList<E>"));
assertSerialzable(type);
assertSerializable(type);
}
@Test
public void forGenericInterfaces() throws Exception {
Type type = SerializableTypeWrapper.forGenericInterfaces(List.class)[0];
assertThat(type.toString(), equalTo("java.util.Collection<E>"));
assertSerialzable(type);
assertSerializable(type);
}
@Test
public void forTypeParamters() throws Exception {
Type type = SerializableTypeWrapper.forTypeParameters(List.class)[0];
assertThat(type.toString(), equalTo("E"));
assertSerialzable(type);
assertSerializable(type);
}
@Test
public void classType() throws Exception {
Type type = SerializableTypeWrapper.forField(Fields.class.getField("classType"));
assertThat(type.toString(), equalTo("class java.lang.String"));
assertSerialzable(type);
assertSerializable(type);
}
@Test
public void genericArrayType() throws Exception {
GenericArrayType type = (GenericArrayType) SerializableTypeWrapper.forField(Fields.class.getField("genericArrayType"));
assertThat(type.toString(), equalTo("java.util.List<java.lang.String>[]"));
assertSerialzable(type);
assertSerialzable(type.getGenericComponentType());
assertSerializable(type);
assertSerializable(type.getGenericComponentType());
}
@Test
public void parameterizedType() throws Exception {
ParameterizedType type = (ParameterizedType) SerializableTypeWrapper.forField(Fields.class.getField("parameterizedType"));
assertThat(type.toString(), equalTo("java.util.List<java.lang.String>"));
assertSerialzable(type);
assertSerialzable(type.getOwnerType());
assertSerialzable(type.getRawType());
assertSerialzable(type.getActualTypeArguments());
assertSerialzable(type.getActualTypeArguments()[0]);
assertSerializable(type);
assertSerializable(type.getOwnerType());
assertSerializable(type.getRawType());
assertSerializable(type.getActualTypeArguments());
assertSerializable(type.getActualTypeArguments()[0]);
}
@Test
public void typeVariableType() throws Exception {
TypeVariable<?> type = (TypeVariable<?>) SerializableTypeWrapper.forField(Fields.class.getField("typeVariableType"));
assertThat(type.toString(), equalTo("T"));
assertSerialzable(type);
assertSerialzable(type.getBounds());
assertSerializable(type);
assertSerializable(type.getBounds());
}
@Test
@@ -125,13 +125,13 @@ public class SerializableTypeWrapperTests {
ParameterizedType typeSource = (ParameterizedType) SerializableTypeWrapper.forField(Fields.class.getField("wildcardType"));
WildcardType type = (WildcardType) typeSource.getActualTypeArguments()[0];
assertThat(type.toString(), equalTo("? extends java.lang.CharSequence"));
assertSerialzable(type);
assertSerialzable(type.getLowerBounds());
assertSerialzable(type.getUpperBounds());
assertSerializable(type);
assertSerializable(type.getLowerBounds());
assertSerializable(type.getUpperBounds());
}
private void assertSerialzable(Object source) throws Exception {
private void assertSerializable(Object source) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(source);
@@ -152,19 +152,19 @@ public class SerializableTypeWrapperTests {
public T typeVariableType;
public List<? extends CharSequence> wildcardType;
}
static interface Methods {
interface Methods {
<T> List<T> method(Class<T> p1, T p2);
}
static class Constructors {
public Constructors(List<String> p) {
}
}
}