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