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