View Javadoc
1   /*
2   RequireThis
3   checkFields = (default)true
4   checkMethods = (default)true
5   validateOnlyOverlapping = false
6   
7   
8   */
9   
10  package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;
11  
12  public class InputRequireThisAnonymousEmpty {
13  
14      private int bar; private int Override;
15      int a;
16  
17      interface AnonWithEmpty {
18          public void fooEmpty();
19      }
20  
21      void method() {
22          AnonWithEmpty foo = new AnonWithEmpty() {
23  
24              public void emptyMethod() {
25              }
26  
27              @Override
28              public void fooEmpty() {
29                  int a = doSideEffect(); // violation 'Method call to 'doSideEffect' needs "this.".'
30              }
31  
32              public int doSideEffect() {
33                  return bar; // violation '.* 'bar' needs "InputRequireThisAnonymousEmpty.this.".'
34              }
35          };
36  
37          new AnonWithEmpty() {
38              int anonMember = 0;
39  
40              @Override
41              public void fooEmpty() {
42                  new AnonWithEmpty() {
43  
44                      @Override
45                      public void fooEmpty() {
46                          anonMember++;
47                      }
48                  };
49              }
50          };
51  
52          new AnonWithEmpty() {
53              int foobar = 1;
54              @Override
55              public void fooEmpty() {
56                  foobar++; // violation 'Reference to instance variable 'foobar' needs "this.".'
57              }
58          };
59      }
60  
61      void method2() {
62          int a = 1;
63          InputRequireThisAnonymousEmpty obj =
64              new InputRequireThisAnonymousEmpty() {
65                  void method() {
66                      a += 1;
67                  }
68              };
69      }
70  
71      void anotherMethod() {
72          int var1 = 12;
73          int var2 = 13;
74          Foo obj = new Foo() {
75              void method() {
76                  var2 += var1;
77              }
78          };
79          obj.getClass();
80      }
81  }
82  
83  class SharkFoo {
84      int var1 = 12;
85  }
86  
87  class Foo {
88      int var2 = 13;
89  
90      class SharkFoo {
91      }
92  }