View Javadoc
1   /*
2   VisibilityModifier
3   packageAllowed = (default)false
4   protectedAllowed = (default)false
5   publicMemberPattern = ^f[A-Z][a-zA-Z0-9]*$
6   allowPublicFinalFields = (default)false
7   allowPublicImmutableFields = (default)false
8   immutableClassCanonicalNames = (default)java.io.File, java.lang.Boolean, java.lang.Byte, \
9                                  java.lang.Character, java.lang.Double, java.lang.Float, \
10                                 java.lang.Integer, java.lang.Long, java.lang.Short, \
11                                 java.lang.StackTraceElement, java.lang.String, \
12                                 java.math.BigDecimal, java.math.BigInteger, \
13                                 java.net.Inet4Address, java.net.Inet6Address, \
14                                 java.net.InetSocketAddress, java.net.URI, java.net.URL, \
15                                 java.util.Locale, java.util.UUID
16  ignoreAnnotationCanonicalNames = (default)com.google.common.annotations.VisibleForTesting, \
17                                   org.junit.ClassRule, org.junit.Rule
18  
19  
20  */
21  
22  package com.puppycrawl.tools.checkstyle.checks.design.visibilitymodifier;
23  import java.io.*;
24  /**
25   * Contains simple mistakes:
26   * - Long lines
27   * - Tabs
28   * - Format of variables and parameters
29   * - Order of modifiers
30   * @author Oliver Burn
31   **/
32  final class InputVisibilityModifierSimple
33  {
34      /** Invalid format **/
35      public static final int badConstant = 2;
36      /** Valid format **/
37      public static final int MAX_ROWS = 2;
38  
39      /** Invalid format **/
40      private static int badStatic = 2;
41      /** Valid format **/
42      private static int sNumCreated = 0;
43  
44      /** Invalid format **/
45      private int badMember = 2;
46      /** Valid format **/
47      private int mNumCreated1 = 0;
48      /** Valid format **/
49      protected int mNumCreated2 = 0; // violation
50  
51      /** commas are wrong **/
52      private int[] mInts = new int[] {1,2, 3,
53                                       4};
54  
55      //
56      // Accessor tests
57      //
58      /** should be private **/
59      public static int sTest1; // violation
60      /** should be private **/
61      protected static int sTest3; // violation
62      /** should be private **/
63      static int sTest2; // violation
64  
65      /** should be private **/
66      int mTest1; // violation
67      /** should be private **/
68      public int mTest2; // violation
69  
70      /**
71       * @return hack
72       * @param badFormat1 bad format
73       * @param badFormat2 bad format
74       * @param badFormat3 bad format
75       * @throws java.lang.Exception abc
76       **/
77      int test1(int badFormat1,int badFormat2,
78                final int badFormat3)
79          throws java.lang.Exception
80      {
81          return 0;
82      }
83  
84      /** test local variables */
85      private void localVariables()
86      {
87          // normal decl
88          int abc = 0;
89          int ABC = 0;
90  
91          // final decls
92          final int cde = 0;
93          final int CDE = 0;
94  
95          // decl in for loop init statement
96          for (int k = 0; k < 1; k++)
97          {
98              String innerBlockVariable = "";
99          }
100         for (int I = 0; I < 1; I++)
101         {
102             String InnerBlockVariable = "";
103         }
104     }
105 
106     /** test illegal constant **/
107     private static final int BAD__NAME = 3;
108 }
109 
110 /** Test class for variable naming in for each clause. */
111 class InputVisibilityModifierSimple2
112 {
113     /** Some more Javadoc. */
114     public void doSomething()
115     {
116         //"O" should be named "o"
117         for (Object O : new java.util.ArrayList())
118         {
119 
120         }
121     }
122 }
123 
124 /** Test enum for member naming check */
125 enum MyEnum1
126 {
127     /** ABC constant */
128     ABC,
129 
130     /** XYZ constant */
131     XYZ;
132 
133     /** Should be mSomeMember */
134     private int someMember;
135 }