View Javadoc
1   /*
2   RequireThis
3   checkFields = (default)true
4   checkMethods = false
5   validateOnlyOverlapping = false
6   
7   
8   */
9   
10  package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;
11  
12  class InputRequireThisAllowLocalVars {
13  
14      private String s1 = "foo1";
15      String s2 = "foo2";
16  
17      InputRequireThisAllowLocalVars() {
18          s1 = "bar1"; // violation 'Reference to instance variable 's1' needs "this.".'
19          String s2;
20          s2 = "bar2"; // No violation. Local var allowed.
21      }
22  
23      public int getS1() {
24          String s1 = null;
25          s1 = "bar"; // No violation
26          s1 = s1; // violation 'Reference to instance variable 's1' needs "this.".'
27          return 1;
28      }
29  
30      public String getS1(String param) {
31          String s1 = null;
32          s1 = param; // No violation
33          s1 += s1;   // No violation. s1 is being returned.
34          return s1;  // No violation
35      }
36  
37      String getS2() {
38          String s2 = null;
39          s2+=s2; // violation 'Reference to instance variable 's2' needs "this.".'
40          return "return";
41      }
42  
43      String getS2(String s2) {
44          s2 = null; // violation 'Reference to instance variable 's2' needs "this.".'
45          return s2; // No violation. param is returned.
46      }
47  
48      String getS2(int a) {
49          String s2 = " ";
50          s2 += s2; // violation 'Reference to instance variable 's2' needs "this.".'
51          return s1; // violation 'Reference to instance variable 's1' needs "this.".'
52      }
53  }