View Javadoc
1   /*
2   EmptyLineSeparator
3   allowNoEmptyLineBetweenFields = (default)false
4   allowMultipleEmptyLines = false
5   allowMultipleEmptyLinesInsideClassMembers = (default)true
6   tokens = (default)PACKAGE_DEF, IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, \
7            STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF, RECORD_DEF, \
8            COMPACT_CTOR_DEF
9   
10  
11  */
12  package com.puppycrawl.tools.checkstyle.checks.whitespace.emptylineseparator; // violation ''package' should be separated from previous line.'
13  
14  
15  
16  // violation ''//' has more than 1 empty lines before.'
17  
18  
19  
20  import java.lang.Object; // violation ''import' has more than 1 empty lines before.'
21  
22  import java.lang.Class;
23  
24  
25  // violation ''//' has more than 1 empty lines before.'
26  import java.lang.Integer;
27  
28  // ok, because no more than 1 empty lines before
29  import java.lang.Long;
30  
31  
32  /* // violation ''/\*' has more than 1 empty lines before.'
33   *
34   */
35  import java.lang.Float;
36  
37  /*
38   * something
39   */
40  import java.lang.Double;
41  
42  
43  /** // violation ''/\*' has more than 1 empty lines before.'
44   *
45   */
46  import java.lang.Character;
47  
48  /**
49   * something
50   */
51  import java.lang.String;
52  
53  /*
54   * something
55   */
56  /* something */
57  import java.lang.Object;
58  
59  
60  // violation ''//' has more than 1 empty lines before.'
61  // .
62  import java.lang.Boolean;
63  
64  import java.lang.Byte;
65  
66  // ok, because no more than 1 empty lines before
67  /* something  */
68  import java.lang.Short;
69  
70  
71  /* something */
72  // violation above ''/\*' has more than 1 empty lines before.'
73  import java.lang.Number;
74  
75  
76  import java.lang.Runnable; // violation ''import' has more than 1 empty lines before.'
77  import java.lang.Thread;
78  
79  // ok, because no more than 1 empty lines before
80  
81  
82  // violation ''//' has more than 1 empty lines before.'
83  import java.lang.StringBuilder;
84  
85  
86  /* // violation ''/\*' has more than 1 empty lines before.'
87   *
88   */
89  import static java.lang.Math.abs;
90  
91  public class InputEmptyLineSeparatorWithComments {
92  
93  
94      public int testViolationWithoutComment = 1; // violation ''VARIABLE_DEF' .*1 empty lines .*'
95  
96      public int testNoViolationWithoutComment = 2;
97  
98  
99      // violation ''//' has more than 1 empty lines before.'
100     public int testViolationWithSingleLineComment = 3;
101 
102     // Should be ok
103     public int testNoViolationWithSingleLineComment = 4;
104 
105 
106     /* // violation ''/\*' has more than 1 empty lines before.'
107      * Should have
108      * violation
109      */
110     public int testViolationWithMultilineComment = 5;
111 
112     /*
113      * Should not have
114      * violation
115      */
116     public int testNoViolationWithMultilineComment = 6;
117 
118 
119     /** // violation ''/\*' has more than 1 empty lines before.'
120      * Should have
121      * violation
122      */
123     public int testViolationWithJavadoc = 7;
124 
125     /**
126      * Should not have
127      * violation
128      */
129     public int testNoViolationWithJavadoc = 8;
130 
131 
132     public void testViolationWithoutComment() { // violation ''METHOD_DEF' .*1 empty lines .*'
133     }
134 
135     public void testNoViolationWithoutComment() {
136     }
137 
138 
139     // violation ''//' has more than 1 empty lines before.'
140     public void testViolationWithSingleLineComment() {
141     }
142 
143     // Should not have
144     // a violation
145     public void testNoViolationWithSingleLineComment() {
146     }
147 
148 
149     /*// violation ''/\*' has more than 1 empty lines before.'
150      * Should have
151      * violation
152      */
153     public void testViolationWithMultilineComment() {
154     }
155 
156     /*
157      * Should not have
158      * violation
159      */
160     public void testNoViolationWithMultilineComment() {
161     }
162 
163 
164     /** // violation ''/\*' has more than 1 empty lines before.'
165      * Should have
166      * violation
167      */
168     public void testViolationWithJavadoc() {
169     }
170 
171     /**
172      * Should not have
173      * violation
174      */
175     public void testNoViolationWithJavadoc() {
176     }
177 
178     public static class Class1 { }
179 
180 
181     public static class Class2 { } // violation ''CLASS_DEF' has more than 1 empty lines before.'
182 
183     // ok, because no more than 1 empty lines before
184     public static class Class3 { }
185 
186 
187     // violation ''//' has more than 1 empty lines before.'
188     public static class Class4 { }
189 
190 
191     // violation ''//' has more than 1 empty lines before.'
192     public
193     // ok, because no more than 1 empty lines before
194     static class Class5 { }
195 
196 
197     // violation ''//' has more than 1 empty lines before.'
198     public
199     /* something */
200     static class Class6 { }
201 
202     /*
203      * Should not have
204      * violation
205      */
206     public static class Class7 { }
207 
208 
209     /* // violation ''/\*' has more than 1 empty lines before.'
210      * Should have
211      * violation
212      */
213     public static class Class8 { }
214 
215     /**
216      * Should not have
217      * violation
218      */
219     public static class Class9 { }
220 
221 
222     /** // violation ''/\*' has more than 1 empty lines before.'
223      * Should have
224      * violation
225      */
226     public static class Class10 {
227         {
228 
229         }
230     }
231 
232     // ok, because no more than 1 empty lines before
233     public interface Interface1 { }
234 
235 
236     // violation ''//' has more than 1 empty lines before.'
237     public interface Interface2 { }
238     // violation below ''INTERFACE_DEF' should be separated from previous line.'
239     public
240     // .
241     interface Interface3 { }
242 
243 
244     /* // violation ''/\*' has more than 1 empty lines before.'
245      */
246     /* . */
247     /* . */
248     /* . */
249     interface Interface4 { }
250 
251     // ok, because no more than 1 empty lines before
252 
253     // ok, because no more than 1 empty lines before
254     // .
255     // .
256     // .
257     interface Interface5 { }
258 
259 
260     // violation ''//' has more than 1 empty lines before.'
261     public enum Enum1 {
262         E1, E2
263     }
264 
265     // ok, because no more than 1 empty lines before
266     public enum Enum2 { }
267 
268 
269     // violation ''//' has more than 1 empty lines before.'
270     // ok, because no more than 1 empty lines before
271 
272     // ok, because no more than 1 empty lines before
273     public enum Enum3 { }
274     // ok, because no more than 1 empty lines before
275 
276     public enum Enum4 { }
277     // ok, because no more than 1 empty lines before
278 
279     public enum Enum5 { }
280 
281 
282     // violation ''//' has more than 1 empty lines before.'
283 
284     public
285 
286 
287     // violation ''//' has more than 1 empty lines before.'
288     static
289 
290     enum Enum6 { }
291 
292 
293     // violation ''//' has more than 1 empty lines before.'
294     static {
295         abs(2);
296     }
297 
298     // ok, because no more than 1 empty lines before
299 
300 
301     // violation ''//' has more than 1 empty lines before.'
302     {
303        abs(1);
304     }
305 
306     /* something */
307     { }
308 
309 
310     // violation ''//' has more than 1 empty lines before.'
311     {
312         int i = 1;
313     }
314 
315 
316     // violation ''//' has more than 1 empty lines before.'
317     // .
318     /* . */ public InputEmptyLineSeparatorWithComments() {
319         testNoViolationWithJavadoc = 1;
320     }
321 
322     // ok, because no more than 1 empty lines before
323     /* . */ public InputEmptyLineSeparatorWithComments(int i) {
324         testNoViolationWithJavadoc = 1;
325     }
326 
327     // ok, because no more than 1 empty lines before
328     // ok, because no more than 1 empty lines before
329 
330     // ok, because no more than 1 empty lines before
331     public InputEmptyLineSeparatorWithComments(int i, int j) {
332         testNoViolationWithJavadoc = 1;
333     }
334 
335 
336     // violation ''//' has more than 1 empty lines before.'
337     // ok, because no more than 1 empty lines before
338 
339     // ok, because no more than 1 empty lines before
340 
341 
342 
343 
344     // violation ''//' has more than 1 empty lines before.'
345     public InputEmptyLineSeparatorWithComments(int i, int j, int k) {
346         testNoViolationWithJavadoc = 1;
347     }
348 
349 }