View Javadoc
1   /*
2   VariableDeclarationUsageDistance
3   allowedDistance = 1
4   ignoreVariablePattern = (default)
5   validateBetweenScopes = true
6   ignoreFinal = false
7   
8   
9   */
10  
11  package com.puppycrawl.tools.checkstyle.checks.coding.variabledeclarationusagedistance;
12  
13  import java.util.HashSet;
14  import java.util.Set;
15  
16  public class InputVariableDeclarationUsageDistanceIfStatements {
17      void method2() {
18          int a = 12; // violation 'Distance between .* declaration and its first usage is 4.'
19          if (true) {
20              method2();
21              checkIfStatementWithoutParen();
22              method2();
23              a++;
24          }
25      }
26  
27      void checkIfStatementWithoutParen() {
28          int a = 12; // violation 'Distance between .* declaration and its first usage is 2.'
29          method2();
30          if (true)
31              a++;
32          int b = 12; // violation 'Distance between .* declaration and its first usage is 2.'
33          method2();
34          if (false)
35              method2();
36          else if(true)
37              b++;
38          int c = 12; // violation 'Distance between .* declaration and its first usage is 3.'
39          method2();
40          checkIfStatementWithoutParen();
41          if (true)
42              c++;
43          else
44              method2();
45      }
46  
47      void testConsecutiveIfStatements() {
48          int a = 12;
49          int b = 13; // violation 'Distance between .* declaration and its first usage is 2.'
50          int c = 14; // violation 'Distance between .* declaration and its first usage is 3.'
51          int d = 15; // violation 'Distance between .* declaration and its first usage is 4.'
52          if (true)
53              a++;
54          if (true)
55              b++;
56          if (false)
57              c++;
58          if (true)
59              d++;
60      }
61  
62      int testReturnStatement() {
63          int a = 1; // violation 'Distance between .* declaration and its first usage is 4.'
64          testConsecutiveIfStatements();
65          testConsecutiveIfStatements();
66          testConsecutiveIfStatements();
67          if (true)
68              return a;
69  
70          return 0;
71      }
72  }