From d7d1b495f2775df0c03d7cff33d0a07c0e3e83dd Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 10 Jan 2012 16:02:00 +0100 Subject: [PATCH] Polish "Support flash attrs..." and related classes - Eliminate trailing whitespace - Update long method signatures to follow framework whitespace conventions Based on the following search, $ git grep -A3 '^.public .* .*([^\{;]*$' */src/main the strong convention throughout the framework when dealing with methods having long signatures (i.e. many parameters) is to break immediately after the opening paren, indent two tabs deeper and break lines around 90 characters as necessary. Such signatures should also be followed by a newline after the opening curly brace to break things up visually. The files edited in this commit had a particularly different style of intenting arguments to align with each other vertically, but the alignment only worked if one's tabstop is set at four spaces. When viewed at a different tabstop value, the effect is is jarring, both in that it is misaligned and significantly different from most of the framework. The convention described above reads well at any tabstop value. --- .../annotation/HttpEntityMethodProcessor.java | 31 ++++++----- .../ModelAndViewMethodReturnValueHandler.java | 29 ++++++----- ...dViewResolverMethodReturnValueHandler.java | 34 ++++++------ ...irectAttributesMethodArgumentResolver.java | 15 +++--- .../ServletInvocableHandlerMethod.java | 12 ++--- .../ServletRequestMethodArgumentResolver.java | 20 +++---- ...ServletResponseMethodArgumentResolver.java | 18 +++---- ...mponentsBuilderMethodArgumentResolver.java | 14 ++--- .../ViewMethodReturnValueHandler.java | 23 ++++---- .../ViewNameMethodReturnValueHandler.java | 23 ++++---- ...lAndViewMethodReturnValueHandlerTests.java | 30 +++++------ ...tractNamedValueMethodArgumentResolver.java | 35 +++++++------ .../AbstractWebArgumentResolverAdapter.java | 37 ++++++------- .../ErrorsMethodArgumentResolver.java | 19 +++---- .../method/annotation/MapMethodProcessor.java | 32 ++++++------ .../ModelAttributeMethodProcessor.java | 52 ++++++++++--------- .../annotation/ModelMethodProcessor.java | 34 ++++++------ ...equestHeaderMapMethodArgumentResolver.java | 23 ++++---- ...RequestParamMapMethodArgumentResolver.java | 23 ++++---- .../SessionStatusMethodArgumentResolver.java | 13 ++--- ...andlerMethodArgumentResolverComposite.java | 25 ++++----- ...dlerMethodReturnValueHandlerComposite.java | 29 ++++++----- .../support/InvocableHandlerMethod.java | 49 ++++++++--------- 23 files changed, 319 insertions(+), 301 deletions(-) diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java index cbf434d4c0..04601a4d47 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -39,13 +39,13 @@ import org.springframework.web.method.support.ModelAndViewContainer; /** * Resolves {@link HttpEntity} method argument values and also handles - * both {@link HttpEntity} and {@link ResponseEntity} return values. - * - *

An {@link HttpEntity} return type has a set purpose. Therefore this - * handler should be configured ahead of handlers that support any return + * both {@link HttpEntity} and {@link ResponseEntity} return values. + * + *

An {@link HttpEntity} return type has a set purpose. Therefore this + * handler should be configured ahead of handlers that support any return * value type annotated with {@code @ModelAttribute} or {@code @ResponseBody} * to ensure they don't take over. - * + * * @author Arjen Poutsma * @author Rossen Stoyanchev * @since 3.1 @@ -66,10 +66,9 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro return HttpEntity.class.equals(parameterType) || ResponseEntity.class.equals(parameterType); } - public Object resolveArgument(MethodParameter parameter, - ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, - WebDataBinderFactory binderFactory) + public Object resolveArgument( + MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws IOException, HttpMediaTypeNotSupportedException { HttpInputMessage inputMessage = createInputMessage(webRequest); @@ -100,11 +99,11 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro + "in method " + parameter.getMethod() + "is not parameterized"); } - public void handleReturnValue(Object returnValue, - MethodParameter returnType, - ModelAndViewContainer mavContainer, - NativeWebRequest webRequest) throws Exception { - + public void handleReturnValue( + Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) + throws Exception { + mavContainer.setRequestHandled(true); if (returnValue == null) { @@ -135,4 +134,4 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro } } -} \ No newline at end of file +} diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java index b5494f5061..cca424048e 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java @@ -25,15 +25,15 @@ import org.springframework.web.servlet.SmartView; import org.springframework.web.servlet.View; /** - * Handles return values of type {@link ModelAndView} copying view and model + * Handles return values of type {@link ModelAndView} copying view and model * information to the {@link ModelAndViewContainer}. - * - *

