View Javadoc
1   package com.google.checkstyle.test.chapter4formatting.rule4821onevariableperline;
2   
3   /** Some javadoc. */
4   public class InputFormattedOneVariablePerDeclaration {
5     int mnp, efg; // violation 'Each variable declaration must be in its own statement.'
6     int i1;
7     int j1;
8   
9     void method1() {
10      String str, str1; // violation 'Each variable declaration must be in its own statement.'
11      java.lang.Object obj;
12      Object obj1;
13    }
14  
15    // second definition is wrapped
16    // line of VARIABLE_DEF is not the same as first line of the definition
17    java.lang.String string;
18    java.lang.String[] strings;
19    // both definitions are wrapped
20    java.lang.String string1;
21    java.lang.String[] strings1;
22  
23    void method2() {
24      for (int i = 0, j = 0; i < 10; i++, j--) { // ok
25      }
26  
27      for (int i = 0; i < 4; i++) {}
28    }
29  
30    class Inner {
31      int xyz, qwe; // violation 'Each variable declaration must be in its own statement.'
32      int i1;
33      int j1;
34  
35      void method1() {
36        String str, str1;
37        // violation above 'Each variable declaration must be in its own statement.'
38        java.lang.Object obj;
39        Object obj1;
40      }
41  
42      // second definition is wrapped
43      // line of VARIABLE_DEF is not the same as first line of the definition
44      java.lang.String string;
45      java.lang.String[] strings;
46      // both definitions are wrapped
47      java.lang.String string1;
48      java.lang.String[] strings1;
49  
50      void method2() {
51        for (int i = 0, j = 0; i < 10; i++, j--) { // ok
52        }
53  
54        for (int i = 0; i < 4; i++) {}
55      }
56  
57      Inner anon =
58          new Inner() {
59            int abc, pqr; // violation 'Each variable declaration must be in its own statement.'
60            int i1;
61            int j1;
62  
63            void method1() {
64              String str, str1;
65              // violation above 'Each variable declaration must be in its own statement.'
66              java.lang.Object obj;
67              Object obj1;
68            }
69  
70            // second definition is wrapped
71            // line of VARIABLE_DEF is not the same as first line of the definition
72            java.lang.String string;
73            java.lang.String[] strings;
74            // both definitions are wrapped
75            java.lang.String string1;
76            java.lang.String[] strings1;
77  
78            void method2() {
79              for (int i = 0, j = 0; i < 10; i++, j--) { // ok
80              }
81  
82              for (int i = 0; i < 4; i++) {}
83            }
84          };
85    }
86  
87    class Suppress {
88      @SuppressWarnings("unused")
89      // violation above 'Each variable declaration must be in its own statement.'
90      long q1, q2, q3;
91      @SuppressWarnings("unused")
92      long q4, q5, q6;
93      // violation 2 lines above 'Each variable declaration must be in its own statement.'
94    }
95  }