File tree 3 files changed +42
-6
lines changed
spring-javaformat/spring-javaformat-checkstyle/src
main/java/io/spring/javaformat/checkstyle/check
3 files changed +42
-6
lines changed Original file line number Diff line number Diff line change 20
20
import com .puppycrawl .tools .checkstyle .api .TokenTypes ;
21
21
22
22
/**
23
- * Checks that lambda definitions follow Spring conventions. Single argument lambda
24
- * parameters should have parentheses. Single statement implementations should not use
25
- * curly braces.
23
+ * Checks that lambda definitions follow Spring conventions. Single argument
24
+ * lambda parameters should have parentheses. Single statement implementations
25
+ * should not use curly braces.
26
26
*
27
27
* @author Phillip Webb
28
28
*/
@@ -38,7 +38,8 @@ public int[] getAcceptableTokens() {
38
38
39
39
@ Override
40
40
public void visitToken (DetailAST ast ) {
41
- if (ast .getType () == TokenTypes .LAMBDA ) {
41
+ if (ast .getType () == TokenTypes .LAMBDA && ast .getParent () != null
42
+ && ast .getParent ().getType () != TokenTypes .SWITCH_RULE ) {
42
43
visitLambda (ast );
43
44
}
44
45
}
@@ -48,8 +49,7 @@ private void visitLambda(DetailAST lambda) {
48
49
boolean hasParentheses = hasToken (lambda , TokenTypes .LPAREN );
49
50
if (this .singleArgumentParentheses && !hasParentheses ) {
50
51
log (lambda .getLineNo (), lambda .getColumnNo (), "lambda.missingParen" );
51
- }
52
- else if (!this .singleArgumentParentheses && hasParentheses ) {
52
+ } else if (!this .singleArgumentParentheses && hasParentheses ) {
53
53
if (!isUsingParametersToDefineType (lambda )) {
54
54
log (lambda .getLineNo (), lambda .getColumnNo (), "lambda.unnecessaryParen" );
55
55
}
Original file line number Diff line number Diff line change
1
+ +0 errors
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2017-2019 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import java .util .function .Function ;
18
+
19
+ /**
20
+ * Lambda in a switch statement.
21
+ *
22
+ * @author Josef Reichardt
23
+ */
24
+ public class LambdaSwitch {
25
+
26
+ private void sayHello (String [] args ) {
27
+ Function <Integer , String > getText = (cnt ) -> "Number of args: " + cnt ;
28
+ String message = switch (args .length ) {
29
+ case 0 -> "No arg" ;
30
+ case 1 -> "One arg" ;
31
+ default -> getText .apply (args .length );
32
+ };
33
+ System .out .println (message );
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments