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 InputColumnLimit {
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, 26, 27
19          // violation above 'Line is longer than 100 characters (found 105).'
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.
37     * Very long url with https: 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.
43     * Very long url with http: 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: ftp://ftp.example.com/areallyyyyyyyyyyyylongggggggggggggggggggggggurlllll.text
48    int ftp = 0;
49  
50    // violation below 'Line is longer than 100 characters (found 144).'
51    // Very long url with invalid href: href="www.google.com/search?hl=en&q=java+style+guide+checkstyle+check+href+length+limit&btnG=Google+Search
52    int invalidHref = 88;
53  
54    // Very long url with valid href: href="www.google.com/search?hl=en&q=java+style+guide+checkstyle+check+href+length+limit&btnG=Google+Search"
55    int validHref = 54;
56  
57    // Very long url with valid href: href    = "www.google.com/search?hl=en&q=java+style+guide+checkstyle+check+href+length+limit&btnG=Google+Search"
58    int validHrefWithWhiteSpaces = 54;
59  
60    // violation below 'Line is longer than 100 characters (found 118).'
61    int aaaarealllllllllllllllllyyyyyyyyyyylllllllloooooooooooooooonnnnnnnnnnnnnnnnnggggggggggvvvvvvaarriaaabllee1 = 99;
62  
63    // CHECKSTYLE.SUPPRESS: LineLength for +1 lines
64    int aaaarealllllllllllllllllyyyyyyyyyyylllllllloooooooooooooooonnnnnnnnnnnnnnnnnggggggggggvvvvvvaarriaaabllee2 = 99;
65    // suppressed above.
66  
67    // violation below 'Line is longer than 100 characters (found 109).'
68    void longggggggggggggggggggggmethoooooooooooooooooooooodddddddddddddddddddddddddddddddddddddddddddddd1() {}
69  
70    // CHECKSTYLE.SUPPRESS: LineLength for +1 lines
71    void longggggggggggggggggggggmethoooooooooooooooooooooodddddddddddddddddddddddddddddddddddddddddddddd2() {}
72    // suppressed above.
73  
74    final boolean isValid = true;
75    final boolean isValid2 = true;
76    final boolean isValid3 = true;
77    final boolean isValid4 = true;
78    final boolean isValid5 = true;
79  
80    void testingNestedIf1() {
81      if (isValid) {
82        if (isValid2) {
83          if (isValid3) {
84            if (isValid4) {
85              if (isValid5) {
86                // CHECKSTYLE.SUPPRESS: LineLength for +1 lines
87                longggggggggggggggggggggmethoooooooooooooooooooooodddddddddddddddddddddddddddddddddddddddddddddd1();
88              }
89            }
90          }
91        }
92      }
93    }
94  
95    void testingNestedIf2() {
96      if (isValid) {
97        if (isValid2) {
98          if (isValid3) {
99            if (isValid4) {
100             if (isValid5) {
101               // violation below 'Line is longer than 100 characters (found 114).'
102               longggggggggggggggggggggmethoooooooooooooooooooooodddddddddddddddddddddddddddddddddddddddddddddd2();
103             }
104           }
105         }
106       }
107     }
108   }
109 
110   // violation below 'Line is longer than 100 characters (found 179).'
111   void testingParametersNames1(int areallllllyyyyyyyyyyyyyyyyyylonnnnggggggggggnameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee, int anotherlongnameblahblahblah) {}
112 
113   // CHECKSTYLE.SUPPRESS: LineLength for +1 lines
114   void testingParametersNames2(int areallllllyyyyyyyyyyyyyyyyyylonnnnggggggggggnameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee, int anotherlongnameblahblahblah) {}
115   // suppressed above.
116 
117   // violation below 'Line is longer than 100 characters (found 156).'
118   InputColumnLimit inputColumnLimit1 = (InputColumnLimit) ((Object) new com.google.checkstyle.test.chapter4formatting.rule44columnlimit.InputColumnLimit());
119 
120   // CHECKSTYLE.SUPPRESS: LineLength for +1 lines
121   InputColumnLimit inputColumnLimit2 = (InputColumnLimit) ((Object) new com.google.checkstyle.test.chapter4formatting.rule44columnlimit.InputColumnLimit());
122   // suppressed above.
123   // Above code is wrap-able, user should not use suppression for such cases
124 
125   void testing1() {
126     try {
127       throwExceptionBasedOnCondition1();
128       // violation below 'Line is longer than 100 characters (found 111).'
129     } catch (IOException | NullPointerException | ArrayIndexOutOfBoundsException | ClassNotFoundException ex) {
130       System.out.println(ex.getMessage());
131     }
132   }
133 
134   void testing2() {
135     try {
136       throwExceptionBasedOnCondition2();
137       // CHECKSTYLE.SUPPRESS: LineLength for +1 lines
138     } catch (IOException | NullPointerException | ArrayIndexOutOfBoundsException | ClassNotFoundException ex) {
139       // Above code is wrap-able. User should not use suppression for such cases
140       System.out.println(ex.getMessage());
141     }
142   }
143 
144   // violation 2 lines below 'Line is longer than 100 characters (found 104).'
145   void throwExceptionBasedOnCondition1()
146       throws IOException, NullPointerException, ArrayIndexOutOfBoundsException, ClassNotFoundException {
147     int condition = new java.util.Random().nextInt(3);
148     switch (condition) {
149       case 0:
150         throw new IOException("Test IOException");
151       case 1:
152         throw new NullPointerException("Test NullPointerException");
153       case 2:
154         throw new ArrayIndexOutOfBoundsException("Test ArrayIndexOutOfBoundsException");
155       case 3:
156         throw new ClassNotFoundException("Test ClassNotFoundException");
157       default:
158     }
159   }
160 
161   // CHECKSTYLE.SUPPRESS: LineLength for +2 lines
162   void throwExceptionBasedOnCondition2()
163           throws IOException, NullPointerException, ArrayIndexOutOfBoundsException, ClassNotFoundException {
164     // suppressed above.
165     // Above code is wrap-able. User should not use suppression for such cases
166     int condition = new java.util.Random().nextInt(3);
167     switch (condition) {
168       case 0:
169         throw new IOException("Test IOException");
170       case 1:
171         throw new NullPointerException("Test NullPointerException");
172       case 2:
173         throw new ArrayIndexOutOfBoundsException("Test ArrayIndexOutOfBoundsException");
174       case 3:
175         throw new ClassNotFoundException("Test ClassNotFoundException");
176       default:
177     }
178   }
179 
180   // CHECKSTYLE.SUPPRESS: LineLength for +1 lines
181   class LonggggggggggggggggggggggggggggClassssssssssssssssssssssssssNameeeeeeeeeeeeeeSoooooBoooooorrriinngggg1 {
182     // ok below, as it is suppressed.
183     void longggggggggggggggggggggmethooooooooooooooooooooooddddddddddddddddddddddddddddddddddddddddddddddddddddddd(int x, int y) {}
184     // CHECKSTYLE.SUPPRESS: LineLength for -1 lines
185 
186     // ok below, as it is suppressed.
187     int aaaarealllllllllllllllllyyyyyyyyyyylllllllloooooooooooooooonnnnnnnnnnnnnnnnnggggggggggvvvvvvaarriaaablleeeeeeeeeeee = 99;
188     // CHECKSTYLE.SUPPRESS: LineLength for -1 lines
189   }
190 
191   // violation below 'Line is longer than 100 characters (found 112).'
192   class LonggggggggggggggggggggggggggggClassssssssssssssssssssssssssNameeeeeeeeeeeeeeSoooooBoooooorrriinngggg2 {
193     // violation below 'Line is longer than 100 characters (found 131).'
194     void longggggggggggggggggggggmethooooooooooooooooooooooddddddddddddddddddddddddddddddddddddddddddddddddddddddd(int x, int y) {}
195 
196     // violation below 'Line is longer than 100 characters (found 129).'
197     int aaaarealllllllllllllllllyyyyyyyyyyylllllllloooooooooooooooonnnnnnnnnnnnnnnnnggggggggggvvvvvvaarriaaablleeeeeeeeeeee = 99;
198   }
199 }