View Javadoc
1   /*
2   Input test file for RequireThisCheck.
3   Created: 2017
4    */
5   
6   package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;
7   
8   class InputRequireThisAllowLocalVars {
9   
10      private String s1 = "foo1";
11      String s2 = "foo2";
12  
13      InputRequireThisAllowLocalVars() {
14          s1 = "bar1"; // Violation. Requires "this".
15          String s2;
16          s2 = "bar2"; // No violation. Local var allowed.
17      }
18  
19      public int getS1() {
20          String s1 = null;
21          s1 = "bar"; // No violation
22          s1 = s1;    // Violation. "this" required here to resolve any confusion due to overlapping.
23          return 1;
24      }
25  
26      public String getS1(String param) {
27          String s1 = null;
28          s1 = param; // No violation
29          s1 += s1;   // No violation. s1 is being returned.
30          return s1;  // No violation
31      }
32  
33      String getS2() {
34          String s2 = null;
35          s2+=s2; // Violation. "this" required here to resolve any confusion due to overlapping.
36          return "return";
37      }
38  
39      String getS2(String s2) {
40          s2 = null; // Violation. Requires "this". s2 is a param not a local var.
41          return s2; // No violation. param is returned.
42      }
43  
44      String getS2(int a) {
45          String s2 = " ";
46          s2 += s2;  // Violation. "this" required here to resolve any confusion due to overlapping.
47          return s1; // Violation. Requires "this".
48      }
49  }