提交 80364355 编写于 作者: S Sam Brannen

Merge branch '5.1.x'

......@@ -583,36 +583,43 @@ public abstract class BeanUtils {
}
/**
* Check if the given type represents a "simple" property:
* a primitive, a String or other CharSequence, a Number, a Date,
* a Temporal, a URI, a URL, a Locale, a Class, or a corresponding array.
* Check if the given type represents a "simple" property: a simple value
* type or an array of simple value types.
* <p>See {@link #isSimpleValueType(Class)} for the definition of <em>simple
* value type</em>.
* <p>Used to determine properties to check for a "simple" dependency-check.
* @param clazz the type to check
* @param type the type to check
* @return whether the given type represents a "simple" property
* @see org.springframework.beans.factory.support.RootBeanDefinition#DEPENDENCY_CHECK_SIMPLE
* @see org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#checkDependencies
* @see #isSimpleValueType(Class)
*/
public static boolean isSimpleProperty(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
return isSimpleValueType(clazz) || (clazz.isArray() && isSimpleValueType(clazz.getComponentType()));
public static boolean isSimpleProperty(Class<?> type) {
Assert.notNull(type, "'type' must not be null");
return isSimpleValueType(type) || (type.isArray() && isSimpleValueType(type.getComponentType()));
}
/**
* Check if the given type represents a "simple" value type:
* a primitive, an enum, a String or other CharSequence, a Number, a Date,
* a Temporal, a URI, a URL, a Locale or a Class.
* @param clazz the type to check
* Check if the given type represents a "simple" value type: a primitive or
* primitive wrapper, an enum, a String or other CharSequence, a Number, a
* Date, a Temporal, a URI, a URL, a Locale, or a Class.
* <p>{@code Void} and {@code void} are not considered simple value types.
* @param type the type to check
* @return whether the given type represents a "simple" value type
* @see #isSimpleProperty(Class)
*/
public static boolean isSimpleValueType(Class<?> clazz) {
return (ClassUtils.isPrimitiveOrWrapper(clazz) ||
Enum.class.isAssignableFrom(clazz) ||
CharSequence.class.isAssignableFrom(clazz) ||
Number.class.isAssignableFrom(clazz) ||
Date.class.isAssignableFrom(clazz) ||
Temporal.class.isAssignableFrom(clazz) ||
URI.class == clazz || URL.class == clazz ||
Locale.class == clazz || Class.class == clazz);
public static boolean isSimpleValueType(Class<?> type) {
return (type != void.class && type != Void.class &&
(ClassUtils.isPrimitiveOrWrapper(type) ||
Enum.class.isAssignableFrom(type) ||
CharSequence.class.isAssignableFrom(type) ||
Number.class.isAssignableFrom(type) ||
Date.class.isAssignableFrom(type) ||
Temporal.class.isAssignableFrom(type) ||
URI.class == type ||
URL.class == type ||
Locale.class == type ||
Class.class == type));
}
......
......@@ -20,7 +20,13 @@ import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import java.time.DayOfWeek;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
......@@ -44,6 +50,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* @author Rob Harrop
* @author Chris Beams
* @author Sebastien Deleuze
* @author Sam Brannen
* @since 19.05.2003
*/
public class BeanUtilsTests {
......@@ -285,6 +292,60 @@ public class BeanUtilsTests {
}
}
@Test
public void isSimpleValueType() {
Stream.of(
boolean.class, char.class, byte.class, short.class, int.class,
long.class, float.class, double.class,
Boolean.class, Character.class, Byte.class, Short.class, Integer.class,
Long.class, Float.class, Double.class,
DayOfWeek.class, String.class, Date.class, URI.class, URL.class, Locale.class, Class.class
).forEach(this::assertIsSimpleValueType);
Stream.of(int[].class, Object.class, List.class, void.class, Void.class)
.forEach(this::assertIsNotSimpleValueType);
}
@Test
public void isSimpleProperty() {
Stream.of(
boolean.class, char.class, byte.class, short.class, int.class,
long.class, float.class, double.class,
Boolean.class, Character.class, Byte.class, Short.class, Integer.class,
Long.class, Float.class, Double.class,
DayOfWeek.class, String.class, Date.class, URI.class, URL.class, Locale.class, Class.class,
boolean[].class, Boolean[].class, Date[].class
).forEach(this::assertIsSimpleProperty);
Stream.of(Object.class, List.class, void.class, Void.class)
.forEach(this::assertIsNotSimpleProperty);
}
private void assertIsSimpleValueType(Class<?> type) {
assertThat(BeanUtils.isSimpleValueType(type)).as("Type [" + type.getName() + "] should be a simple value type").isTrue();
}
private void assertIsNotSimpleValueType(Class<?> type) {
assertThat(BeanUtils.isSimpleValueType(type)).as("Type [" + type.getName() + "] should not be a simple value type").isFalse();
}
private void assertIsSimpleProperty(Class<?> type) {
assertThat(BeanUtils.isSimpleProperty(type)).as("Type [" + type.getName() + "] should be a simple property").isTrue();
}
private void assertIsNotSimpleProperty(Class<?> type) {
assertThat(BeanUtils.isSimpleProperty(type)).as("Type [" + type.getName() + "] should not be a simple property").isFalse();
}
private void assertSignatureEquals(Method desiredMethod, String signature) {
assertThat(BeanUtils.resolveSignature(signature, MethodSignatureBean.class)).isEqualTo(desiredMethod);
}
......
......@@ -160,9 +160,11 @@ public class ViewResolutionResultHandler extends HandlerResultHandlerSupport imp
type = result.getReturnType().getGeneric().toClass();
}
return (CharSequence.class.isAssignableFrom(type) || Rendering.class.isAssignableFrom(type) ||
Model.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type) ||
void.class == type || Void.class == type || View.class.isAssignableFrom(type) ||
return (CharSequence.class.isAssignableFrom(type) ||
Rendering.class.isAssignableFrom(type) ||
Model.class.isAssignableFrom(type) ||
Map.class.isAssignableFrom(type) ||
View.class.isAssignableFrom(type) ||
!BeanUtils.isSimpleProperty(type));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册