From 61579ffe7b8dc60c69224b71073da4255012311b Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 22 Jan 2018 21:34:44 +0100 Subject: [PATCH] Polishing --- .../context/web/AbstractGenericWebContextLoader.java | 3 +-- .../method/SyncHandlerMethodArgumentResolver.java | 6 +++--- .../AbstractNamedValueSyncArgumentResolver.java | 11 +++++------ .../MatrixVariableMapMethodArgumentResolver.java | 7 +++---- .../MatrixVariableMethodArgumentResolver.java | 12 +++++------- .../method/annotation/ModelArgumentResolver.java | 7 +++---- .../PathVariableMapMethodArgumentResolver.java | 8 ++++---- .../RequestHeaderMapMethodArgumentResolver.java | 12 +++++------- .../RequestParamMapMethodArgumentResolver.java | 11 +++++------ .../ServerWebExchangeArgumentResolver.java | 7 +++---- .../SessionStatusMethodArgumentResolver.java | 8 ++++---- .../MatrixVariableMapMethodArgumentResolver.java | 5 ++--- 12 files changed, 43 insertions(+), 54 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java index f1a35bade1f..7f21760f9cd 100644 --- a/spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java +++ b/spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java @@ -190,7 +190,6 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa } else { ServletContext servletContext = null; - // Find the root WebApplicationContext while (parent != null) { if (parent instanceof WebApplicationContext && !(parent.getParent() instanceof WebApplicationContext)) { @@ -199,7 +198,7 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa } parent = parent.getParent(); } - Assert.state(servletContext != null, "Failed to find Root WebApplicationContext in the context hierarchy"); + Assert.state(servletContext != null, "Failed to find root WebApplicationContext in the context hierarchy"); context.setServletContext(servletContext); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncHandlerMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncHandlerMethodArgumentResolver.java index 6c1a96a442e..68e85de7836 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncHandlerMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncHandlerMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -52,7 +52,7 @@ public interface SyncHandlerMethodArgumentResolver extends HandlerMethodArgument * @return the resolved value, if any */ @Nullable - Object resolveArgumentValue(MethodParameter parameter, BindingContext bindingContext, - ServerWebExchange exchange); + Object resolveArgumentValue( + MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java index 5251be88bd5..962baea1cb8 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -38,15 +38,14 @@ import org.springframework.web.server.ServerWebExchange; public abstract class AbstractNamedValueSyncArgumentResolver extends AbstractNamedValueArgumentResolver implements SyncHandlerMethodArgumentResolver { - /** * @param factory a bean factory to use for resolving ${...} * placeholder and #{...} SpEL expressions in default values; * or {@code null} if default values are not expected to have expressions * @param registry for checking reactive type wrappers */ - protected AbstractNamedValueSyncArgumentResolver(@Nullable ConfigurableBeanFactory factory, - ReactiveAdapterRegistry registry) { + protected AbstractNamedValueSyncArgumentResolver( + @Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { super(factory, registry); } @@ -65,8 +64,8 @@ public abstract class AbstractNamedValueSyncArgumentResolver extends AbstractNam } @Override - public Object resolveArgumentValue(MethodParameter parameter, BindingContext context, - ServerWebExchange exchange) { + public Object resolveArgumentValue( + MethodParameter parameter, BindingContext context, ServerWebExchange exchange) { // This won't block since resolveName below doesn't return resolveArgument(parameter, context, exchange).block(); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMapMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMapMethodArgumentResolver.java index 8476b27f01d..1a81a98fb65 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMapMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMapMethodArgumentResolver.java @@ -40,7 +40,7 @@ import org.springframework.web.server.ServerWebExchange; /** * Resolves arguments of type {@link Map} annotated with {@link MatrixVariable @MatrixVariable} * where the annotation does not specify a name. In other words the purpose of this resolver - * is to provide access to multiple matrix variables, either all or associted with a specific + * is to provide access to multiple matrix variables, either all or associated with a specific * path variable. * *

When a name is specified, an argument of type Map is considered to be a single attribute @@ -53,7 +53,6 @@ import org.springframework.web.server.ServerWebExchange; public class MatrixVariableMapMethodArgumentResolver extends HandlerMethodArgumentResolverSupport implements SyncHandlerMethodArgumentResolver { - public MatrixVariableMapMethodArgumentResolver(ReactiveAdapterRegistry registry) { super(registry); } @@ -62,7 +61,7 @@ public class MatrixVariableMapMethodArgumentResolver extends HandlerMethodArgume @Override public boolean supportsParameter(MethodParameter parameter) { return checkAnnotatedParamNoReactiveWrapper(parameter, MatrixVariable.class, - (annot, type) -> (Map.class.isAssignableFrom(type) && !StringUtils.hasText(annot.name()))); + (ann, type) -> (Map.class.isAssignableFrom(type) && !StringUtils.hasText(ann.name()))); } @Nullable @@ -113,4 +112,4 @@ public class MatrixVariableMapMethodArgumentResolver extends HandlerMethodArgume return false; } -} \ No newline at end of file +} diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMethodArgumentResolver.java index 7310fb23c23..a2824b4c859 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.result.method.annotation; import java.util.ArrayList; @@ -48,9 +49,8 @@ import org.springframework.web.server.ServerWebInputException; */ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueSyncArgumentResolver { - - protected MatrixVariableMethodArgumentResolver(@Nullable ConfigurableBeanFactory factory, - ReactiveAdapterRegistry registry) { + public MatrixVariableMethodArgumentResolver( + @Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { super(factory, registry); } @@ -59,7 +59,7 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueSync @Override public boolean supportsParameter(MethodParameter parameter) { return checkAnnotatedParamNoReactiveWrapper(parameter, MatrixVariable.class, - (annot, type) -> !Map.class.isAssignableFrom(type) || StringUtils.hasText(annot.name())); + (ann, type) -> !Map.class.isAssignableFrom(type) || StringUtils.hasText(ann.name())); } @@ -73,10 +73,8 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueSync @Nullable @Override protected Object resolveNamedValue(String name, MethodParameter param, ServerWebExchange exchange) { - Map> pathParameters = exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE); - if (CollectionUtils.isEmpty(pathParameters)) { return null; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelArgumentResolver.java index cd6fa1a41ce..e67fe62f82a 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -21,7 +21,6 @@ import java.util.Map; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.ui.Model; -import org.springframework.util.Assert; import org.springframework.web.reactive.BindingContext; import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport; import org.springframework.web.reactive.result.method.SyncHandlerMethodArgumentResolver; @@ -49,8 +48,8 @@ public class ModelArgumentResolver extends HandlerMethodArgumentResolverSupport } @Override - public Object resolveArgumentValue(MethodParameter parameter, BindingContext context, - ServerWebExchange exchange) { + public Object resolveArgumentValue( + MethodParameter parameter, BindingContext context, ServerWebExchange exchange) { Class type = parameter.getParameterType(); if (Model.class.isAssignableFrom(type)) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PathVariableMapMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PathVariableMapMethodArgumentResolver.java index 9cd93e005ec..f73e470be5a 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PathVariableMapMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PathVariableMapMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -53,13 +53,13 @@ public class PathVariableMapMethodArgumentResolver extends HandlerMethodArgument } private boolean allVariables(PathVariable pathVariable, Class type) { - return Map.class.isAssignableFrom(type) && !StringUtils.hasText(pathVariable.value()); + return (Map.class.isAssignableFrom(type) && !StringUtils.hasText(pathVariable.value())); } @Override - public Object resolveArgumentValue(MethodParameter methodParameter, BindingContext context, - ServerWebExchange exchange) { + public Object resolveArgumentValue( + MethodParameter methodParameter, BindingContext context, ServerWebExchange exchange) { String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE; return exchange.getAttributeOrDefault(name, Collections.emptyMap()); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMapMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMapMethodArgumentResolver.java index 8ee570a97a6..b0124287485 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMapMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMapMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -60,14 +60,12 @@ public class RequestHeaderMapMethodArgumentResolver extends HandlerMethodArgumen @Override - public Object resolveArgumentValue(MethodParameter methodParameter, - BindingContext context, ServerWebExchange exchange) { - - Class paramType = methodParameter.getParameterType(); - boolean isMultiValueMap = MultiValueMap.class.isAssignableFrom(paramType); + public Object resolveArgumentValue( + MethodParameter methodParameter, BindingContext context, ServerWebExchange exchange) { + boolean isMultiValueMap = MultiValueMap.class.isAssignableFrom(methodParameter.getParameterType()); HttpHeaders headers = exchange.getRequest().getHeaders(); - return isMultiValueMap ? headers : headers.toSingleValueMap(); + return (isMultiValueMap ? headers : headers.toSingleValueMap()); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolver.java index 32f59681e57..1b1bba87e96 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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,7 +47,6 @@ import org.springframework.web.server.ServerWebExchange; public class RequestParamMapMethodArgumentResolver extends HandlerMethodArgumentResolverSupport implements SyncHandlerMethodArgumentResolver { - public RequestParamMapMethodArgumentResolver(ReactiveAdapterRegistry adapterRegistry) { super(adapterRegistry); } @@ -59,17 +58,17 @@ public class RequestParamMapMethodArgumentResolver extends HandlerMethodArgument } private boolean allParams(RequestParam requestParam, Class type) { - return Map.class.isAssignableFrom(type) && !StringUtils.hasText(requestParam.name()); + return (Map.class.isAssignableFrom(type) && !StringUtils.hasText(requestParam.name())); } @Override - public Object resolveArgumentValue(MethodParameter methodParameter, BindingContext context, - ServerWebExchange exchange) { + public Object resolveArgumentValue( + MethodParameter methodParameter, BindingContext context, ServerWebExchange exchange) { boolean isMultiValueMap = MultiValueMap.class.isAssignableFrom(methodParameter.getParameterType()); MultiValueMap queryParams = exchange.getRequest().getQueryParams(); - return isMultiValueMap ? queryParams : queryParams.toSingleValueMap(); + return (isMultiValueMap ? queryParams : queryParams.toSingleValueMap()); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolver.java index c9e8433bcbe..7577b9ae351 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -25,7 +25,6 @@ import org.springframework.context.i18n.TimeZoneAwareLocaleContext; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.http.HttpMethod; -import org.springframework.http.HttpRequest; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.lang.Nullable; @@ -80,8 +79,8 @@ public class ServerWebExchangeArgumentResolver extends HandlerMethodArgumentReso } @Override - public Object resolveArgumentValue(MethodParameter methodParameter, BindingContext context, - ServerWebExchange exchange) { + public Object resolveArgumentValue( + MethodParameter methodParameter, BindingContext context, ServerWebExchange exchange) { Class paramType = methodParameter.getParameterType(); if (ServerWebExchange.class.isAssignableFrom(paramType)) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionStatusMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionStatusMethodArgumentResolver.java index c6c847164df..15a10010e98 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionStatusMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionStatusMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.result.method.annotation; import org.springframework.core.MethodParameter; @@ -32,7 +33,6 @@ import org.springframework.web.server.ServerWebExchange; */ public class SessionStatusMethodArgumentResolver implements SyncHandlerMethodArgumentResolver { - @Override public boolean supportsParameter(MethodParameter parameter) { return SessionStatus.class == parameter.getParameterType(); @@ -40,8 +40,8 @@ public class SessionStatusMethodArgumentResolver implements SyncHandlerMethodArg @Nullable @Override - public Object resolveArgumentValue(MethodParameter parameter, BindingContext bindingContext, - ServerWebExchange exchange) { + public Object resolveArgumentValue( + MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) { Assert.isInstanceOf(InitBinderBindingContext.class, bindingContext); return ((InitBinderBindingContext) bindingContext).getSessionStatus(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java index d1407e71298..1fbd904b5c7 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java @@ -40,7 +40,7 @@ import org.springframework.web.servlet.HandlerMapping; /** * Resolves arguments of type {@link Map} annotated with {@link MatrixVariable @MatrixVariable} * where the annotation does not specify a name. In other words the purpose of this resolver - * is to provide access to multiple matrix variables, either all or associted with a specific + * is to provide access to multiple matrix variables, either all or associated with a specific * path variable. * *

When a name is specified, an argument of type Map is considered to be a single attribute @@ -51,7 +51,6 @@ import org.springframework.web.servlet.HandlerMapping; */ public class MatrixVariableMapMethodArgumentResolver implements HandlerMethodArgumentResolver { - @Override public boolean supportsParameter(MethodParameter parameter) { MatrixVariable matrixVariable = parameter.getParameterAnnotation(MatrixVariable.class); @@ -113,4 +112,4 @@ public class MatrixVariableMapMethodArgumentResolver implements HandlerMethodArg return false; } -} \ No newline at end of file +}