Skip to content

Commit bc3b3d0

Browse files
committed
Polishing
1 parent d9d45cc commit bc3b3d0

File tree

12 files changed

+68
-68
lines changed

12 files changed

+68
-68
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragments.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ private RegisteredBean getInnerRegisteredBean(Object value) {
138138
return null;
139139
}
140140

141+
@Override
141142
public CodeBlock generateSetBeanInstanceSupplierCode(
142143
GenerationContext generationContext,
143144
BeanRegistrationCode beanRegistrationCode, CodeBlock instanceSupplierCode,

spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public CodeBlock generateSetBeanDefinitionPropertiesCode(
196196
RootBeanDefinition beanDefinition,
197197
Predicate<String> attributeFilter) {
198198
return super.generateSetBeanDefinitionPropertiesCode(generationContext,
199-
beanRegistrationCode, beanDefinition, name -> "a".equals(name));
199+
beanRegistrationCode, beanDefinition, "a"::equals);
200200
}
201201

202202
};

spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ void attributesWhenAllFiltered() {
371371
void attributesWhenSomeFiltered() {
372372
this.beanDefinition.setAttribute("a", "A");
373373
this.beanDefinition.setAttribute("b", "B");
374-
Predicate<String> attributeFilter = attribute -> "a".equals(attribute);
374+
Predicate<String> attributeFilter = "a"::equals;
375375
this.generator = new BeanDefinitionPropertiesCodeGenerator(this.hints,
376376
attributeFilter, this.generatedMethods, (name, value) -> null);
377377
testCompiledResult(this.beanDefinition, (actual, compiled) -> {

spring-beans/src/test/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -38,7 +38,7 @@ public void testSingletons() {
3838
beanRegistry.registerSingleton("tb", tb);
3939
assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb);
4040

41-
TestBean tb2 = (TestBean) beanRegistry.getSingleton("tb2", () -> new TestBean());
41+
TestBean tb2 = (TestBean) beanRegistry.getSingleton("tb2", TestBean::new);
4242
assertThat(beanRegistry.getSingleton("tb2")).isSameAs(tb2);
4343

4444
assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb);

spring-context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -214,7 +214,7 @@ public void testResourceInjectionWithResolvableDependencyType() {
214214
bf.registerBeanDefinition("testBean4", tbd);
215215

216216
bf.registerResolvableDependency(BeanFactory.class, bf);
217-
bf.registerResolvableDependency(INestedTestBean.class, (ObjectFactory<Object>) () -> new NestedTestBean());
217+
bf.registerResolvableDependency(INestedTestBean.class, (ObjectFactory<Object>) NestedTestBean::new);
218218

219219
@SuppressWarnings("deprecation")
220220
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer();

spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ void createDefaultConversionService() {
5555
void createDefaultConversionServiceWithSupplements() {
5656
ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean();
5757
Set<Object> converters = new HashSet<>();
58+
// The following String -> Foo Converter cannot be implemented as a lambda
59+
// due to type erasure of the source and target types.
5860
converters.add(new Converter<String, Foo>() {
5961
@Override
6062
public Foo convert(String source) {

spring-core-test/src/main/java/org/springframework/aot/test/generator/file/DynamicFileAssert.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public A doesNotContain(CharSequence... values) {
4949
return this.myself;
5050
}
5151

52+
@Override
5253
public A isEqualTo(@Nullable Object expected) {
5354
if (expected instanceof DynamicFile) {
5455
return super.isEqualTo(expected);

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -153,11 +153,15 @@ static class Person {
153153
public String[] getRoles() { return new String[]{"NONE"}; }
154154

155155
public boolean hasAnyRole(String... roles) {
156-
if (roles == null) return true;
156+
if (roles == null) {
157+
return true;
158+
}
157159
String[] myRoles = getRoles();
158-
for (int i = 0; i < myRoles.length; i++) {
159-
for (int j = 0; j < roles.length; j++) {
160-
if (myRoles[i].equals(roles[j])) return true;
160+
for (String myRole : myRoles) {
161+
for (String role : roles) {
162+
if (myRole.equals(role)) {
163+
return true;
164+
}
161165
}
162166
}
163167
return false;

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ public void opNe_SPR14863() throws Exception {
17961796
((SpelExpression) expression).compileExpression();
17971797
assertThat(expression.getValue(context, Boolean.class)).isFalse();
17981798

1799-
List<String> ls = new ArrayList<String>();
1799+
List<String> ls = new ArrayList<>();
18001800
ls.add(new String("foo"));
18011801
context = new StandardEvaluationContext(ls);
18021802
expression = parse("get(0) != 'foo'");
@@ -1844,7 +1844,7 @@ public void opEq_SPR14863() throws Exception {
18441844
assertThat(aa.gotComparedTo).isEqualTo(bb);
18451845

18461846

1847-
List<String> ls = new ArrayList<String>();
1847+
List<String> ls = new ArrayList<>();
18481848
ls.add(new String("foo"));
18491849
StandardEvaluationContext context = new StandardEvaluationContext(ls);
18501850
expression = parse("get(0) == 'foo'");
@@ -5109,29 +5109,26 @@ private SpelNodeImpl getAst() {
51095109

51105110
private String stringify(Object object) {
51115111
StringBuilder s = new StringBuilder();
5112-
if (object instanceof List) {
5113-
List<?> ls = (List<?>) object;
5114-
for (Object l: ls) {
5112+
if (object instanceof List<?> list) {
5113+
for (Object l: list) {
51155114
s.append(l);
51165115
s.append(' ');
51175116
}
51185117
}
5119-
else if (object instanceof Object[]) {
5120-
Object[] os = (Object[]) object;
5121-
for (Object o: os) {
5118+
else if (object instanceof Object[] objects) {
5119+
for (Object o: objects) {
51225120
s.append(o);
51235121
s.append(' ');
51245122
}
51255123
}
5126-
else if (object instanceof int[]) {
5127-
int[] is = (int[]) object;
5128-
for (int i: is) {
5124+
else if (object instanceof int[] ints) {
5125+
for (int i: ints) {
51295126
s.append(i);
51305127
s.append(' ');
51315128
}
51325129
}
51335130
else {
5134-
s.append(object.toString());
5131+
s.append(object);
51355132
}
51365133
return s.toString().trim();
51375134
}

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,20 +1321,14 @@ void SPR9495() {
13211321
assertThat(Array.get(result, 1)).isEqualTo(ABC.B);
13221322
assertThat(Array.get(result, 2)).isEqualTo(ABC.C);
13231323

1324-
context.addMethodResolver(new MethodResolver() {
1325-
@Override
1326-
public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name,
1327-
List<TypeDescriptor> argumentTypes) throws AccessException {
1328-
return (context1, target, arguments) -> {
1329-
try {
1330-
Method method = XYZ.class.getMethod("values");
1331-
Object value = method.invoke(target, arguments);
1332-
return new TypedValue(value, new TypeDescriptor(new MethodParameter(method, -1)).narrow(value));
1333-
}
1334-
catch (Exception ex) {
1335-
throw new AccessException(ex.getMessage(), ex);
1336-
}
1337-
};
1324+
context.addMethodResolver((context2, targetObject, name, argumentTypes) -> (context1, target, arguments) -> {
1325+
try {
1326+
Method method = XYZ.class.getMethod("values");
1327+
Object value = method.invoke(target, arguments);
1328+
return new TypedValue(value, new TypeDescriptor(new MethodParameter(method, -1)).narrow(value));
1329+
}
1330+
catch (Exception ex) {
1331+
throw new AccessException(ex.getMessage(), ex);
13381332
}
13391333
});
13401334

spring-expression/src/test/java/org/springframework/expression/spel/testresources/PlaceOfBirth.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -18,6 +18,7 @@
1818

1919
///CLOVER:OFF
2020
public class PlaceOfBirth {
21+
2122
private String city;
2223

2324
public String Country;
@@ -29,11 +30,14 @@ public class PlaceOfBirth {
2930
* country - but as it is just a test object, it is ok.
3031
*/
3132
@Override
32-
public String toString() {return city;}
33+
public String toString() {
34+
return city;
35+
}
3336

3437
public String getCity() {
3538
return city;
3639
}
40+
3741
public void setCity(String s) {
3842
this.city = s;
3943
}
@@ -48,11 +52,10 @@ public int doubleIt(int i) {
4852

4953
@Override
5054
public boolean equals(Object o) {
51-
if (!(o instanceof PlaceOfBirth)) {
55+
if (!(o instanceof PlaceOfBirth otherPOB)) {
5256
return false;
5357
}
54-
PlaceOfBirth oPOB = (PlaceOfBirth)o;
55-
return (city.equals(oPOB.city));
58+
return (city.equals(otherPOB.city));
5659
}
5760

5861
@Override

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -209,32 +209,30 @@ protected Mono<Void> doBegin(TransactionSynchronizationManager synchronizationMa
209209
connectionMono = Mono.just(txObject.getConnectionHolder().getConnection());
210210
}
211211

212-
return connectionMono.flatMap(con -> {
213-
return prepareTransactionalConnection(con, definition, transaction)
214-
.then(Mono.from(doBegin(definition, con)))
215-
.doOnSuccess(v -> {
216-
txObject.getConnectionHolder().setTransactionActive(true);
217-
Duration timeout = determineTimeout(definition);
218-
if (!timeout.isNegative() && !timeout.isZero()) {
219-
txObject.getConnectionHolder().setTimeoutInMillis(timeout.toMillis());
220-
}
221-
// Bind the connection holder to the thread.
222-
if (txObject.isNewConnectionHolder()) {
223-
synchronizationManager.bindResource(obtainConnectionFactory(), txObject.getConnectionHolder());
224-
}
225-
}).thenReturn(con).onErrorResume(e -> {
226-
if (txObject.isNewConnectionHolder()) {
227-
return ConnectionFactoryUtils.releaseConnection(con, obtainConnectionFactory())
228-
.doOnTerminate(() -> txObject.setConnectionHolder(null, false))
229-
.then(Mono.error(e));
230-
}
231-
return Mono.error(e);
232-
});
233-
}).onErrorResume(e -> {
234-
CannotCreateTransactionException ex = new CannotCreateTransactionException(
235-
"Could not open R2DBC Connection for transaction", e);
236-
return Mono.error(ex);
237-
});
212+
return connectionMono.flatMap(con -> prepareTransactionalConnection(con, definition, transaction)
213+
.then(Mono.from(doBegin(definition, con)))
214+
.doOnSuccess(v -> {
215+
txObject.getConnectionHolder().setTransactionActive(true);
216+
Duration timeout = determineTimeout(definition);
217+
if (!timeout.isNegative() && !timeout.isZero()) {
218+
txObject.getConnectionHolder().setTimeoutInMillis(timeout.toMillis());
219+
}
220+
// Bind the connection holder to the thread.
221+
if (txObject.isNewConnectionHolder()) {
222+
synchronizationManager.bindResource(obtainConnectionFactory(), txObject.getConnectionHolder());
223+
}
224+
}).thenReturn(con).onErrorResume(e -> {
225+
if (txObject.isNewConnectionHolder()) {
226+
return ConnectionFactoryUtils.releaseConnection(con, obtainConnectionFactory())
227+
.doOnTerminate(() -> txObject.setConnectionHolder(null, false))
228+
.then(Mono.error(e));
229+
}
230+
return Mono.error(e);
231+
})).onErrorResume(e -> {
232+
CannotCreateTransactionException ex = new CannotCreateTransactionException(
233+
"Could not open R2DBC Connection for transaction", e);
234+
return Mono.error(ex);
235+
});
238236
}).then();
239237
}
240238

0 commit comments

Comments
 (0)