Skip to content

Commit 0b76b13

Browse files
committed
Polishing
(cherry picked from commit 5fee5f3)
1 parent 23e91e1 commit 0b76b13

File tree

22 files changed

+220
-217
lines changed

22 files changed

+220
-217
lines changed

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

Lines changed: 18 additions & 17 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-2016 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.
@@ -30,8 +30,8 @@
3030
* Helper class for calculating property matches, according to a configurable
3131
* distance. Provide the list of potential matches and an easy way to generate
3232
* an error message. Works for both java bean properties and fields.
33-
* <p>
34-
* Mainly for use within the framework and in particular the binding facility
33+
*
34+
* <p>Mainly for use within the framework and in particular the binding facility.
3535
*
3636
* @author Alef Arendsen
3737
* @author Arjen Poutsma
@@ -43,14 +43,12 @@
4343
*/
4444
public abstract class PropertyMatches {
4545

46-
//---------------------------------------------------------------------
47-
// Static section
48-
//---------------------------------------------------------------------
49-
5046
/** Default maximum property distance: 2 */
5147
public static final int DEFAULT_MAX_DISTANCE = 2;
5248

5349

50+
// Static factory methods
51+
5452
/**
5553
* Create PropertyMatches for the given bean property.
5654
* @param propertyName the name of the property to find possible matches for
@@ -90,9 +88,7 @@ public static PropertyMatches forField(String propertyName, Class<?> beanClass,
9088
}
9189

9290

93-
//---------------------------------------------------------------------
94-
// Instance section
95-
//---------------------------------------------------------------------
91+
// Instance state
9692

9793
private final String propertyName;
9894

@@ -107,18 +103,19 @@ private PropertyMatches(String propertyName, String[] possibleMatches) {
107103
this.possibleMatches = possibleMatches;
108104
}
109105

106+
110107
/**
111108
* Return the name of the requested property.
112109
*/
113110
public String getPropertyName() {
114-
return propertyName;
111+
return this.propertyName;
115112
}
116113

117114
/**
118115
* Return the calculated possible matches.
119116
*/
120117
public String[] getPossibleMatches() {
121-
return possibleMatches;
118+
return this.possibleMatches;
122119
}
123120

124121
/**
@@ -127,6 +124,9 @@ public String[] getPossibleMatches() {
127124
*/
128125
public abstract String buildErrorMessage();
129126

127+
128+
// Implementation support for subclasses
129+
130130
protected void appendHintMessage(StringBuilder msg) {
131131
msg.append("Did you mean ");
132132
for (int i = 0; i < this.possibleMatches.length; i++) {
@@ -184,9 +184,12 @@ private static int calculateStringDistance(String s1, String s2) {
184184
return d[s1.length()][s2.length()];
185185
}
186186

187+
188+
// Concrete subclasses
189+
187190
private static class BeanPropertyMatches extends PropertyMatches {
188191

189-
private BeanPropertyMatches(String propertyName, Class<?> beanClass, int maxDistance) {
192+
public BeanPropertyMatches(String propertyName, Class<?> beanClass, int maxDistance) {
190193
super(propertyName, calculateMatches(propertyName,
191194
BeanUtils.getPropertyDescriptors(beanClass), maxDistance));
192195
}
@@ -231,12 +234,12 @@ public String buildErrorMessage() {
231234
}
232235
return msg.toString();
233236
}
234-
235237
}
236238

239+
237240
private static class FieldPropertyMatches extends PropertyMatches {
238241

239-
private FieldPropertyMatches(String propertyName, Class<?> beanClass, int maxDistance) {
242+
public FieldPropertyMatches(String propertyName, Class<?> beanClass, int maxDistance) {
240243
super(propertyName, calculateMatches(propertyName, beanClass, maxDistance));
241244
}
242245

@@ -255,7 +258,6 @@ public void doWith(Field field) throws IllegalArgumentException, IllegalAccessEx
255258
return StringUtils.toStringArray(candidates);
256259
}
257260

258-
259261
@Override
260262
public String buildErrorMessage() {
261263
String propertyName = getPropertyName();
@@ -270,7 +272,6 @@ public String buildErrorMessage() {
270272
}
271273
return msg.toString();
272274
}
273-
274275
}
275276

276277
}

spring-context/src/main/java/org/springframework/context/support/ConversionServiceFactoryBean.java

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

2828
/**
2929
* A factory providing convenient access to a ConversionService configured with
30-
* converters appropriate for most environments. Set the {@link #setConverters
31-
* "converters"} property to supplement the default converters.
30+
* converters appropriate for most environments. Set the
31+
* {@link #setConverters "converters"} property to supplement the default converters.
3232
*
33-
* <p>This implementation creates a {@link DefaultConversionService}. Subclasses
34-
* may override {@link #createConversionService()} in order to return a
35-
* {@link GenericConversionService} instance of their choosing.
33+
* <p>This implementation creates a {@link DefaultConversionService}.
34+
* Subclasses may override {@link #createConversionService()} in order to return
35+
* a {@link GenericConversionService} instance of their choosing.
3636
*
3737
* <p>Like all {@code FactoryBean} implementations, this class is suitable for
3838
* use when configuring a Spring application context using Spring {@code <beans>}

spring-context/src/main/java/org/springframework/jmx/support/ConnectorServerFactoryBean.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -49,7 +49,6 @@
4949
* @author Rob Harrop
5050
* @author Juergen Hoeller
5151
* @since 1.2
52-
* @see FactoryBean
5352
* @see JMXConnectorServer
5453
* @see MBeanServer
5554
*/

spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java

Lines changed: 4 additions & 4 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-2016 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.
@@ -206,8 +206,8 @@ public void setBeanClassLoader(ClassLoader classLoader) {
206206
@Override
207207
public void setBeanFactory(BeanFactory beanFactory) {
208208
if (!(beanFactory instanceof ConfigurableBeanFactory)) {
209-
throw new IllegalStateException("ScriptFactoryPostProcessor doesn't work with a BeanFactory "
210-
+ "which does not implement ConfigurableBeanFactory: " + beanFactory.getClass());
209+
throw new IllegalStateException("ScriptFactoryPostProcessor doesn't work with " +
210+
"non-ConfigurableBeanFactory: " + beanFactory.getClass());
211211
}
212212
this.beanFactory = (ConfigurableBeanFactory) beanFactory;
213213

@@ -381,7 +381,7 @@ protected void prepareScriptBeans(BeanDefinition bd, String scriptFactoryBeanNam
381381
* If the {@link BeanDefinition} has a
382382
* {@link org.springframework.core.AttributeAccessor metadata attribute}
383383
* under the key {@link #REFRESH_CHECK_DELAY_ATTRIBUTE} which is a valid {@link Number}
384-
* type, then this value is used. Otherwise, the the {@link #defaultRefreshCheckDelay}
384+
* type, then this value is used. Otherwise, the {@link #defaultRefreshCheckDelay}
385385
* value is used.
386386
* @param beanDefinition the BeanDefinition to check
387387
* @return the refresh check delay

spring-context/src/test/java/org/springframework/cache/config/ExpressionCachingIntegrationTests.java

Lines changed: 21 additions & 9 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-2016 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.
@@ -29,13 +29,12 @@
2929
import org.springframework.context.annotation.Configuration;
3030

3131
/**
32-
*
3332
* @author Stephane Nicoll
3433
*/
3534
public class ExpressionCachingIntegrationTests {
3635

36+
@Test // SPR-11692
3737
@SuppressWarnings("unchecked")
38-
@Test // SPR-11692
3938
public void expressionIsCacheBasedOnActualMethod() {
4039
ConfigurableApplicationContext context =
4140
new AnnotationConfigApplicationContext(SharedConfig.class, Spr11692Config.class);
@@ -50,9 +49,9 @@ public void expressionIsCacheBasedOnActualMethod() {
5049
}
5150

5251

53-
5452
@Configuration
5553
static class Spr11692Config {
54+
5655
@Bean
5756
public BaseDao<User> userDao() {
5857
return new UserDaoImpl();
@@ -65,53 +64,66 @@ public BaseDao<Order> orderDao() {
6564
}
6665

6766

68-
private static interface BaseDao<T> {
67+
private interface BaseDao<T> {
68+
6969
T persist(T t);
7070
}
7171

72+
7273
private static class UserDaoImpl implements BaseDao<User> {
74+
7375
@Override
7476
@CachePut(value = "users", key = "#user.id")
7577
public User persist(User user) {
7678
return user;
7779
}
7880
}
7981

82+
8083
private static class OrderDaoImpl implements BaseDao<Order> {
84+
8185
@Override
8286
@CachePut(value = "orders", key = "#order.id")
8387
public Order persist(Order order) {
8488
return order;
8589
}
8690
}
8791

92+
8893
private static class User {
94+
8995
private final String id;
9096

91-
private User(String id) {
97+
public User(String id) {
9298
this.id = id;
9399
}
94100

101+
@SuppressWarnings("unused")
95102
public String getId() {
96-
return id;
103+
return this.id;
97104
}
98105
}
99106

107+
100108
private static class Order {
109+
101110
private final String id;
102111

103-
private Order(String id) {
112+
public Order(String id) {
104113
this.id = id;
105114
}
106115

116+
@SuppressWarnings("unused")
107117
public String getId() {
108-
return id;
118+
return this.id;
109119
}
110120
}
111121

122+
112123
@Configuration
113124
@EnableCaching
114125
static class SharedConfig extends CachingConfigurerSupport {
126+
115127
@Override
116128
@Bean
117129
public CacheManager cacheManager() {

spring-core/src/main/java/org/springframework/core/convert/Property.java

Lines changed: 2 additions & 2 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-2016 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.
@@ -72,7 +72,7 @@ public Property(Class<?> objectType, Method readMethod, Method writeMethod, Stri
7272
this.readMethod = readMethod;
7373
this.writeMethod = writeMethod;
7474
this.methodParameter = resolveMethodParameter();
75-
this.name = (name == null ? resolveName() : name);
75+
this.name = (name != null ? name : resolveName());
7676
}
7777

7878

spring-core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ abstract class ConversionUtils {
3131

3232
public static Object invokeConverter(GenericConverter converter, Object source, TypeDescriptor sourceType,
3333
TypeDescriptor targetType) {
34+
3435
try {
3536
return converter.convert(source, sourceType, targetType);
3637
}
@@ -42,7 +43,9 @@ public static Object invokeConverter(GenericConverter converter, Object source,
4243
}
4344
}
4445

45-
public static boolean canConvertElements(TypeDescriptor sourceElementType, TypeDescriptor targetElementType, ConversionService conversionService) {
46+
public static boolean canConvertElements(TypeDescriptor sourceElementType, TypeDescriptor targetElementType,
47+
ConversionService conversionService) {
48+
4649
if (targetElementType == null) {
4750
// yes
4851
return true;
@@ -56,11 +59,11 @@ public static boolean canConvertElements(TypeDescriptor sourceElementType, TypeD
5659
return true;
5760
}
5861
else if (sourceElementType.getType().isAssignableFrom(targetElementType.getType())) {
59-
// maybe;
62+
// maybe
6063
return true;
6164
}
6265
else {
63-
// no;
66+
// no
6467
return false;
6568
}
6669
}

spring-core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java

Lines changed: 1 addition & 2 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-2016 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.
@@ -53,7 +53,6 @@ public class DefaultConversionService extends GenericConversionService {
5353
"java.util.stream.Stream", DefaultConversionService.class.getClassLoader());
5454

5555

56-
5756
/**
5857
* Create a new {@code DefaultConversionService} with the set of
5958
* {@linkplain DefaultConversionService#addDefaultConverters(ConverterRegistry) default converters}.

spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public class GenericConversionService implements ConfigurableConversionService {
6666
private static final GenericConverter NO_OP_CONVERTER = new NoOpConverter("NO_OP");
6767

6868
/**
69-
* Used as a cache entry when no converter is available. This converter is never
70-
* returned.
69+
* Used as a cache entry when no converter is available.
70+
* This converter is never returned.
7171
*/
7272
private static final GenericConverter NO_MATCH = new NoOpConverter("NO_MATCH");
7373

0 commit comments

Comments
 (0)