Skip to content

Commit b0ed385

Browse files
committed
Polishing
1 parent 5d54adf commit b0ed385

File tree

14 files changed

+62
-93
lines changed

14 files changed

+62
-93
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java

Lines changed: 5 additions & 7 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.
@@ -227,7 +227,7 @@ public String getAspectName() {
227227
}
228228

229229
/**
230-
* Sets the <b>declaration order</b> of this advice within the aspect
230+
* Set the declaration order of this advice within the aspect.
231231
*/
232232
public void setDeclarationOrder(int order) {
233233
this.declarationOrder = order;
@@ -366,18 +366,16 @@ private boolean isVariableName(String name) {
366366
* to which argument name. There are multiple strategies for determining
367367
* this binding, which are arranged in a ChainOfResponsibility.
368368
*/
369-
public synchronized final void calculateArgumentBindings() {
369+
public final synchronized void calculateArgumentBindings() {
370370
// The simple case... nothing to bind.
371371
if (this.argumentsIntrospected || this.parameterTypes.length == 0) {
372372
return;
373373
}
374374

375375
int numUnboundArgs = this.parameterTypes.length;
376376
Class<?>[] parameterTypes = this.aspectJAdviceMethod.getParameterTypes();
377-
if (maybeBindJoinPoint(parameterTypes[0]) || maybeBindProceedingJoinPoint(parameterTypes[0])) {
378-
numUnboundArgs--;
379-
}
380-
else if (maybeBindJoinPointStaticPart(parameterTypes[0])) {
377+
if (maybeBindJoinPoint(parameterTypes[0]) || maybeBindProceedingJoinPoint(parameterTypes[0]) ||
378+
maybeBindJoinPointStaticPart(parameterTypes[0])) {
381379
numUnboundArgs--;
382380
}
383381

spring-beans-groovy/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,8 @@ else if ("ref".equals(name)) {
381381
refName = args[0].toString();
382382
}
383383
boolean parentRef = false;
384-
if (args.length > 1) {
385-
if (args[1] instanceof Boolean) {
386-
parentRef = (Boolean) args[1];
387-
}
384+
if (args.length > 1 && args[1] instanceof Boolean) {
385+
parentRef = (Boolean) args[1];
388386
}
389387
return new RuntimeBeanReference(refName, parentRef);
390388
}
@@ -411,12 +409,7 @@ else if (args.length > 1 && args[args.length -1] instanceof Closure) {
411409
}
412410

413411
private boolean addDeferredProperty(String property, Object newValue) {
414-
if (newValue instanceof List) {
415-
this.deferredProperties.put(this.currentBeanDefinition.getBeanName() + '.' + property,
416-
new DeferredProperty(this.currentBeanDefinition, property, newValue));
417-
return true;
418-
}
419-
else if (newValue instanceof Map) {
412+
if (newValue instanceof List || newValue instanceof Map) {
420413
this.deferredProperties.put(this.currentBeanDefinition.getBeanName() + '.' + property,
421414
new DeferredProperty(this.currentBeanDefinition, property, newValue));
422415
return true;

spring-beans/src/main/java/org/springframework/beans/BeanUtils.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,23 +311,23 @@ else if (!method.isBridge() && targetMethod.getParameterTypes().length == numPar
311311
public static Method resolveSignature(String signature, Class<?> clazz) {
312312
Assert.hasText(signature, "'signature' must not be empty");
313313
Assert.notNull(clazz, "Class must not be null");
314-
int firstParen = signature.indexOf('(');
315-
int lastParen = signature.indexOf(')');
316-
if (firstParen > -1 && lastParen == -1) {
314+
int startParen = signature.indexOf('(');
315+
int endParen = signature.indexOf(')');
316+
if (startParen > -1 && endParen == -1) {
317317
throw new IllegalArgumentException("Invalid method signature '" + signature +
318318
"': expected closing ')' for args list");
319319
}
320-
else if (lastParen > -1 && firstParen == -1) {
320+
else if (startParen == -1 && endParen > -1) {
321321
throw new IllegalArgumentException("Invalid method signature '" + signature +
322322
"': expected opening '(' for args list");
323323
}
324-
else if (firstParen == -1 && lastParen == -1) {
324+
else if (startParen == -1 && endParen == -1) {
325325
return findMethodWithMinimalParameters(clazz, signature);
326326
}
327327
else {
328-
String methodName = signature.substring(0, firstParen);
328+
String methodName = signature.substring(0, startParen);
329329
String[] parameterTypeNames =
330-
StringUtils.commaDelimitedListToStringArray(signature.substring(firstParen + 1, lastParen));
330+
StringUtils.commaDelimitedListToStringArray(signature.substring(startParen + 1, endParen));
331331
Class<?>[] parameterTypes = new Class<?>[parameterTypeNames.length];
332332
for (int i = 0; i < parameterTypeNames.length; i++) {
333333
String parameterTypeName = parameterTypeNames[i].trim();

spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java

Lines changed: 3 additions & 7 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-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.
@@ -262,7 +262,7 @@ public PropertyValue getPropertyValue(String propertyName) {
262262
/**
263263
* Get the raw property value, if any.
264264
* @param propertyName the name to search for
265-
* @return the raw property value, or {@code null}
265+
* @return the raw property value, or {@code null} if none found
266266
* @since 4.0
267267
* @see #getPropertyValue(String)
268268
* @see PropertyValue#getValue()
@@ -283,11 +283,7 @@ public PropertyValues changesSince(PropertyValues old) {
283283
for (PropertyValue newPv : this.propertyValueList) {
284284
// if there wasn't an old one, add it
285285
PropertyValue pvOld = old.getPropertyValue(newPv.getName());
286-
if (pvOld == null) {
287-
changes.addPropertyValue(newPv);
288-
}
289-
else if (!pvOld.equals(newPv)) {
290-
// it's changed
286+
if (pvOld == null || !pvOld.equals(newPv)) {
291287
changes.addPropertyValue(newPv);
292288
}
293289
}

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ private void processDeferredImportSelectors() {
561561
}
562562

563563
private void processImports(ConfigurationClass configClass, SourceClass currentSourceClass,
564-
Collection<SourceClass> importCandidates, boolean checkForCircularImports) throws IOException {
564+
Collection<SourceClass> importCandidates, boolean checkForCircularImports) {
565565

566566
if (importCandidates.isEmpty()) {
567567
return;
@@ -702,7 +702,8 @@ SourceClass asSourceClass(String className) throws IOException {
702702
@SuppressWarnings("serial")
703703
private static class ImportStack extends ArrayDeque<ConfigurationClass> implements ImportRegistry {
704704

705-
private final MultiValueMap<String, AnnotationMetadata> imports = new LinkedMultiValueMap<String, AnnotationMetadata>();
705+
private final MultiValueMap<String, AnnotationMetadata> imports =
706+
new LinkedMultiValueMap<String, AnnotationMetadata>();
706707

707708
public void registerImport(AnnotationMetadata importingClass, String importedClass) {
708709
this.imports.add(importedClass, importingClass);
@@ -948,9 +949,9 @@ private static class CircularImportProblem extends Problem {
948949
public CircularImportProblem(ConfigurationClass attemptedImport, Deque<ConfigurationClass> importStack) {
949950
super(String.format("A circular @Import has been detected: " +
950951
"Illegal attempt by @Configuration class '%s' to import class '%s' as '%s' is " +
951-
"already present in the current import stack %s", importStack.peek().getSimpleName(),
952+
"already present in the current import stack %s", importStack.element().getSimpleName(),
952953
attemptedImport.getSimpleName(), attemptedImport.getSimpleName(), importStack),
953-
new Location(importStack.peek().getResource(), attemptedImport.getMetadata()));
954+
new Location(importStack.element().getResource(), attemptedImport.getMetadata()));
954955
}
955956
}
956957

spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java

Lines changed: 7 additions & 5 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.
@@ -134,8 +134,9 @@ public void success(T result) {
134134
synchronized (this.mutex) {
135135
this.state = State.SUCCESS;
136136
this.result = result;
137-
while (!this.successCallbacks.isEmpty()) {
138-
notifySuccess(this.successCallbacks.poll());
137+
SuccessCallback<? super T> callback;
138+
while ((callback = this.successCallbacks.poll()) != null) {
139+
notifySuccess(callback);
139140
}
140141
}
141142
}
@@ -149,8 +150,9 @@ public void failure(Throwable ex) {
149150
synchronized (this.mutex) {
150151
this.state = State.FAILURE;
151152
this.result = ex;
152-
while (!this.failureCallbacks.isEmpty()) {
153-
notifyFailure(this.failureCallbacks.poll());
153+
FailureCallback callback;
154+
while ((callback = this.failureCallbacks.poll()) != null) {
155+
notifyFailure(callback);
154156
}
155157
}
156158
}

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

Lines changed: 4 additions & 4 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-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.
@@ -57,7 +57,7 @@ public interface ValueRef {
5757
/**
5858
* A ValueRef for the null value.
5959
*/
60-
static class NullValueRef implements ValueRef {
60+
class NullValueRef implements ValueRef {
6161

6262
static final NullValueRef INSTANCE = new NullValueRef();
6363

@@ -84,13 +84,13 @@ public boolean isWritable() {
8484
/**
8585
* A ValueRef holder for a single value, which cannot be set.
8686
*/
87-
static class TypedValueHolderValueRef implements ValueRef {
87+
class TypedValueHolderValueRef implements ValueRef {
8888

8989
private final TypedValue typedValue;
9090

9191
private final SpelNodeImpl node; // used only for error reporting
9292

93-
public TypedValueHolderValueRef(TypedValue typedValue,SpelNodeImpl node) {
93+
public TypedValueHolderValueRef(TypedValue typedValue, SpelNodeImpl node) {
9494
this.typedValue = typedValue;
9595
this.node = node;
9696
}

spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,7 @@ private TypeDescriptor getTypeDescriptor(EvaluationContext context, Object targe
349349
if (typeDescriptor == null) {
350350
// Attempt to populate the cache entry
351351
try {
352-
if (canRead(context, target, name)) {
353-
typeDescriptor = this.typeDescriptorCache.get(cacheKey);
354-
}
355-
else if (canWrite(context, target, name)) {
352+
if (canRead(context, target, name) || canWrite(context, target, name)) {
356353
typeDescriptor = this.typeDescriptorCache.get(cacheKey);
357354
}
358355
}

spring-jms/src/main/java/org/springframework/jms/config/AbstractListenerContainerParser.java

Lines changed: 6 additions & 9 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.
@@ -263,16 +263,13 @@ else if ("".equals(destinationType) || DESTINATION_TYPE_QUEUE.equals(destination
263263

264264
boolean replyPubSubDomain = false;
265265
String replyDestinationType = containerEle.getAttribute(RESPONSE_DESTINATION_TYPE_ATTRIBUTE);
266-
if (DESTINATION_TYPE_TOPIC.equals(replyDestinationType)) {
267-
replyPubSubDomain = true;
268-
}
269-
else if (DESTINATION_TYPE_QUEUE.equals(replyDestinationType)) {
270-
replyPubSubDomain = false;
266+
if (!StringUtils.hasText(replyDestinationType)) {
267+
replyPubSubDomain = pubSubDomain; // the default: same value as pubSubDomain
271268
}
272-
else if (!StringUtils.hasText(replyDestinationType)) {
273-
replyPubSubDomain = pubSubDomain; // the default: same value as pubSubDomain
269+
else if (DESTINATION_TYPE_TOPIC.equals(replyDestinationType)) {
270+
replyPubSubDomain = true;
274271
}
275-
else if (StringUtils.hasText(replyDestinationType)) {
272+
else if (!DESTINATION_TYPE_QUEUE.equals(replyDestinationType)) {
276273
parserContext.getReaderContext().error("Invalid listener container 'response-destination-type': only " +
277274
"\"queue\", \"topic\" supported.", containerEle);
278275
}

spring-test/src/main/java/org/springframework/test/web/servlet/MockMvc.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 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.
@@ -90,6 +90,7 @@ public final class MockMvc {
9090
this.servletContext = servletContext;
9191
}
9292

93+
9394
/**
9495
* A default request builder merged into every performed request.
9596
* @see org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder#defaultRequest(RequestBuilder)
@@ -103,7 +104,7 @@ void setDefaultRequest(RequestBuilder requestBuilder) {
103104
* @see org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder#alwaysExpect(ResultMatcher)
104105
*/
105106
void setGlobalResultMatchers(List<ResultMatcher> resultMatchers) {
106-
Assert.notNull(resultMatchers, "resultMatchers is required");
107+
Assert.notNull(resultMatchers, "ResultMatcher List is required");
107108
this.defaultResultMatchers = resultMatchers;
108109
}
109110

@@ -112,20 +113,17 @@ void setGlobalResultMatchers(List<ResultMatcher> resultMatchers) {
112113
* @see org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder#alwaysDo(ResultHandler)
113114
*/
114115
void setGlobalResultHandlers(List<ResultHandler> resultHandlers) {
115-
Assert.notNull(resultHandlers, "resultHandlers is required");
116+
Assert.notNull(resultHandlers, "ResultHandler List is required");
116117
this.defaultResultHandlers = resultHandlers;
117118
}
118119

119120
/**
120121
* Perform a request and return a type that allows chaining further
121122
* actions, such as asserting expectations, on the result.
122-
*
123123
* @param requestBuilder used to prepare the request to execute;
124124
* see static factory methods in
125125
* {@link org.springframework.test.web.servlet.request.MockMvcRequestBuilders}
126-
*
127-
* @return an instance of {@link ResultActions}; never {@code null}
128-
*
126+
* @return an instance of {@link ResultActions} (never {@code null})
129127
* @see org.springframework.test.web.servlet.request.MockMvcRequestBuilders
130128
* @see org.springframework.test.web.servlet.result.MockMvcResultMatchers
131129
*/
@@ -153,29 +151,24 @@ public ResultActions perform(RequestBuilder requestBuilder) throws Exception {
153151
filterChain.doFilter(request, response);
154152

155153
if (DispatcherType.ASYNC.equals(request.getDispatcherType()) &&
156-
request.getAsyncContext() != null & !request.isAsyncStarted()) {
157-
154+
request.getAsyncContext() != null && !request.isAsyncStarted()) {
158155
request.getAsyncContext().complete();
159156
}
160157

161158
applyDefaultResultActions(mvcResult);
162-
163159
RequestContextHolder.setRequestAttributes(previousAttributes);
164160

165161
return new ResultActions() {
166-
167162
@Override
168163
public ResultActions andExpect(ResultMatcher matcher) throws Exception {
169164
matcher.match(mvcResult);
170165
return this;
171166
}
172-
173167
@Override
174168
public ResultActions andDo(ResultHandler handler) throws Exception {
175169
handler.handle(mvcResult);
176170
return this;
177171
}
178-
179172
@Override
180173
public MvcResult andReturn() {
181174
return mvcResult;
@@ -184,7 +177,6 @@ public MvcResult andReturn() {
184177
}
185178

186179
private void applyDefaultResultActions(MvcResult mvcResult) throws Exception {
187-
188180
for (ResultMatcher matcher : this.defaultResultMatchers) {
189181
matcher.match(mvcResult);
190182
}

0 commit comments

Comments
 (0)