Skip to content

Commit 9cc03fa

Browse files
committed
Polishing
1 parent 59189e5 commit 9cc03fa

File tree

52 files changed

+511
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+511
-560
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java

Lines changed: 3 additions & 4 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.
@@ -25,7 +25,6 @@
2525
import java.util.LinkedHashMap;
2626
import java.util.List;
2727
import java.util.Map;
28-
import java.util.Map.Entry;
2928
import java.util.Properties;
3029
import java.util.Set;
3130

@@ -201,7 +200,7 @@ private Map<String, Object> asMap(Object object) {
201200
}
202201

203202
Map<Object, Object> map = (Map<Object, Object>) object;
204-
for (Entry<Object, Object> entry : map.entrySet()) {
203+
for (Map.Entry<Object, Object> entry : map.entrySet()) {
205204
Object value = entry.getValue();
206205
if (value instanceof Map) {
207206
value = asMap(value);
@@ -273,7 +272,7 @@ protected final Map<String, Object> getFlattenedMap(Map<String, Object> source)
273272
}
274273

275274
private void buildFlattenedMap(Map<String, Object> result, Map<String, Object> source, String path) {
276-
for (Entry<String, Object> entry : source.entrySet()) {
275+
for (Map.Entry<String, Object> entry : source.entrySet()) {
277276
String key = entry.getKey();
278277
if (StringUtils.hasText(path)) {
279278
if (key.startsWith("[")) {

spring-context/src/main/java/org/springframework/context/expression/BeanFactoryResolver.java

Lines changed: 7 additions & 1 deletion
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-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.
@@ -34,11 +34,17 @@ public class BeanFactoryResolver implements BeanResolver {
3434

3535
private final BeanFactory beanFactory;
3636

37+
38+
/**
39+
* Create a new {@link BeanFactoryResolver} for the given factory.
40+
* @param beanFactory the {@link BeanFactory} to resolve bean names against
41+
*/
3742
public BeanFactoryResolver(BeanFactory beanFactory) {
3843
Assert.notNull(beanFactory, "BeanFactory must not be null");
3944
this.beanFactory = beanFactory;
4045
}
4146

47+
4248
@Override
4349
public Object resolve(EvaluationContext context, String beanName) throws AccessException {
4450
try {

spring-context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java

Lines changed: 2 additions & 3 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.
@@ -143,8 +143,7 @@ public Object evaluate(String value, BeanExpressionContext evalContext) throws B
143143
}
144144
StandardEvaluationContext sec = this.evaluationCache.get(evalContext);
145145
if (sec == null) {
146-
sec = new StandardEvaluationContext();
147-
sec.setRootObject(evalContext);
146+
sec = new StandardEvaluationContext(evalContext);
148147
sec.addPropertyAccessor(new BeanExpressionContextAccessor());
149148
sec.addPropertyAccessor(new BeanFactoryAccessor());
150149
sec.addPropertyAccessor(new MapAccessor());

spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.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.
@@ -69,7 +69,7 @@ public abstract class SpringFactoriesLoader {
6969
/**
7070
* Load and instantiate the factory implementations of the given type from
7171
* {@value #FACTORIES_RESOURCE_LOCATION}, using the given class loader.
72-
* <p>The returned factories are sorted in accordance with the {@link AnnotationAwareOrderComparator}.
72+
* <p>The returned factories are sorted through {@link AnnotationAwareOrderComparator}.
7373
* <p>If a custom instantiation strategy is required, use {@link #loadFactoryNames}
7474
* to obtain all registered factory names.
7575
* @param factoryClass the interface or abstract class representing the factory

spring-expression/src/main/java/org/springframework/expression/BeanResolver.java

Lines changed: 8 additions & 9 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.
@@ -17,23 +17,22 @@
1717
package org.springframework.expression;
1818

1919
/**
20-
* A bean resolver can be registered with the evaluation context
21-
* and will kick in for {@code @myBeanName} and {@code &myBeanName} expressions.
22-
* The <tt>&</tt> variant syntax allows access to the factory bean where
23-
* relevant.
20+
* A bean resolver can be registered with the evaluation context and will kick in
21+
* for bean references: {@code @myBeanName} and {@code &myBeanName} expressions.
22+
* The <tt>&</tt> variant syntax allows access to the factory bean where relevant.
2423
*
2524
* @author Andy Clement
2625
* @since 3.0.3
2726
*/
2827
public interface BeanResolver {
2928

3029
/**
31-
* Look up the named bean and return it. If attempting to access a factory
32-
* bean the name will have a <tt>&</tt> prefix.
30+
* Look up a bean by the given name and return a corresponding instance for it.
31+
* For attempting access to a factory bean, the name needs a <tt>&</tt> prefix.
3332
* @param context the current evaluation context
34-
* @param beanName the name of the bean to lookup
33+
* @param beanName the name of the bean to look up
3534
* @return an object representing the bean
36-
* @throws AccessException if there is an unexpected problem resolving the named bean
35+
* @throws AccessException if there is an unexpected problem resolving the bean
3736
*/
3837
Object resolve(EvaluationContext context, String beanName) throws AccessException;
3938

spring-expression/src/test/java/org/springframework/expression/spel/AbstractExpressionTests.java

Lines changed: 13 additions & 13 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.
@@ -44,7 +44,7 @@ public abstract class AbstractExpressionTests {
4444

4545
protected final ExpressionParser parser = new SpelExpressionParser();
4646

47-
protected final StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
47+
protected final StandardEvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
4848

4949

5050
/**
@@ -63,14 +63,14 @@ public void evaluate(String expression, Object expectedValue, Class<?> expectedR
6363
SpelUtilities.printAbstractSyntaxTree(System.out, expr);
6464
}
6565

66-
Object value = expr.getValue(eContext);
66+
Object value = expr.getValue(context);
6767

6868
// Check the return value
6969
if (value == null) {
7070
if (expectedValue == null) {
7171
return; // no point doing other checks
7272
}
73-
assertEquals("Expression returned null value, but expected '" + expectedValue + "'", expectedValue, null);
73+
assertNull("Expression returned null value, but expected '" + expectedValue + "'", expectedValue);
7474
}
7575

7676
Class<?> resultType = value.getClass();
@@ -95,12 +95,12 @@ public void evaluateAndAskForReturnType(String expression, Object expectedValue,
9595
SpelUtilities.printAbstractSyntaxTree(System.out, expr);
9696
}
9797

98-
Object value = expr.getValue(eContext, expectedResultType);
98+
Object value = expr.getValue(context, expectedResultType);
9999
if (value == null) {
100100
if (expectedValue == null) {
101101
return; // no point doing other checks
102102
}
103-
assertEquals("Expression returned null value, but expected '" + expectedValue + "'", expectedValue, null);
103+
assertNull("Expression returned null value, but expected '" + expectedValue + "'", expectedValue);
104104
}
105105

106106
Class<?> resultType = value.getClass();
@@ -127,12 +127,12 @@ public void evaluate(String expression, Object expectedValue, Class<?> expectedC
127127
if (DEBUG) {
128128
SpelUtilities.printAbstractSyntaxTree(System.out, expr);
129129
}
130-
Object value = expr.getValue(eContext);
130+
Object value = expr.getValue(context);
131131
if (value == null) {
132132
if (expectedValue == null) {
133133
return; // no point doing other checks
134134
}
135-
assertEquals("Expression returned null value, but expected '" + expectedValue + "'", expectedValue, null);
135+
assertNull("Expression returned null value, but expected '" + expectedValue + "'", expectedValue);
136136
}
137137
Class<? extends Object> resultType = value.getClass();
138138
if (expectedValue instanceof String) {
@@ -142,10 +142,10 @@ public void evaluate(String expression, Object expectedValue, Class<?> expectedC
142142
else {
143143
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
144144
}
145-
assertEquals("Type of the result was not as expected. Expected '" + expectedClassOfResult +
146-
"' but result was of type '" + resultType + "'", expectedClassOfResult.equals(resultType), true);
145+
assertTrue("Type of the result was not as expected. Expected '" + expectedClassOfResult +
146+
"' but result was of type '" + resultType + "'", expectedClassOfResult.equals(resultType));
147147

148-
boolean isWritable = expr.isWritable(eContext);
148+
boolean isWritable = expr.isWritable(context);
149149
if (isWritable != shouldBeWritable) {
150150
if (shouldBeWritable)
151151
fail("Expected the expression to be writable but it is not");
@@ -184,10 +184,10 @@ protected void evaluateAndCheckError(String expression, Class<?> expectedReturnT
184184
fail("Parser returned null for expression");
185185
}
186186
if (expectedReturnType != null) {
187-
expr.getValue(eContext, expectedReturnType);
187+
expr.getValue(context, expectedReturnType);
188188
}
189189
else {
190-
expr.getValue(eContext);
190+
expr.getValue(context);
191191
}
192192
fail("Should have failed with message " + expectedMessage);
193193
}

spring-expression/src/test/java/org/springframework/expression/spel/BooleanExpressionTests.java

Lines changed: 3 additions & 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-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.
@@ -104,11 +104,12 @@ protected Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor tar
104104
return targetType.getType() == Boolean.class ? false : null;
105105
}
106106
};
107-
eContext.setTypeConverter(new StandardTypeConverter(conversionService));
107+
context.setTypeConverter(new StandardTypeConverter(conversionService));
108108

109109
evaluate("null or true", Boolean.TRUE, Boolean.class, false);
110110
evaluate("null and true", Boolean.FALSE, Boolean.class, false);
111111
evaluate("!null", Boolean.TRUE, Boolean.class, false);
112112
evaluate("null ? 'foo' : 'bar'", "bar", String.class, false);
113113
}
114+
114115
}

spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public void testTernaryOperator03() {
359359
@Test
360360
public void testTernaryOperator04() {
361361
Expression e = parser.parseExpression("1>2?3:4");
362-
assertFalse(e.isWritable(eContext));
362+
assertFalse(e.isWritable(context));
363363
}
364364

365365
@Test

spring-expression/src/test/java/org/springframework/expression/spel/MethodInvocationTests.java

Lines changed: 9 additions & 9 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.
@@ -98,7 +98,7 @@ public void testMethodThrowingException_SPR6760() {
9898
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
9999
eContext.setVariable("bar", 3);
100100
Object o = expr.getValue(eContext);
101-
assertEquals(o, 3);
101+
assertEquals(3, o);
102102
assertEquals(1, parser.parseExpression("counter").getValue(eContext));
103103

104104
// Now the expression has cached that throwException(int) is the right thing to call
@@ -163,9 +163,9 @@ public void testMethodThrowingException_SPR6941() {
163163
SpelExpressionParser parser = new SpelExpressionParser();
164164
Expression expr = parser.parseExpression("throwException(#bar)");
165165

166-
eContext.setVariable("bar", 2);
166+
context.setVariable("bar", 2);
167167
try {
168-
expr.getValue(eContext);
168+
expr.getValue(context);
169169
fail();
170170
}
171171
catch (Exception ex) {
@@ -187,9 +187,9 @@ public void testMethodThrowingException_SPR6941_2() {
187187
SpelExpressionParser parser = new SpelExpressionParser();
188188
Expression expr = parser.parseExpression("throwException(#bar)");
189189

190-
eContext.setVariable("bar", 4);
190+
context.setVariable("bar", 4);
191191
try {
192-
expr.getValue(eContext);
192+
expr.getValue(context);
193193
fail();
194194
}
195195
catch (ExpressionInvocationTargetException ex) {
@@ -251,7 +251,7 @@ public void testAddingMethodResolvers() {
251251
ctx.addMethodResolver(dummy);
252252
assertEquals(2, ctx.getMethodResolvers().size());
253253

254-
List<MethodResolver> copy = new ArrayList<MethodResolver>();
254+
List<MethodResolver> copy = new ArrayList<>();
255255
copy.addAll(ctx.getMethodResolvers());
256256
assertTrue(ctx.removeMethodResolver(dummy));
257257
assertFalse(ctx.removeMethodResolver(dummy));
@@ -294,7 +294,7 @@ public void testInvocationOnNullContextObject() {
294294
public void testMethodOfClass() throws Exception {
295295
Expression expression = parser.parseExpression("getName()");
296296
Object value = expression.getValue(new StandardEvaluationContext(String.class));
297-
assertEquals(value, "java.lang.String");
297+
assertEquals("java.lang.String", value);
298298
}
299299

300300
@Test
@@ -341,7 +341,7 @@ private boolean isAnnotated(Method method) {
341341
@Override
342342
public List<Method> filter(List<Method> methods) {
343343
filterCalled = true;
344-
List<Method> forRemoval = new ArrayList<Method>();
344+
List<Method> forRemoval = new ArrayList<>();
345345
for (Method method: methods) {
346346
if (removeIfNotAnnotated && !isAnnotated(method)) {
347347
forRemoval.add(method);

0 commit comments

Comments
 (0)