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