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