1   package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;
2   
3   import java.util.function.Consumer;
4   public class InputRequireThisAllowLambdaParameters {
5       private String s1 = "foo1";
6       int x=-1;
7       int y=-2;
8   
9       void foo1() {
10          final java.util.List<String> strings = new java.util.ArrayList<>();
11          strings.add("foo1");
12          strings.stream().filter(s1 -> s1.contains("f"))  // NO violation; s1 is a lambda parameter
13                  .collect(java.util.stream.Collectors.toList());
14  
15          s1 = "foo1"; // violation; validateOnlyOverlapping=false
16      }
17  
18      void foo2() {
19          final java.util.List<String> strings = new java.util.ArrayList<>();
20          strings.add("foo1");
21          strings.stream().filter(s1 -> s1.contains(s1 = s1 + "2"))// NO violation;s1 is lambda param
22                  .collect(java.util.stream.Collectors.toList());
23      }
24  
25      class FirstLevel {
26  
27          int x;
28          int y;
29          int z;
30          void methodInFirstLevel(int x) {
31              Consumer<Integer> myConsumer = (y) ->   // NO violation; y is a lambda parameter
32              {
33                  new String("x = " + x);
34                  new String("y = " + y);  // NO violation; y is a lambda parameter
35                  new String("InputRequireThisAllowLambdaParameters.this.x = " +
36                          InputRequireThisAllowLambdaParameters.this.x);
37                  y=x+z++; // 1 violation for z; NO violation for y; y is a lambda parameter
38              };
39              myConsumer.accept(x);
40          }
41      }
42  }
43  
44  class Calculator {
45  
46      int a;
47      int b;
48      interface IntegerMath {
49          int operation(int a, int b);
50      }
51  
52      public int operateBinary(int a, int b, IntegerMath op) {
53          return op.operation(a, b);
54      }
55  
56      public void addSub(String... args) {
57  
58          Calculator myApp = new Calculator();
59          IntegerMath addition = (a, b) -> a = a + b;  // NO violations
60          IntegerMath subtraction = (a, b) -> a = a - b; // NO violations
61          myApp.operateBinary(20, 10, subtraction);
62          myApp.operateBinary(a++, b, addition);  // 2 violations
63      }
64  }