If the return value is {@code null}, the - * {@link ModelAndViewContainer#setRequestHandled(boolean)} flag is set to + * + *

If the return value is {@code null}, the + * {@link ModelAndViewContainer#setRequestHandled(boolean)} flag is set to * {@code false} to indicate the request was handled directly. - * - *

A {@link ModelAndView} return type has a set purpose. Therefore this - * handler should be configured ahead of handlers that support any return + * + *

A {@link ModelAndView} return type has a set purpose. Therefore this + * handler should be configured ahead of handlers that support any return * value type annotated with {@code @ModelAttribute} or {@code @ResponseBody} * to ensure they don't take over. * @@ -41,20 +41,21 @@ import org.springframework.web.servlet.View; * @since 3.1 */ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturnValueHandler { - + public boolean supportsReturnType(MethodParameter returnType) { return ModelAndView.class.isAssignableFrom(returnType.getParameterType()); } - public void handleReturnValue(Object returnValue, - MethodParameter returnType, - ModelAndViewContainer mavContainer, - NativeWebRequest webRequest) throws Exception { + public void handleReturnValue( + Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) + throws Exception { + if (returnValue == null) { mavContainer.setRequestHandled(true); return; } - + ModelAndView mav = (ModelAndView) returnValue; if (mav.isReference()) { String viewName = mav.getViewName(); @@ -75,4 +76,4 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn mavContainer.addAllAttributes(mav.getModel()); } -} \ No newline at end of file +} diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java index 121ad3ecc0..d1ede55c57 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -29,25 +29,25 @@ import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; /** - * This return value handler is intended to be ordered after all others as it + * This return value handler is intended to be ordered after all others as it * attempts to handle _any_ return value type (i.e. returns {@code true} for * all return types). - * + * *

The return value is handled either with a {@link ModelAndViewResolver} - * or otherwise by regarding it as a model attribute if it is a non-simple - * type. If neither of these succeeds (essentially simple type other than + * or otherwise by regarding it as a model attribute if it is a non-simple + * type. If neither of these succeeds (essentially simple type other than * String), {@link UnsupportedOperationException} is raised. - * - *

Note: This class is primarily needed to support + * + *

Note: This class is primarily needed to support * {@link ModelAndViewResolver}, which unfortunately cannot be properly - * adapted to the {@link HandlerMethodReturnValueHandler} contract since the + * adapted to the {@link HandlerMethodReturnValueHandler} contract since the * {@link HandlerMethodReturnValueHandler#supportsReturnType} method * cannot be implemented. Hence {@code ModelAndViewResolver}s are limited - * to always being invoked at the end after all other return value - * handlers have been given a chance. It is recommended to re-implement + * to always being invoked at the end after all other return value + * handlers have been given a chance. It is recommended to re-implement * a {@code ModelAndViewResolver} as {@code HandlerMethodReturnValueHandler}, * which also provides better access to the return type and method information. - * + * * @author Rossen Stoyanchev * @since 3.1 */ @@ -71,10 +71,10 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth return true; } - public void handleReturnValue(Object returnValue, - MethodParameter returnType, - ModelAndViewContainer mavContainer, - NativeWebRequest request) throws Exception { + public void handleReturnValue( + Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest request) + throws Exception { if (this.mavResolvers != null) { for (ModelAndViewResolver mavResolver : this.mavResolvers) { @@ -93,7 +93,7 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth } } - // No suitable ModelAndViewResolver.. + // No suitable ModelAndViewResolver.. if (this.modelAttributeProcessor.supportsReturnType(returnType)) { this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, request); @@ -104,4 +104,4 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth } } -} \ No newline at end of file +} diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java index 272ab04ff9..89d4849c3d 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -30,8 +30,8 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; /** - * Resolves method arguments of type {@link RedirectAttributes}. - * + * Resolves method arguments of type {@link RedirectAttributes}. + * *

This resolver must be listed ahead of {@link org.springframework.web.method.annotation.ModelMethodProcessor} and * {@link org.springframework.web.method.annotation.MapMethodProcessor}, which support {@link Map} and {@link Model} * arguments both of which are "super" types of {@code RedirectAttributes} @@ -46,10 +46,11 @@ public class RedirectAttributesMethodArgumentResolver implements HandlerMethodAr return RedirectAttributes.class.isAssignableFrom(parameter.getParameterType()); } - public Object resolveArgument(MethodParameter parameter, - ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, - WebDataBinderFactory binderFactory) throws Exception { + public Object resolveArgument( + MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) + throws Exception { + DataBinder dataBinder = binderFactory.createBinder(webRequest, null, null); ModelMap redirectAttributes = new RedirectAttributesModelMap(dataBinder); mavContainer.setRedirectModel(redirectAttributes); diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java index 348be0654a..3eb3261fb7 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -89,9 +89,9 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { * @param mavContainer the {@link ModelAndViewContainer} for the current request * @param providedArgs argument values to try to use without the need for view resolution */ - public final void invokeAndHandle(NativeWebRequest request, - ModelAndViewContainer mavContainer, - Object...providedArgs) throws Exception { + public final void invokeAndHandle( + NativeWebRequest request, ModelAndViewContainer mavContainer, + Object... providedArgs) throws Exception { Object returnValue = invokeForRequest(request, mavContainer, providedArgs); @@ -124,7 +124,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { sb.append("[value=" + returnValue + "]"); return getDetailedErrorMessage(sb.toString()); } - + /** * Set the response status according to the {@link ResponseStatus} annotation. */ @@ -157,4 +157,4 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { private boolean hasResponseStatus() { return responseStatus != null; } -} \ No newline at end of file +} diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java index 6976861adb..a6e9f7f933 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -37,7 +37,7 @@ import org.springframework.web.multipart.MultipartRequest; import org.springframework.web.servlet.support.RequestContextUtils; /** - * Resolves request-related method argument values of the following types: + * Resolves request-related method argument values of the following types: *