View Javadoc
1   package com.google.checkstyle.test.chapter4formatting.rule44columnlimit;
2   
3   // ok above, longer package statements are allowed
4   
5   // ok below, longer imports are allowed
6   import com.google.checkstyle.test.chapter3filestructure.toolongpackagetotestcoveragegooglesjavastylerule.PackageStatementTest;
7   import java.io.IOException;
8   
9   final class InputFormattedColumnLimit {
10    // Long line
11    // ----------------------------------------------------------------------------------------------------
12    // violation above 'Line is longer than 100 characters (found 105).'
13  
14    PackageStatementTest pckgStmt = new PackageStatementTest();
15  
16    private int[] testing =
17        new int[] {
18          1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
19          26, 27
20        };
21  
22    /**
23     * Some javadoc.
24     *
25     * @param badFormat1 bad format
26     * @param badFormat2 bad format
27     * @param badFormat3 bad format
28     * @return hack
29     * @throws java.lang.Exception abc
30     */
31    int test1(int badFormat1, int badFormat2, final int badFormat3) throws java.lang.Exception {
32      return 0;
33    }
34  
35    /**
36     * Some javadoc. Very long url with https:
37     * https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheck.java
38     */
39    String https = "200 OK";
40  
41    /**
42     * Some javadoc. Very long url with http:
43     * http://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheck.java
44     */
45    String http = "200 OK";
46  
47    // Very long url with ftp:
48    // ftp://ftp.example.com/areallyyyyyyyyyyyylongggggggggggggggggggggggurlllll.text
49    int ftp = 0;
50  
51    // violation 2 lines below 'Line is longer than 100 characters (found 111).'
52    // Very long url with invalid href:
53    // href="www.google.com/search?hl=en&q=java+style+guide+checkstyle+check+href+length+limit&btnG=Google+Search
54    int invalidHref = 88;
55  
56    // Very long url with valid href:
57    // href="www.google.com/search?hl=en&q=java+style+guide+checkstyle+check+href+length+limit&btnG=Google+Search"
58    int validHref = 54;
59  
60    // violation 2 lines below 'Line is longer than 100 characters (found 107).'
61    // Very long url with valid href: href    =
62    // "www.google.com/search?hl=en&q=java+style+guide+checkstyle+check+href+length+limit&btnG=Google+Search"
63    int validHrefWithWhiteSpaces = 54;
64  
65    // violation 2 lines below 'Line is longer than 100 characters (found 114).'
66    int
67        aaaarealllllllllllllllllyyyyyyyyyyylllllllloooooooooooooooonnnnnnnnnnnnnnnnnggggggggggvvvvvvaarriaaabllee1 =
68            99;
69  
70    // CHECKSTYLE.SUPPRESS: LineLength for +2 lines
71    int
72        aaaarealllllllllllllllllyyyyyyyyyyylllllllloooooooooooooooonnnnnnnnnnnnnnnnnggggggggggvvvvvvaarriaaabllee2 =
73            99;
74  
75    // suppressed above.
76  
77    // violation 2 lines below 'Line is longer than 100 characters (found 108).'
78    void
79        longggggggggggggggggggggmethoooooooooooooooooooooodddddddddddddddddddddddddddddddddddddddddddddd1() {}
80  
81    // CHECKSTYLE.SUPPRESS: LineLength for +2 lines
82    void
83        longggggggggggggggggggggmethoooooooooooooooooooooodddddddddddddddddddddddddddddddddddddddddddddd2() {}
84  
85    // suppressed above.
86  
87    final boolean isValid = true;
88    final boolean isValid2 = true;
89    final boolean isValid3 = true;
90    final boolean isValid4 = true;
91    final boolean isValid5 = true;
92  
93    void testingNestedIf1() {
94      if (isValid) {
95        if (isValid2) {
96          if (isValid3) {
97            if (isValid4) {
98              if (isValid5) {
99                // CHECKSTYLE.SUPPRESS: LineLength for +1 lines
100               longggggggggggggggggggggmethoooooooooooooooooooooodddddddddddddddddddddddddddddddddddddddddddddd1();
101             }
102           }
103         }
104       }
105     }
106   }
107 
108   void testingNestedIf2() {
109     if (isValid) {
110       if (isValid2) {
111         if (isValid3) {
112           if (isValid4) {
113             if (isValid5) {
114               // violation below 'Line is longer than 100 characters (found 114).'
115               longggggggggggggggggggggmethoooooooooooooooooooooodddddddddddddddddddddddddddddddddddddddddddddd2();
116             }
117           }
118         }
119       }
120     }
121   }
122 
123   // violation 3 lines below 'Line is longer than 100 characters (found 118).'
124   void testingParametersNames1(
125       int
126           areallllllyyyyyyyyyyyyyyyyyylonnnnggggggggggnameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee,
127       int anotherlongnameblahblahblah) {}
128 
129   // CHECKSTYLE.SUPPRESS: LineLength for +3 lines
130   void testingParametersNames2(
131       int
132           areallllllyyyyyyyyyyyyyyyyyylonnnnggggggggggnameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee,
133       int anotherlongnameblahblahblah) {}
134 
135   // suppressed above.
136 
137   InputColumnLimit inputColumnLimit1 =
138       (InputColumnLimit)
139           ((Object)
140               new com.google.checkstyle.test.chapter4formatting.rule44columnlimit
141                   .InputColumnLimit());
142 
143   // CHECKSTYLE.SUPPRESS: LineLength for +1 lines
144   InputColumnLimit inputColumnLimit2 =
145       (InputColumnLimit)
146           ((Object)
147               new com.google.checkstyle.test.chapter4formatting.rule44columnlimit
148                   .InputColumnLimit());
149 
150   // suppressed above.
151   // Above code is wrap-able, user should not use suppression for such cases
152 
153   void testing1() {
154     try {
155       throwExceptionBasedOnCondition1();
156     } catch (IOException
157         | NullPointerException
158         | ArrayIndexOutOfBoundsException
159         | ClassNotFoundException ex) {
160       System.out.println(ex.getMessage());
161     }
162   }
163 
164   void testing2() {
165     try {
166       throwExceptionBasedOnCondition2();
167       // CHECKSTYLE.SUPPRESS: LineLength for +1 lines
168     } catch (IOException
169         | NullPointerException
170         | ArrayIndexOutOfBoundsException
171         | ClassNotFoundException ex) {
172       // Above code is wrap-able. User should not use suppression for such cases
173       System.out.println(ex.getMessage());
174     }
175   }
176 
177   void throwExceptionBasedOnCondition1()
178       throws IOException,
179           NullPointerException,
180           ArrayIndexOutOfBoundsException,
181           ClassNotFoundException {
182     int condition = new java.util.Random().nextInt(3);
183     switch (condition) {
184       case 0:
185         throw new IOException("Test IOException");
186       case 1:
187         throw new NullPointerException("Test NullPointerException");
188       case 2:
189         throw new ArrayIndexOutOfBoundsException("Test ArrayIndexOutOfBoundsException");
190       case 3:
191         throw new ClassNotFoundException("Test ClassNotFoundException");
192       default:
193     }
194   }
195 
196   // CHECKSTYLE.SUPPRESS: LineLength for +2 lines
197   void throwExceptionBasedOnCondition2()
198       throws IOException,
199           NullPointerException,
200           ArrayIndexOutOfBoundsException,
201           ClassNotFoundException {
202     // suppressed above.
203     // Above code is wrap-able. User should not use suppression for such cases
204     int condition = new java.util.Random().nextInt(3);
205     switch (condition) {
206       case 0:
207         throw new IOException("Test IOException");
208       case 1:
209         throw new NullPointerException("Test NullPointerException");
210       case 2:
211         throw new ArrayIndexOutOfBoundsException("Test ArrayIndexOutOfBoundsException");
212       case 3:
213         throw new ClassNotFoundException("Test ClassNotFoundException");
214       default:
215     }
216   }
217 
218   // CHECKSTYLE.SUPPRESS: LineLength for +1 lines
219   class LonggggggggggggggggggggggggggggClassssssssssssssssssssssssssNameeeeeeeeeeeeeeSoooooBoooooorrriinngggg1 {
220     // ok below, as it is suppressed.
221     void
222         longggggggggggggggggggggmethooooooooooooooooooooooddddddddddddddddddddddddddddddddddddddddddddddddddddddd(
223             int x, int y) {}
224 
225     // CHECKSTYLE.SUPPRESS: LineLength for -3 lines
226 
227     // ok below, as it is suppressed.
228     // violation 4 lines below '.* indentation should be the same level as line 231.'
229     int
230         aaaarealllllllllllllllllyyyyyyyyyyylllllllloooooooooooooooonnnnnnnnnnnnnnnnnggggggggggvvvvvvaarriaaablleeeeeeeeeeee =
231             99;
232     // CHECKSTYLE.SUPPRESS: LineLength for -2 lines
233   }
234 
235   // violation below 'Line is longer than 100 characters (found 112).'
236   class LonggggggggggggggggggggggggggggClassssssssssssssssssssssssssNameeeeeeeeeeeeeeSoooooBoooooorrriinngggg2 {
237     // violation 2 lines below 'Line is longer than 100 characters (found 114).'
238     void
239         longggggggggggggggggggggmethooooooooooooooooooooooddddddddddddddddddddddddddddddddddddddddddddddddddddddd(
240             int x, int y) {}
241 
242     // violation 2 lines below 'Line is longer than 100 characters (found 125).'
243     int
244         aaaarealllllllllllllllllyyyyyyyyyyylllllllloooooooooooooooonnnnnnnnnnnnnnnnnggggggggggvvvvvvaarriaaablleeeeeeeeeeee =
245             99;
246   }
247 }