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