Skip to content

Commit d5de386

Browse files
committed
Polishing
(cherry picked from commit 3c6f1f8)
1 parent a64dcc2 commit d5de386

File tree

3 files changed

+48
-54
lines changed

3 files changed

+48
-54
lines changed

spring-core/src/main/java/org/springframework/util/ClassUtils.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -272,7 +272,7 @@ public static Class<?> forName(String name, ClassLoader classLoader) throws Clas
272272
return (clToUse != null ? clToUse.loadClass(innerClassName) : Class.forName(innerClassName));
273273
}
274274
catch (ClassNotFoundException ex2) {
275-
// swallow - let original exception get through
275+
// Swallow - let original exception get through
276276
}
277277
}
278278
throw ex;
@@ -380,9 +380,9 @@ public static Class<?> getUserClass(Object instance) {
380380
*/
381381
public static Class<?> getUserClass(Class<?> clazz) {
382382
if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) {
383-
Class<?> superClass = clazz.getSuperclass();
384-
if (superClass != null && !Object.class.equals(superClass)) {
385-
return superClass;
383+
Class<?> superclass = clazz.getSuperclass();
384+
if (superclass != null && !Object.class.equals(superclass)) {
385+
return superclass;
386386
}
387387
}
388388
return clazz;
@@ -829,8 +829,8 @@ private static boolean isOverridable(Method method, Class<?> targetClass) {
829829

830830
/**
831831
* Return a public static method of a class.
832-
* @param methodName the static method name
833832
* @param clazz the class which defines the method
833+
* @param methodName the static method name
834834
* @param args the parameter types to the method
835835
* @return the static method, or {@code null} if no static method was found
836836
* @throws IllegalArgumentException if the method name is blank or the clazz is null
@@ -901,7 +901,7 @@ public static boolean isPrimitiveWrapperArray(Class<?> clazz) {
901901
*/
902902
public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
903903
Assert.notNull(clazz, "Class must not be null");
904-
return (clazz.isPrimitive() && clazz != void.class? primitiveTypeToWrapperMap.get(clazz) : clazz);
904+
return (clazz.isPrimitive() && clazz != void.class ? primitiveTypeToWrapperMap.get(clazz) : clazz);
905905
}
906906

907907
/**
@@ -978,7 +978,7 @@ public static String convertClassNameToResourcePath(String className) {
978978
* loading a resource file that is in the same package as a class file,
979979
* although {@link org.springframework.core.io.ClassPathResource} is usually
980980
* even more convenient.
981-
* @param clazz the Class whose package will be used as the base
981+
* @param clazz the Class whose package will be used as the base
982982
* @param resourceName the resource name to append. A leading slash is optional.
983983
* @return the built-up resource path
984984
* @see ClassLoader#getResource

spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -88,43 +88,40 @@ private TypedValue getValueInternal(TypedValue contextObject, EvaluationContext
8888
if (result.getValue() == null && isAutoGrowNullReferences &&
8989
nextChildIs(Indexer.class, PropertyOrFieldReference.class)) {
9090
TypeDescriptor resultDescriptor = result.getTypeDescriptor();
91-
// Creating lists and maps
92-
if ((resultDescriptor.getType().equals(List.class) || resultDescriptor.getType().equals(Map.class))) {
93-
// Create a new collection or map ready for the indexer
94-
if (resultDescriptor.getType().equals(List.class)) {
95-
try {
96-
if (isWritableProperty(this.name,contextObject,eContext)) {
97-
List<?> newList = ArrayList.class.newInstance();
98-
writeProperty(contextObject, eContext, this.name, newList);
99-
result = readProperty(contextObject, eContext, this.name);
100-
}
101-
}
102-
catch (InstantiationException ex) {
103-
throw new SpelEvaluationException(getStartPosition(), ex,
104-
SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING);
105-
}
106-
catch (IllegalAccessException ex) {
107-
throw new SpelEvaluationException(getStartPosition(), ex,
108-
SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING);
91+
// Create a new collection or map ready for the indexer
92+
if (List.class.equals(resultDescriptor.getType())) {
93+
try {
94+
if (isWritableProperty(this.name, contextObject, eContext)) {
95+
List<?> newList = ArrayList.class.newInstance();
96+
writeProperty(contextObject, eContext, this.name, newList);
97+
result = readProperty(contextObject, eContext, this.name);
10998
}
11099
}
111-
else {
112-
try {
113-
if (isWritableProperty(this.name,contextObject,eContext)) {
114-
Map<?,?> newMap = HashMap.class.newInstance();
115-
writeProperty(contextObject, eContext, this.name, newMap);
116-
result = readProperty(contextObject, eContext, this.name);
117-
}
118-
}
119-
catch (InstantiationException ex) {
120-
throw new SpelEvaluationException(getStartPosition(), ex,
121-
SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING);
122-
}
123-
catch (IllegalAccessException ex) {
124-
throw new SpelEvaluationException(getStartPosition(), ex,
125-
SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING);
100+
catch (InstantiationException ex) {
101+
throw new SpelEvaluationException(getStartPosition(), ex,
102+
SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING);
103+
}
104+
catch (IllegalAccessException ex) {
105+
throw new SpelEvaluationException(getStartPosition(), ex,
106+
SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING);
107+
}
108+
}
109+
else if (Map.class.equals(resultDescriptor.getType())) {
110+
try {
111+
if (isWritableProperty(this.name, contextObject, eContext)) {
112+
Map<?,?> newMap = HashMap.class.newInstance();
113+
writeProperty(contextObject, eContext, this.name, newMap);
114+
result = readProperty(contextObject, eContext, this.name);
126115
}
127116
}
117+
catch (InstantiationException ex) {
118+
throw new SpelEvaluationException(getStartPosition(), ex,
119+
SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING);
120+
}
121+
catch (IllegalAccessException ex) {
122+
throw new SpelEvaluationException(getStartPosition(), ex,
123+
SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING);
124+
}
128125
}
129126
else {
130127
// 'simple' object

spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,8 +47,8 @@
4747
* type {@link MultipartFile} in conjunction with Spring's {@link MultipartResolver}
4848
* abstraction, and arguments of type {@code javax.servlet.http.Part} in conjunction
4949
* with Servlet 3.0 multipart requests. This resolver can also be created in default
50-
* resolution mode in which simple types (int, long, etc.) not annotated
51-
* with @{@link RequestParam} are also treated as request parameters with the
50+
* resolution mode in which simple types (int, long, etc.) not annotated with
51+
* @{@link RequestParam} are also treated as request parameters with the
5252
* parameter name derived from the argument name.
5353
*
5454
* <p>If the method parameter type is {@link Map}, the name specified in the
@@ -131,19 +131,16 @@ else if (this.useDefaultResolution) {
131131

132132
@Override
133133
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
134-
RequestParam annotation = parameter.getParameterAnnotation(RequestParam.class);
135-
return (annotation != null) ?
136-
new RequestParamNamedValueInfo(annotation) :
137-
new RequestParamNamedValueInfo();
134+
RequestParam ann = parameter.getParameterAnnotation(RequestParam.class);
135+
return (ann != null ? new RequestParamNamedValueInfo(ann) : new RequestParamNamedValueInfo());
138136
}
139137

140138
@Override
141139
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest) throws Exception {
142-
Object arg;
143-
144140
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
145141
MultipartHttpServletRequest multipartRequest =
146-
WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);
142+
WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);
143+
Object arg;
147144

148145
if (MultipartFile.class.equals(parameter.getParameterType())) {
149146
assertIsMultipartRequest(servletRequest);
@@ -170,7 +167,7 @@ else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName()
170167
if (arg == null) {
171168
String[] paramValues = webRequest.getParameterValues(name);
172169
if (paramValues != null) {
173-
arg = paramValues.length == 1 ? paramValues[0] : paramValues;
170+
arg = (paramValues.length == 1 ? paramValues[0] : paramValues);
174171
}
175172
}
176173
}
@@ -189,7 +186,7 @@ private boolean isMultipartFileCollection(MethodParameter parameter) {
189186
Class<?> paramType = parameter.getParameterType();
190187
if (Collection.class.equals(paramType) || List.class.isAssignableFrom(paramType)){
191188
Class<?> valueType = GenericCollectionTypeResolver.getCollectionParameterType(parameter);
192-
if (valueType != null && valueType.equals(MultipartFile.class)) {
189+
if (MultipartFile.class.equals(valueType)) {
193190
return true;
194191
}
195192
}

0 commit comments

Comments
 (0)