View Javadoc
1   /*
2   RequireThis
3   checkFields = false
4   checkMethods = (default)true
5   validateOnlyOverlapping = false
6   
7   
8   */
9   
10  package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;
11  
12  import java.io.ByteArrayInputStream;
13  import java.io.IOException;
14  import java.io.InputStream;
15  
16  public class InputRequireThisEnumInnerClassesAndBugs2 {
17      int i;
18      void method1() {
19          i = 3;
20      }
21  
22      void method2(int i) {
23          i++;
24          this.i = i;
25          method1(); // violation 'Method call to 'method1' needs "this.".'
26          try {
27              this.method1();
28          }
29          catch (RuntimeException e) {
30              e.toString();
31          }
32          this.i--;
33  
34          Integer.toString(10);
35      }
36  
37      <T> void method3()
38      {
39          i = 3;
40      }
41  
42      void method4() {
43          this.<String>method3();
44          this.<I>method3();
45      }
46      int I = 0;
47      private class I {}
48  }
49  
50  //  enum
51  enum MyEnum2
52  {
53      A,
54      B
55      {
56          void doSomething()
57          {
58              z = 1;
59          }
60      };
61  
62      int z;
63      private MyEnum2()
64      {
65          z = 0;
66      }
67  }
68  
69  class Bug21230032 {
70      @Rock(band = "GnR")
71      private String band;
72  
73      class Inner {
74          @Rock(band = {"GnR"})
75          private String band;
76      }
77  
78      class Inner2 {
79          @Rock(band = {"Tool"})
80          private String band;
81      }
82      /*     \m/(>.<)\m/     */
83      @interface Rock {
84          String[] band() default "Metallica";
85      }
86  }
87  
88  class Bug11559212 {
89      private static int CONST = 1;
90      private static int static_method() {
91          return 1;
92      }
93  
94      private int method1() {
95          return CONST;
96      }
97  
98      private int method2() {
99          return static_method();
100     }
101 }
102 
103 interface Issue1552 {
104     String BASE = "A";
105     String EXT = BASE + "B";
106 }
107 
108 class Issue2572 {
109     public void foo() {
110         try (final InputStream foo = new ByteArrayInputStream(new byte[512])) {
111             foo.read();
112         }
113         catch (final IOException e) {
114             e.getCause();
115         }
116     }
117 }
118 
119 class Issue22402 {
120     int i;
121     void foo() {
122         i++;
123         i++; int i = 1; i++;
124         instanceMethod(); // violation 'Method call to 'instanceMethod' needs "this.".'
125     }
126     void instanceMethod() {};
127 
128     class Nested {
129         void bar() {
130             instanceMethod(); // violation 'Method .* 'instanceMethod' needs "Issue22402.this.".'
131             i++;
132         }
133     }
134 }
135 
136 class Issue25392{
137     void foo(int i) {}
138     static void foo(double i) {}
139     void foo() {}
140 
141     void bar() {
142         foo(1);
143         foo(); // violation 'Method call to 'foo' needs "this.".'
144     }
145 }
146 
147 class NestedRechange2 {
148     final String s = "";
149 
150     NestedRechange2() {
151         String s = "t";
152         s = s.substring(0);
153     }
154 
155     private static class NestedStatic {
156         static final String s = "";
157 
158         public void method() {
159             s.substring(0);
160         }
161     }
162 }
163 
164 class NestedFrames2 {
165     int a = 0;
166     int b = 0;
167 
168     public int oneReturnInMethod2() {
169         for (int i = 0; i < 10; i++) {
170             int a = 1;
171             if (a != 2 && true) {
172                 if (true | false) {
173                     if (a - a != 0) {
174                         a += 1;
175                     }
176                 }
177             }
178         }
179         return a + a * a;
180     }
181 
182     public int oneReturnInMethod3() {
183         for (int b = 0; b < 10; b++) {
184         }
185         return b + b * b;
186     }
187     final NestedFrames NestedFrames = new NestedFrames();
188 }