View Javadoc
1   /*
2   NoWhitespaceAfter
3   allowLineBreaks = (default)true
4   tokens = ARRAY_DECLARATOR,INDEX_OP
5   
6   
7   */
8   
9   package com.puppycrawl.tools.checkstyle.checks.whitespace.nowhitespaceafter;
10  
11  import java.util.List;
12  
13  
14  
15  public class InputNoWhitespaceAfterArrayDeclarations2
16  {
17  
18      public class A {
19          public int[][] create(int i, int j) {
20              return new int[3] [3]; // violation
21          }
22      }
23  
24      public class B {
25          public int create(int i, int j) [][] { // violation
26              return new int     [3][i + j] ; // violation
27          }
28      }
29  
30      public class C {
31          public int[][] create(int i, int j) {
32              return new int[i + j][i + j];//correct
33          }
34      }
35  
36      public class D {
37          public int[][]   [] create(int i, int j) { // violation
38              return new int  [ i + j ]    [ i + j ]               [ 0 ]     ; // 3 violations
39          }
40      }
41  
42      public class E {
43          public int create(int i, int j, int   [][] k)[] [][] { // 2 violations
44              int e [][] [] = new int[i + j] [2][i + j]; // 3 violations
45              e [0] [1][2] = 0; e[1][1][1] = 0; // 2 violations
46              return e;
47          }
48      }
49      public static class F {
50          public static Integer [][][] create(int i, int j) { // violation
51              int[][] [] f= new int[   0][1    ][    2    ]   ; // violation
52              return new Integer[i + j][i + j][0];
53          }
54      }
55      public class G {
56          public List<String> [] [] [] create(int i, int j) { // 3 violations
57              //cannot build with check - generic array creation error, but whitespaces still caught
58              //List<String> g[][] [] = new List<String> [0][1][2];//incorrect 49:33,55
59              //return new List<String>[i + j][i + j][0];//correct
60              int g[][][] = new int [0][1][2]; // violation
61              g[  0][0   ][   0   ]=0;
62              g [0][0][0]=0; // violation
63              g[0] [0][0]=0; // violation
64              g [0] [0] [0]        =0; // 3 violations
65              return null;
66          }
67  
68      }
69      public class H {
70          public List<Integer> create(int i, int j)     []      [][] { // 2 violations
71              return null;
72          }
73      }
74  
75      Object someStuff4 = boolean [].class; // violation
76      String[][] someStuff5 = new String[4][9];
77      String[][] someStuff6 = (java.lang.String  []  []) someStuff5; // 2 violations
78      String[][] someStuff7 = (String [][]) someStuff5; // violation
79  
80      //this is legal until allowLineBreaks is set to false
81      int someStuff8
82      [];
83  
84      //this is legal until allowLineBreaks is set to false
85      int[]
86      someStuff81;
87  
88  
89      Integer someStuff9[][][] = (Integer [][][]) F.create(1,2); // violation
90  
91      //type arguments
92      List<char[]> someStuff10;//correct
93      List<char [][]> someStuff11; // violation
94      List<InputNoWhitespaceAfterArrayDeclarations2.A []> someStuff12; // violation
95      void foo(List<? extends String[]> bar, Comparable<? super Object []> baz) { } // violation
96  
97      Integer someStuff13 = F.create(1,1)[0][0][0];
98      Integer someStuff131 = F.create(1,1)  [0][0]   [0]; // 2 violations
99      Object[] someStuff14 = (Object[]) null;
100     Object[] someStuff15 = (Object  []  ) null; // violation
101 
102     byte someStuff16 = ((byte[]) someStuff4) [0]; // violation
103 
104     public void bar() {
105         if(someStuff15 instanceof Object  []) { // violation
106 
107         }
108         if(someStuff15 instanceof Object[]  []) { // violation
109 
110         }
111         if(someStuff15 instanceof Object[][]) {
112 
113         }
114         Object[] a = null;
115 
116         if(a instanceof Object  []) { // violation
117 
118         }
119         if(a instanceof Object[][]) {
120 
121         }
122     }
123 
124 }