Skip to content

Commit 5378572

Browse files
committed
Clarify lambda code block methods
1 parent f64fc4b commit 5378572

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationContributionProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public CodeContribution generateBeanInstantiation(RuntimeHints runtimeHints) {
9292
statements.addStatement("factory.setTargetBeanName($S)", targetBeanName);
9393
statements.addStatement("factory.setBeanFactory(beanFactory)");
9494
statements.addStatement("return factory.getObject()");
95-
codeContribution.statements().add(statements.toLambdaBody("() ->"));
95+
codeContribution.statements().add(statements.toLambda("() ->"));
9696
return codeContribution;
9797
}
9898
};

spring-beans/src/main/java/org/springframework/beans/factory/generator/BeanRegistrationBeanFactoryContribution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ private void handleBeanDefinitionMetadata(Builder code) {
421421
if (statements.isEmpty()) {
422422
return;
423423
}
424-
code.add(statements.toLambdaBody(".customize((" + bdVariable + ") ->"));
424+
code.add(statements.toLambda(".customize((" + bdVariable + ") ->"));
425425
code.add(")");
426426
}
427427

spring-beans/src/main/java/org/springframework/beans/factory/generator/InjectionGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ CodeBlock generateFieldInjection(Field injectionPoint, boolean required) {
234234
code.add(".resolve(beanFactory, false).ifResolved(");
235235
}
236236
code.add(this.fieldGenerator.generateSetValue("bean", injectionPoint,
237-
CodeBlock.of("attributes.get(0)")).toLambdaBody("(attributes) ->"));
237+
CodeBlock.of("attributes.get(0)")).toLambda("(attributes) ->"));
238238
code.add(")").unindent().unindent();
239239
return code.build();
240240
}

spring-core/src/main/java/org/springframework/javapoet/support/MultiStatement.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public CodeBlock toCodeBlock() {
141141
* Return a {@link CodeBlock} that applies all the {@code statements} of this
142142
* instance. If only one statement is available, it is not completed using the
143143
* {@code ;} termination so that it can be used in the context of a lambda.
144-
* @return the statement(s)
144+
* @return the body of the lambda
145145
*/
146146
public CodeBlock toLambdaBody() {
147147
Builder code = CodeBlock.builder();
@@ -155,12 +155,12 @@ public CodeBlock toLambdaBody() {
155155
/**
156156
* Return a {@link CodeBlock} that applies all the {@code statements} of this
157157
* instance in the context of a lambda.
158-
* @param lambda the context of the lambda, must end with {@code ->}
159-
* @return the lambda body
158+
* @param lambdaParameter the parameter(s) of the lambda, must end with {@code ->}
159+
* @return a lambda whose body is generated from the statements of this instance
160160
*/
161-
public CodeBlock toLambdaBody(CodeBlock lambda) {
161+
public CodeBlock toLambda(CodeBlock lambdaParameter) {
162162
Builder code = CodeBlock.builder();
163-
code.add(lambda);
163+
code.add(lambdaParameter);
164164
if (isMulti()) {
165165
code.beginControlFlow("");
166166
}
@@ -177,11 +177,11 @@ public CodeBlock toLambdaBody(CodeBlock lambda) {
177177
/**
178178
* Return a {@link CodeBlock} that applies all the {@code statements} of this
179179
* instance in the context of a lambda.
180-
* @param lambda the context of the lambda, must end with {@code ->}
181-
* @return the lambda body
180+
* @param lambdaParameter the parameter(s) of the lambda, must end with {@code ->}
181+
* @return a lambda whose body is generated from the statements of this instance
182182
*/
183-
public CodeBlock toLambdaBody(String lambda) {
184-
return toLambdaBody(CodeBlock.of(lambda));
183+
public CodeBlock toLambda(String lambdaParameter) {
184+
return toLambda(CodeBlock.of(lambdaParameter));
185185
}
186186

187187
private boolean isMulti() {

spring-core/src/test/java/org/springframework/javapoet/support/MultiStatementTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void multiStatementsWithCodeBlockRenderedAsIsLambdaBody() {
119119
void singleStatementWithLambda() {
120120
MultiStatement statements = new MultiStatement();
121121
statements.addStatement("field.method($S)", "hello");
122-
CodeBlock codeBlock = statements.toLambdaBody(CodeBlock.of("() ->"));
122+
CodeBlock codeBlock = statements.toLambda(CodeBlock.of("() ->"));
123123
assertThat(codeBlock.toString()).isEqualTo("() -> field.method(\"hello\")");
124124
}
125125

@@ -128,7 +128,7 @@ void multiStatementsWithLambda() {
128128
MultiStatement statements = new MultiStatement();
129129
statements.addStatement("field.method($S)", "hello");
130130
statements.addStatement("field.anotherMethod($S)", "hello");
131-
CodeBlock codeBlock = statements.toLambdaBody(CodeBlock.of("() ->"));
131+
CodeBlock codeBlock = statements.toLambda(CodeBlock.of("() ->"));
132132
assertThat(codeBlock.toString().lines()).containsExactly(
133133
"() -> {",
134134
" field.method(\"hello\");",
@@ -141,7 +141,7 @@ void multiStatementsWithAddAllAndLambda() {
141141
MultiStatement statements = new MultiStatement();
142142
statements.addAll(List.of(0, 1, 2),
143143
index -> CodeBlock.of("field[$L] = $S", index, "hello"));
144-
CodeBlock codeBlock = statements.toLambdaBody("() ->");
144+
CodeBlock codeBlock = statements.toLambda("() ->");
145145
assertThat(codeBlock.toString().lines()).containsExactly(
146146
"() -> {",
147147
" field[0] = \"hello\";",

0 commit comments

Comments
 (0)