View Javadoc
1   /*
2   ArrayTrailingComma
3   alwaysDemandTrailingComma = true
4   
5   
6   */
7   
8   package com.puppycrawl.tools.checkstyle.checks.coding.arraytrailingcomma;
9   
10  public class InputArrayTrailingCommaAlwaysDemandTrailingComma {
11      public int[] test() {
12          if (true) {
13              return new int[]{0,};
14          }
15          return new int[]{0}; // violation 'Array should contain trailing comma.'
16      }
17  
18      public int[] test2() {
19          if (true) {
20              return new int[]{0, 1,};
21          }
22          return new int[]{0, 1}; // violation 'Array should contain trailing comma.'
23      }
24  
25      public void test3() {
26          int[] a = new int[]
27              {0}; // violation 'Array should contain trailing comma.'
28          int[] b = new int[]
29              {0, 1}; // violation 'Array should contain trailing comma.'
30          int[] c = new int[]
31              {0, 1,
32                  2, 3 // violation 'Array should contain trailing comma.'
33              };
34          int[] d = new int[]
35              {
36                  1,
37                  2,
38                  3 // violation 'Array should contain trailing comma.'
39              };
40          int[] e = new int[]
41              {
42                  1,
43                  5,
44                  6,
45              };
46          int[] f = {1,
47              2 // violation 'Array should contain trailing comma.'
48          };
49          int[] g = {1,
50              2,
51          };
52          int[][] empty2d = {{}}; // violation 'Array should contain trailing comma.'
53          int[][] multiDimensionalArray = {
54              {1, 2}, // violation 'Array should contain trailing comma.'
55              {1,},
56              {3, 2, 1,} // violation 'Array should contain trailing comma.'
57          };
58      }
59  }