Polishing

(cherry picked from commit 3c6f1f8)
This commit is contained in:
Juergen Hoeller
2015-05-22 17:24:40 +02:00
parent a64dcc2a31
commit d5de3867ca
3 changed files with 48 additions and 54 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -272,7 +272,7 @@ public abstract class ClassUtils {
return (clToUse != null ? clToUse.loadClass(innerClassName) : Class.forName(innerClassName));
}
catch (ClassNotFoundException ex2) {
// swallow - let original exception get through
// Swallow - let original exception get through
}
}
throw ex;
@@ -380,9 +380,9 @@ public abstract class ClassUtils {
*/
public static Class<?> getUserClass(Class<?> clazz) {
if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) {
Class<?> superClass = clazz.getSuperclass();
if (superClass != null && !Object.class.equals(superClass)) {
return superClass;
Class<?> superclass = clazz.getSuperclass();
if (superclass != null && !Object.class.equals(superclass)) {
return superclass;
}
}
return clazz;
@@ -829,8 +829,8 @@ public abstract class ClassUtils {
/**
* Return a public static method of a class.
* @param methodName the static method name
* @param clazz the class which defines the method
* @param methodName the static method name
* @param args the parameter types to the method
* @return the static method, or {@code null} if no static method was found
* @throws IllegalArgumentException if the method name is blank or the clazz is null
@@ -901,7 +901,7 @@ public abstract class ClassUtils {
*/
public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
return (clazz.isPrimitive() && clazz != void.class? primitiveTypeToWrapperMap.get(clazz) : clazz);
return (clazz.isPrimitive() && clazz != void.class ? primitiveTypeToWrapperMap.get(clazz) : clazz);
}
/**
@@ -978,7 +978,7 @@ public abstract class ClassUtils {
* loading a resource file that is in the same package as a class file,
* although {@link org.springframework.core.io.ClassPathResource} is usually
* even more convenient.
* @param clazz the Class whose package will be used as the base
* @param clazz the Class whose package will be used as the base
* @param resourceName the resource name to append. A leading slash is optional.
* @return the built-up resource path
* @see ClassLoader#getResource
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -88,43 +88,40 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
if (result.getValue() == null && isAutoGrowNullReferences &&
nextChildIs(Indexer.class, PropertyOrFieldReference.class)) {
TypeDescriptor resultDescriptor = result.getTypeDescriptor();
// Creating lists and maps
if ((resultDescriptor.getType().equals(List.class) || resultDescriptor.getType().equals(Map.class))) {
// Create a new collection or map ready for the indexer
if (resultDescriptor.getType().equals(List.class)) {
try {
if (isWritableProperty(this.name,contextObject,eContext)) {
List<?> newList = ArrayList.class.newInstance();
writeProperty(contextObject, eContext, this.name, newList);
result = readProperty(contextObject, eContext, this.name);
}
}
catch (InstantiationException ex) {
throw new SpelEvaluationException(getStartPosition(), ex,
SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING);
}
catch (IllegalAccessException ex) {
throw new SpelEvaluationException(getStartPosition(), ex,
SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING);
// Create a new collection or map ready for the indexer
if (List.class.equals(resultDescriptor.getType())) {
try {
if (isWritableProperty(this.name, contextObject, eContext)) {
List<?> newList = ArrayList.class.newInstance();
writeProperty(contextObject, eContext, this.name, newList);
result = readProperty(contextObject, eContext, this.name);
}
}
else {
try {
if (isWritableProperty(this.name,contextObject,eContext)) {
Map<?,?> newMap = HashMap.class.newInstance();
writeProperty(contextObject, eContext, this.name, newMap);
result = readProperty(contextObject, eContext, this.name);
}
}
catch (InstantiationException ex) {
throw new SpelEvaluationException(getStartPosition(), ex,
SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING);
}
catch (IllegalAccessException ex) {
throw new SpelEvaluationException(getStartPosition(), ex,
SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING);
catch (InstantiationException ex) {
throw new SpelEvaluationException(getStartPosition(), ex,
SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING);
}
catch (IllegalAccessException ex) {
throw new SpelEvaluationException(getStartPosition(), ex,
SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING);
}
}
else if (Map.class.equals(resultDescriptor.getType())) {
try {
if (isWritableProperty(this.name, contextObject, eContext)) {
Map<?,?> newMap = HashMap.class.newInstance();
writeProperty(contextObject, eContext, this.name, newMap);
result = readProperty(contextObject, eContext, this.name);
}
}
catch (InstantiationException ex) {
throw new SpelEvaluationException(getStartPosition(), ex,
SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING);
}
catch (IllegalAccessException ex) {
throw new SpelEvaluationException(getStartPosition(), ex,
SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING);
}
}
else {
// 'simple' object
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -47,8 +47,8 @@ import org.springframework.web.util.WebUtils;
* type {@link MultipartFile} in conjunction with Spring's {@link MultipartResolver}
* abstraction, and arguments of type {@code javax.servlet.http.Part} in conjunction
* with Servlet 3.0 multipart requests. This resolver can also be created in default
* resolution mode in which simple types (int, long, etc.) not annotated
* with @{@link RequestParam} are also treated as request parameters with the
* resolution mode in which simple types (int, long, etc.) not annotated with
* @{@link RequestParam} are also treated as request parameters with the
* parameter name derived from the argument name.
*
* <p>If the method parameter type is {@link Map}, the name specified in the
@@ -131,19 +131,16 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
@Override
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
RequestParam annotation = parameter.getParameterAnnotation(RequestParam.class);
return (annotation != null) ?
new RequestParamNamedValueInfo(annotation) :
new RequestParamNamedValueInfo();
RequestParam ann = parameter.getParameterAnnotation(RequestParam.class);
return (ann != null ? new RequestParamNamedValueInfo(ann) : new RequestParamNamedValueInfo());
}
@Override
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest) throws Exception {
Object arg;
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
MultipartHttpServletRequest multipartRequest =
WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);
WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);
Object arg;
if (MultipartFile.class.equals(parameter.getParameterType())) {
assertIsMultipartRequest(servletRequest);
@@ -170,7 +167,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
if (arg == null) {
String[] paramValues = webRequest.getParameterValues(name);
if (paramValues != null) {
arg = paramValues.length == 1 ? paramValues[0] : paramValues;
arg = (paramValues.length == 1 ? paramValues[0] : paramValues);
}
}
}
@@ -189,7 +186,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
Class<?> paramType = parameter.getParameterType();
if (Collection.class.equals(paramType) || List.class.isAssignableFrom(paramType)){
Class<?> valueType = GenericCollectionTypeResolver.getCollectionParameterType(parameter);
if (valueType != null && valueType.equals(MultipartFile.class)) {
if (MultipartFile.class.equals(valueType)) {
return true;
}
}