Skip to content

Commit ea534b6

Browse files
committed
Polishing
1 parent 5a11112 commit ea534b6

File tree

13 files changed

+42
-51
lines changed

13 files changed

+42
-51
lines changed

spring-aspects/src/main/java/org/springframework/transaction/aspectj/JtaAnnotationTransactionAspect.aj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import org.springframework.transaction.annotation.AnnotationTransactionAttribute
4545
* @see javax.transaction.Transactional
4646
* @see AnnotationTransactionAspect
4747
*/
48-
@RequiredTypes({"javax.transaction.Transactional"})
48+
@RequiredTypes("javax.transaction.Transactional")
4949
public aspect JtaAnnotationTransactionAspect extends AbstractTransactionAspect {
5050

5151
public JtaAnnotationTransactionAspect() {

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MessageMethodArgumentResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -97,7 +97,7 @@ public Object resolveArgument(MethodParameter parameter, Message<?> message) thr
9797
private Class<?> getPayloadType(MethodParameter parameter) {
9898
Type genericParamType = parameter.getGenericParameterType();
9999
ResolvableType resolvableType = ResolvableType.forType(genericParamType).as(Message.class);
100-
return resolvableType.getGeneric(0).resolve(Object.class);
100+
return resolvableType.getGeneric().resolve(Object.class);
101101
}
102102

103103
/**

spring-test/src/main/java/org/springframework/mock/http/client/reactive/MockClientHttpRequest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -36,6 +36,7 @@
3636

3737
/**
3838
* Mock implementation of {@link ClientHttpRequest}.
39+
*
3940
* @author Brian Clozel
4041
* @author Rossen Stoyanchev
4142
* @since 5.0
@@ -97,11 +98,9 @@ public Flux<DataBuffer> getBody() {
9798

9899
/**
99100
* Configure a custom handler for writing the request body.
100-
*
101101
* <p>The default write handler consumes and caches the request body so it
102102
* may be accessed subsequently, e.g. in test assertions. Use this property
103103
* when the request body is an infinite stream.
104-
*
105104
* @param writeHandler the write handler to use returning {@code Mono<Void>}
106105
* when the body has been "written" (i.e. consumed).
107106
*/

spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpResponse.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -125,10 +125,8 @@ public Flux<DataBuffer> getBody() {
125125
* charset or "UTF-8" by default.
126126
*/
127127
public Mono<String> getBodyAsString() {
128-
129128
Charset charset = Optional.ofNullable(getHeaders().getContentType()).map(MimeType::getCharset)
130129
.orElse(StandardCharsets.UTF_8);
131-
132130
return getBody()
133131
.reduce(bufferFactory().allocateBuffer(), (previous, current) -> {
134132
previous.write(current);
@@ -139,7 +137,6 @@ public Mono<String> getBodyAsString() {
139137
}
140138

141139
private static String bufferToString(DataBuffer buffer, Charset charset) {
142-
Assert.notNull(charset, "'charset' must not be null");
143140
byte[] bytes = new byte[buffer.readableByteCount()];
144141
buffer.read(bytes);
145142
return new String(bytes, charset);

spring-test/src/main/java/org/springframework/test/web/client/AbstractRequestExpectationManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,16 @@ private void updateInternal(RequestExpectation expectation) {
239239

240240
/**
241241
* Add expectations to this group.
242-
* @deprecated as of 5.0.3 please use {@link #addAllExpectations(Collection)} instead.
242+
* @deprecated as of 5.0.3, if favor of {@link #addAllExpectations}
243243
*/
244244
@Deprecated
245245
public void updateAll(Collection<RequestExpectation> expectations) {
246246
expectations.forEach(this::updateInternal);
247247
}
248248

249+
/**
250+
* Reset all expectations for this group.
251+
*/
249252
public void reset() {
250253
this.expectations.clear();
251254
}

spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public Flux<Object> read(ResolvableType elementType, ReactiveHttpInputMessage me
103103
Map<String, Object> hints) {
104104

105105
boolean shouldWrap = isServerSentEvent(elementType);
106-
ResolvableType valueType = (shouldWrap ? elementType.getGeneric(0) : elementType);
106+
ResolvableType valueType = (shouldWrap ? elementType.getGeneric() : elementType);
107107

108108
return stringDecoder.decode(message.getBody(), STRING_TYPE, null, Collections.emptyMap())
109109
.bufferUntil(line -> line.equals(""))

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -123,7 +123,7 @@ protected Mono<Void> writeBody(@Nullable Object body, MethodParameter bodyParame
123123
ResolvableType elementType;
124124
if (adapter != null) {
125125
publisher = adapter.toPublisher(body);
126-
ResolvableType genericType = bodyType.getGeneric(0);
126+
ResolvableType genericType = bodyType.getGeneric();
127127
elementType = getElementType(adapter, genericType);
128128
}
129129
else {

spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public abstract class AbstractView implements View, ApplicationContextAware {
5656
private static final Object NO_VALUE = new Object();
5757

5858

59-
private final List<MediaType> mediaTypes = new ArrayList<>(4);
59+
private final ReactiveAdapterRegistry reactiveAdapterRegistry;
6060

61-
private final ReactiveAdapterRegistry adapterRegistry;
61+
private final List<MediaType> mediaTypes = new ArrayList<>(4);
6262

6363
private Charset defaultCharset = StandardCharsets.UTF_8;
6464

@@ -73,9 +73,9 @@ public AbstractView() {
7373
this(ReactiveAdapterRegistry.getSharedInstance());
7474
}
7575

76-
public AbstractView(ReactiveAdapterRegistry registry) {
76+
public AbstractView(ReactiveAdapterRegistry reactiveAdapterRegistry) {
77+
this.reactiveAdapterRegistry = reactiveAdapterRegistry;
7778
this.mediaTypes.add(ViewResolverSupport.DEFAULT_CONTENT_TYPE);
78-
this.adapterRegistry = registry;
7979
}
8080

8181

@@ -155,7 +155,7 @@ protected final ApplicationContext obtainApplicationContext() {
155155

156156
/**
157157
* Prepare the model to render.
158-
* @param model Map with name Strings as keys and corresponding model
158+
* @param model a Map with name Strings as keys and corresponding model
159159
* objects as values (Map can also be {@code null} in case of empty model)
160160
* @param contentType the content type selected to render with which should
161161
* match one of the {@link #getSupportedMediaTypes() supported media types}.
@@ -209,7 +209,6 @@ protected Mono<Map<String, Object>> getModelAttributes(@Nullable Map<String, ?>
209209
* @return {@code Mono} for the completion of async attributes resolution
210210
*/
211211
protected Mono<Void> resolveAsyncAttributes(Map<String, Object> model) {
212-
213212
List<String> names = new ArrayList<>();
214213
List<Mono<?>> valueMonos = new ArrayList<>();
215214

@@ -218,7 +217,7 @@ protected Mono<Void> resolveAsyncAttributes(Map<String, Object> model) {
218217
if (value == null) {
219218
continue;
220219
}
221-
ReactiveAdapter adapter = this.adapterRegistry.getAdapter(null, value);
220+
ReactiveAdapter adapter = this.reactiveAdapterRegistry.getAdapter(null, value);
222221
if (adapter != null) {
223222
names.add(entry.getKey());
224223
if (adapter.isMultiValue()) {

spring-webflux/src/main/java/org/springframework/web/reactive/support/AbstractAnnotationConfigDispatcherHandlerInitializer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
public abstract class AbstractAnnotationConfigDispatcherHandlerInitializer
3636
extends AbstractDispatcherHandlerInitializer {
3737

38-
3938
/**
4039
* {@inheritDoc}
4140
* <p>This implementation creates an {@link AnnotationConfigApplicationContext},

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -86,9 +86,7 @@ public ReactiveTypeHandler() {
8686
this(ReactiveAdapterRegistry.getSharedInstance(), new SyncTaskExecutor(), new ContentNegotiationManager());
8787
}
8888

89-
ReactiveTypeHandler(ReactiveAdapterRegistry registry, TaskExecutor executor,
90-
ContentNegotiationManager manager) {
91-
89+
ReactiveTypeHandler(ReactiveAdapterRegistry registry, TaskExecutor executor, ContentNegotiationManager manager) {
9290
Assert.notNull(registry, "ReactiveAdapterRegistry is required");
9391
Assert.notNull(executor, "TaskExecutor is required");
9492
Assert.notNull(manager, "ContentNegotiationManager is required");
@@ -120,7 +118,7 @@ public ResponseBodyEmitter handleValue(Object returnValue, MethodParameter retur
120118
ReactiveAdapter adapter = this.reactiveRegistry.getAdapter(returnValue.getClass());
121119
Assert.state(adapter != null, "Unexpected return value: " + returnValue);
122120

123-
ResolvableType elementType = ResolvableType.forMethodParameter(returnType).getGeneric(0);
121+
ResolvableType elementType = ResolvableType.forMethodParameter(returnType).getGeneric();
124122
Class<?> elementClass = elementType.resolve(Object.class);
125123

126124
Collection<MediaType> mediaTypes = getMediaTypes(request);
@@ -249,7 +247,7 @@ private void trySchedule() {
249247
schedule();
250248
}
251249
}
252-
250+
253251
private void schedule() {
254252
try {
255253
this.taskExecutor.execute(this);
@@ -264,7 +262,7 @@ private void schedule() {
264262
}
265263
}
266264
}
267-
265+
268266
@Override
269267
public void run() {
270268
if (this.done) {
@@ -310,7 +308,7 @@ public void run() {
310308
}
311309
return;
312310
}
313-
311+
314312
if (this.executing.decrementAndGet() != 0) {
315313
schedule();
316314
}
@@ -324,7 +322,6 @@ private void terminate() {
324322
this.subscription.cancel();
325323
}
326324
}
327-
328325
}
329326

330327

@@ -407,16 +404,12 @@ private static class DeferredResultSubscriber implements Subscriber<Object> {
407404

408405
private final CollectedValuesList values;
409406

410-
411-
DeferredResultSubscriber(DeferredResult<Object> result, ReactiveAdapter adapter,
412-
ResolvableType elementType) {
413-
407+
DeferredResultSubscriber(DeferredResult<Object> result, ReactiveAdapter adapter, ResolvableType elementType) {
414408
this.result = result;
415409
this.multiValueSource = adapter.isMultiValue();
416410
this.values = new CollectedValuesList(elementType);
417411
}
418412

419-
420413
public void connect(ReactiveAdapter adapter, Object returnValue) {
421414
Publisher<Object> publisher = adapter.toPublisher(returnValue);
422415
publisher.subscribe(this);
@@ -452,6 +445,10 @@ else if (this.values.size() == 1) {
452445
}
453446
}
454447

448+
449+
/**
450+
* List of collect values where all elements are a specified type.
451+
*/
455452
@SuppressWarnings("serial")
456453
static class CollectedValuesList extends ArrayList<Object> {
457454

@@ -466,4 +463,4 @@ public ResolvableType getReturnType() {
466463
}
467464
}
468465

469-
}
466+
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandler.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -20,7 +20,6 @@
2020
import java.io.OutputStream;
2121
import java.util.List;
2222
import java.util.function.Consumer;
23-
2423
import javax.servlet.ServletRequest;
2524
import javax.servlet.http.HttpServletResponse;
2625

@@ -83,17 +82,14 @@ public ResponseBodyEmitterReturnValueHandler(List<HttpMessageConverter<?>> messa
8382

8483
/**
8584
* Complete constructor with pluggable "reactive" type support.
86-
*
8785
* @param messageConverters converters to write emitted objects with
8886
* @param reactiveRegistry for reactive return value type support
8987
* @param executor for blocking I/O writes of items emitted from reactive types
9088
* @param manager for detecting streaming media types
91-
*
9289
* @since 5.0
9390
*/
9491
public ResponseBodyEmitterReturnValueHandler(List<HttpMessageConverter<?>> messageConverters,
95-
ReactiveAdapterRegistry reactiveRegistry, TaskExecutor executor,
96-
ContentNegotiationManager manager) {
92+
ReactiveAdapterRegistry reactiveRegistry, TaskExecutor executor, ContentNegotiationManager manager) {
9793

9894
Assert.notEmpty(messageConverters, "HttpMessageConverter List must not be empty");
9995
this.messageConverters = messageConverters;
@@ -103,16 +99,16 @@ public ResponseBodyEmitterReturnValueHandler(List<HttpMessageConverter<?>> messa
10399

104100
@Override
105101
public boolean supportsReturnType(MethodParameter returnType) {
106-
107102
Class<?> bodyType = ResponseEntity.class.isAssignableFrom(returnType.getParameterType()) ?
108-
ResolvableType.forMethodParameter(returnType).getGeneric(0).resolve() :
103+
ResolvableType.forMethodParameter(returnType).getGeneric().resolve() :
109104
returnType.getParameterType();
110105

111-
return bodyType != null && (ResponseBodyEmitter.class.isAssignableFrom(bodyType) ||
112-
this.reactiveHandler.isReactiveType(bodyType));
106+
return (bodyType != null && (ResponseBodyEmitter.class.isAssignableFrom(bodyType) ||
107+
this.reactiveHandler.isReactiveType(bodyType)));
113108
}
114109

115110
@Override
111+
@SuppressWarnings("resource")
116112
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
117113
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
118114

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -259,7 +259,7 @@ public ConcurrentResultMethodParameter(Object returnValue) {
259259
this.returnValue = returnValue;
260260
this.returnType = (returnValue instanceof ReactiveTypeHandler.CollectedValuesList ?
261261
((ReactiveTypeHandler.CollectedValuesList) returnValue).getReturnType() :
262-
ResolvableType.forType(super.getGenericParameterType()).getGeneric(0));
262+
ResolvableType.forType(super.getGenericParameterType()).getGeneric());
263263
}
264264

265265
public ConcurrentResultMethodParameter(ConcurrentResultMethodParameter original) {

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -50,13 +50,14 @@ public boolean supportsReturnType(MethodParameter returnType) {
5050
return true;
5151
}
5252
else if (ResponseEntity.class.isAssignableFrom(returnType.getParameterType())) {
53-
Class<?> bodyType = ResolvableType.forMethodParameter(returnType).getGeneric(0).resolve();
53+
Class<?> bodyType = ResolvableType.forMethodParameter(returnType).getGeneric().resolve();
5454
return (bodyType != null && StreamingResponseBody.class.isAssignableFrom(bodyType));
5555
}
5656
return false;
5757
}
5858

5959
@Override
60+
@SuppressWarnings("resource")
6061
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
6162
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
6263

0 commit comments

Comments
 (0)