View Javadoc
1   /*
2   PackageName
3   format = (default)^[a-z]+(\.[a-zA-Z_]\w*)*$
4   
5   
6   */
7   
8   package com.puppycrawl.tools.checkstyle.checks.naming.packagename;
9   import java.io.*;
10  /**
11   * Contains simple mistakes:
12   * - Long lines
13   * - Tabs
14   * - Format of variables and parameters
15   * - Order of modifiers
16   * @author Oliver Burn
17   **/
18  final class InputPackageNameSimple
19  {
20      // Long line ----------------------------------------------------------------
21      // Contains a tab ->        <-
22      // Contains trailing whitespace ->
23  
24      // Name format tests
25      //
26      /** Invalid format **/
27      public static final int badConstant = 2;
28      /** Valid format **/
29      public static final int MAX_ROWS = 2;
30  
31      /** Invalid format **/
32      private static int badStatic = 2;
33      /** Valid format **/
34      private static int sNumCreated = 0;
35  
36      /** Invalid format **/
37      private int badMember = 2;
38      /** Valid format **/
39      private int mNumCreated1 = 0;
40      /** Valid format **/
41      protected int mNumCreated2 = 0;
42  
43      /** commas are wrong **/
44      private int[] mInts = new int[] {1,2, 3,
45                                       4};
46  
47      //
48      // Accessor tests
49      //
50      /** should be private **/
51      public static int sTest1;
52      /** should be private **/
53      protected static int sTest3;
54      /** should be private **/
55      static int sTest2;
56  
57      /** should be private **/
58      int mTest1;
59      /** should be private **/
60      public int mTest2;
61  
62      //
63      // Parameter name format tests
64      //
65  
66      /**
67       * @return hack
68       * @param badFormat1 bad format
69       * @param badFormat2 bad format
70       * @param badFormat3 bad format
71       * @throws java.lang.Exception abc
72       **/
73      int test1(int badFormat1,int badFormat2,
74                final int badFormat3)
75          throws java.lang.Exception
76      {
77          return 0;
78      }
79  
80      /** method that is 20 lines long **/
81      private void longMethod()
82      {
83          // a line
84          // a line
85          // a line
86          // a line
87          // a line
88          // a line
89          // a line
90          // a line
91          // a line
92          // a line
93          // a line
94          // a line
95          // a line
96          // a line
97          // a line
98          // a line
99          // a line
100         // a line
101     }
102 
103     /** constructor that is 10 lines long **/
104     private InputPackageNameSimple()
105     {
106         // a line
107         // a line
108         // a line
109         // a line
110         // a line
111         // a line
112         // a line
113         // a line
114     }
115 
116     /** test local variables */
117     private void localVariables()
118     {
119         // normal decl
120         int abc = 0;
121         int ABC = 0;
122 
123         // final decls
124         final int cde = 0;
125         final int CDE = 0;
126 
127         // decl in for loop init statement
128         for (int k = 0; k < 1; k++)
129         {
130             String innerBlockVariable = "";
131         }
132         for (int I = 0; I < 1; I++)
133         {
134             String InnerBlockVariable = "";
135         }
136     }
137 
138     /** test method pattern */
139     void ALL_UPPERCASE_METHOD()
140     {
141     }
142 
143     /** test illegal constant **/
144     private static final int BAD__NAME = 3;
145 
146     // A very, very long line that is OK because it matches the regexp "^.*is OK.*regexp.*$"
147     // long line that has a tab ->        <- and would be OK if tab counted as 1 char
148     // tabs that count as one char because of their position ->        <-   ->        <-, OK
149 
150     /** some lines to test the violation column after tabs */
151     void errorColumnAfterTabs()
152     {
153         // with tab-width 8 all statements below start at the same column,
154         // with different combinations of ' ' and '\t' before the statement
155                 int tab0 =1;
156                 int tab1 =1;
157                  int tab2 =1;
158                 int tab3 =1;
159                     int tab4 =1;
160                   int tab5 =1;
161     }
162 
163     // MEMME:
164     /* MEMME: a
165      * MEMME:
166      * OOOO
167      */
168     /* NOTHING */
169     /* YES */ /* MEMME: x */ /* YES!! */
170 
171     /** test long comments **/
172     void veryLong()
173     {
174         /*
175           blah blah blah blah
176           blah blah blah blah
177           blah blah blah blah
178           blah blah blah blah
179           blah blah blah blah
180           blah blah blah blah
181           blah blah blah blah
182           blah blah blah blah
183           blah blah blah blah
184           blah blah blah blah
185           blah blah blah blah
186           blah blah blah blah
187           blah blah blah blah
188           blah blah blah blah
189           blah blah blah blah
190           enough talk */
191     }
192 
193     /**
194      * @see to lazy to document all args. Testing excessive # args
195      **/
196     void toManyArgs(int aArg1, int aArg2, int aArg3, int aArg4, int aArg5,
197                     int aArg6, int aArg7, int aArg8, int aArg9)
198     {
199     }
200 }
201 
202 /** Test class for variable naming in for each clause. */
203 class InputPackageNameSimple2
204 {
205     /** Some more Javadoc. */
206     public void doSomething()
207     {
208         //"O" should be named "o"
209         for (Object O : new java.util.ArrayList())
210         {
211 
212         }
213     }
214 }
215 
216 /** Test enum for member naming check */
217 enum MyEnum1
218 {
219     /** ABC constant */
220     ABC,
221 
222     /** XYZ constant */
223     XYZ;
224 
225     /** Should be mSomeMember */
226     private int someMember;
227 }