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