View Javadoc
1   /*xml
2   <module name="Checker">
3     <module name="TreeWalker">
4       <module name="VisibilityModifier">
5         <property name="protectedAllowed" value="true"/>
6       </module>
7     </module>
8   </module>
9   
10  
11  */
12  
13  package com.puppycrawl.tools.checkstyle.checks.design.visibilitymodifier;
14  
15  import com.google.common.collect.ImmutableMap;
16  import com.google.common.collect.ImmutableSet;
17  
18  import java.util.HashSet;
19  import java.util.Set;
20  
21  // xdoc section -- start
22  class Example3 {
23    private int myPrivateField1;
24  
25    int field1; // violation, must have visibility modifier 'must be private'
26  
27    protected String field2;
28  
29    // violation below, not final nor matching pattern 'must be private'
30    public int field3 = 42;
31  
32    public long serialVersionUID = 1L;
33  
34    public static final int field4 = 42;
35  
36    // violation below, public immutable fields are not allowed 'must be private'
37    public final int field5 = 42;
38  
39    // violation below, public immutable fields are not allowed 'must be private'
40    public final java.lang.String notes = null;
41  
42    // violation below, HashSet is mutable 'must be private'
43    public final Set<String> mySet1 = new HashSet<>();
44  
45    // violation below, immutable type not in config 'must be private'
46    public final ImmutableSet<String> mySet2 = null;
47  
48    // violation below, immutable type not in config 'must be private'
49    public final ImmutableMap<String, Object> objects1 = null;
50  
51    @java.lang.Deprecated
52    String annotatedString; // violation, annotation not configured 'must be private'
53  
54    @Deprecated
55    // violation below, annotation not configured 'must be private'
56    String shortCustomAnnotated;
57  
58    @com.google.common.annotations.VisibleForTesting
59    public String testString = "";
60  }
61  // xdoc section -- end