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