View Javadoc
1   /*xml
2   <module name="Checker">
3     <module name="TreeWalker">
4       <module name="VariableDeclarationUsageDistance">
5         <property name="ignoreFinal" value="false"/>
6       </module>
7     </module>
8   </module>
9   */
10  package com.puppycrawl.tools.checkstyle.checks.coding.variabledeclarationusagedistance;
11  
12  // xdoc section -- start
13  public class Example6 {
14  
15    public void foo1() {
16      // violation below, 'variable 'num' declaration and its first usage is 4.'
17      int num;
18      // violation below, 'variable 'PI' declaration and its first usage is 5.'
19      final double PI;
20      System.out.println("Statement 1");
21      System.out.println("Statement 2");
22      System.out.println("Statement 3");
23      num = 1;
24      PI = 3.14;
25    }
26  
27    public void foo2() {
28      int a;          // ok, used in different scope
29      int b;          // ok, used in different scope
30      int count = 0;  // ok, used in different scope
31  
32      {
33        System.out.println("Inside inner scope");
34        a = 1;
35        b = 2;
36        count++;
37      }
38    }
39  }
40  // xdoc section -- end