aboutsummaryrefslogtreecommitdiff
path: root/src/xdocs/config_design.xml
blob: c4ded71b6d1ebeb139bff8bfa20386efaced8951 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
<?xml version="1.0" encoding="UTF-8"?>

<document xmlns="http://maven.apache.org/XDOC/2.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd">

  <head>
    <title>Class Design</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"/>
    <script type="text/javascript" src="js/anchors.js"/>
    <script type="text/javascript" src="js/google-analytics.js"/>
    <link rel="icon" href="images/favicon.png" type="image/x-icon" />
    <link rel="shortcut icon" href="images/favicon.ico" type="image/ico" />
  </head>

  <body>
    <section name="Content">
      <macro name="toc">
        <param name="fromDepth" value="1"/>
        <param name="toDepth" value="1"/>
      </macro>
    </section>

    <section name="DesignForExtension">
      <subsection name="Description">
        <p>
          The Check finds classes that are designed for extension (subclass creation).
        </p>
        <p>
          Problem is described at "Effective Java, 2nd Edition by Josh Bloch" book, chapter "Item 17: Design and document for inheritance or else prohibit it".
        </p>
        <p>
          Some quotes from book:
        </p>
        <blockquote>The class must document its self-use of overridable methods.
By convention, a method that invokes overridable methods contains a description
of these invocations at the end of its documentation comment. The description
begins with the phrase “This implementation.”
        </blockquote>
        <blockquote>The best solution to this problem is to prohibit subclassing in classes that
are not designed and documented to be safely subclassed.
        </blockquote>
        <blockquote>If a concrete class does not implement a standard interface, then you may
inconvenience some programmers by prohibiting inheritance. If you feel that you
must allow inheritance from such a class, one reasonable approach is to ensure
that the class never invokes any of its overridable methods and to document this
fact. In other words, eliminate the class’s self-use of overridable methods entirely.
In doing so, you’ll create a class that is reasonably safe to subclass. Overriding a
method will never affect the behavior of any other method.
        </blockquote>
        <p>
          The exact rule is that non-private, non-static methods of classes that
          can be subclassed must
        </p>

        <ul>
          <li>be abstract or</li>
          <li>be final or</li>
          <li>have an empty implementation.</li>
        </ul>

        <p>
          Rationale: This API design style protects superclasses against
          being broken by subclasses. The downside is that subclasses are
          limited in their flexibility, in particular they cannot prevent
          execution of code in the superclass, but that also means that
          subclasses cannot corrupt the state of the superclass by forgetting
          to call the superclass's method.
        </p>
        <p>
          More specifically,
          it enforces a programming style where superclasses provide empty
          "hooks" that can be implemented by subclasses.
        </p>
        <p>
          Example of code that cause violation as it is designed for extension:
        </p>
        <source>
public abstract class Plant {
    private String roots;
    private String trunk;

    protected void validate() {
      if (roots == null) throw new IllegalArgumentException("No roots!");
      if (trunk == null) throw new IllegalArgumentException("No trunk!");
    }

    public abstract void grow();
}

public class Tree extends Plant {
    private List leaves;

    @Overrides
    protected void validate() {
      super.validate();
      if (leaves == null) throw new IllegalArgumentException("No leaves!");
    }

    public void grow() {
      validate();
    }
}
        </source>
        <p>
          Example of code without violation:
        </p>
        <source>
public abstract class Plant {
    private String roots;
    private String trunk;

    private void validate() {
        if (roots == null) throw new IllegalArgumentException("No roots!");
        if (trunk == null) throw new IllegalArgumentException("No trunk!");
        validateEx();
    }

    protected void validateEx() { }

    public abstract void grow();
}
        </source>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check:
        </p>

        <source>
&lt;module name=&quot;DesignForExtension&quot;/&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+DesignForExtension">
            Sun Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+DesignForExtension">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="FinalClass">
      <subsection name="Description">
        <p>
          Checks that a class which has only private constructors is declared
          as final. Doesn't check for classes nested in interfaces
          or annotations, as they are always <code>final</code> there.
        </p>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check:
        </p>
        <source>
&lt;module name=&quot;FinalClass&quot;/&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+FinalClass">
            Sun Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+FinalClass">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="HideUtilityClassConstructor">
      <subsection name="Description">
        <p>
          Makes sure that utility classes (classes that contain only static
          methods or fields in their API) do not have a public constructor.
        </p>

        <p>
          Rationale: Instantiating utility classes does not make sense.  Hence
          the constructors should either be private or (if you want to allow
          subclassing) protected. A common mistake is forgetting to hide the
          default constructor.
        </p>

        <p>
          If you make the constructor protected you may want to consider the
          following constructor implementation technique to disallow
          instantiating subclasses:
        </p>

        <source>
public class StringUtils // not final to allow subclassing
{
    protected StringUtils() {
        // prevents calls from subclass
        throw new UnsupportedOperationException();
    }

    public static int count(char c, String s) {
        // ...
    }
}
        </source>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check:
        </p>
        <source>
&lt;module name=&quot;HideUtilityClassConstructor&quot;/&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+HideUtilityClassConstructor">
            Sun Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+HideUtilityClassConstructor">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="InnerTypeLast">
      <subsection name="Description">
        <p>
          Check nested (inner) classes/interfaces are declared at the
          bottom of the class after all method and field declarations.
        </p>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check:
        </p>
        <source>
&lt;module name=&quot;InnerTypeLast&quot;/&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+InnerTypeLast">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="InterfaceIsType">
      <subsection name="Description">
        <p>
          Implements Joshua Bloch, Effective Java, Item 17 - Use Interfaces only to
          define types.
        </p>

        <p>
          According to Bloch, an interface should describe a <em>type</em>.
          It is therefore inappropriate to define an interface that does not
          contain any methods but only constants. The Standard class <a
          href="http://docs.oracle.com/javase/8/docs/api/javax/swing/SwingConstants.html">javax.swing.SwingConstants</a>
          is an example of a class that would be flagged by this check.
        </p>

        <p>
          The check can be configured to also disallow marker interfaces like
          <code>java.io.Serializable</code>, that do not contain methods or
          constants at all.
        </p>
      </subsection>

      <subsection name="Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
          </tr>
          <tr>
            <td>allowMarkerInterfaces</td>
            <td>
              Controls whether marker interfaces like Serializable are
              allowed.
            </td>
            <td><a href="property_types.html#boolean">Boolean</a></td>
            <td><code>true</code></td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check:
        </p>
        <source>
&lt;module name=&quot;InterfaceIsType&quot;/&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+InterfaceIsType">
            Sun Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+InterfaceIsType">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="MutableException">
      <subsection name="Description">
        <p>
          Ensures that exception classes (classes with names conforming to some regular
          expression and explicitly extending classes with names conforming to other
          regular expression) are immutable, that is, that they have only final fields.
        </p>

        <p>
          The current algorithm is very simple: it checks that all members of
          exception are final.  The user can still mutate an exception's instance
          (e.g. Throwable has a method called <code>setStackTrace</code>
          which changes the exception's stack trace).  But, at least, all information
          provided by this exception type is unchangeable.
        </p>

        <p>
          Rationale: Exception instances should represent an error
          condition. Having non final fields not only allows the state to be
          modified by accident and therefore mask the original condition but
          also allows developers to accidentally forget to set the initial state.
          In both cases, code catching the exception could draw incorrect
          conclusions based on the state.
        </p>
      </subsection>

      <subsection name="Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
          </tr>
          <tr>
            <td>format</td>
            <td>pattern for exception class names</td>
            <td><a href="property_types.html#regexp">regular expression</a></td>
            <td><code>^.*Exception$|^.*Error$|^.*Throwable$</code></td>
          </tr>
          <tr>
            <td>extendedClassNameFormat</td>
            <td>pattern for extended class names</td>
            <td><a href="property_types.html#regexp">regular expression</a></td>
            <td><code>^.*Exception$|^.*Error$|^.*Throwable$</code></td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check:
        </p>
        <source>
&lt;module name=&quot;MutableException&quot;/&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MutableException">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="OneTopLevelClass">
      <subsection name="Description">
        <p>
          Checks that each top-level class, interface or
          enum resides in a source file of its own.
          Official description of a 'top-level' term:<a
          href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-7.html#jls-7.6">7.6. Top Level Type Declarations</a>.
          If file doesn't contains public class, enum or interface,
          top-level type is the first type in file.
        </p>
      </subsection>

      <subsection name="Examples">
        <p>
          An example of check's configuration:
        </p>
        <source>
&lt;module name="OneTopLevelClass"/&gt;
        </source>
        <p>
          <b>ATTENTION:</b> This Check does not support customization of validated tokens, so do not use the "tokens" property.
        </p>
        <p>
          An example of code with violations:
        </p>
        <source>
public class Foo{
    //methods
}

class Foo2{
    //methods
}
        </source>
        <p>
          An example of code without public top-level type:
        </p>
        <source>
class Foo{ // top-level class
    //methods
}

class Foo2{
    //methods
}
        </source>
        <p>
          An example of code without violations:
        </p>
        <source>
public class Foo{
    //methods
}
        </source>
      </subsection>

      <subsection name="Example of Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+OneTopLevelClass">
            Google Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+OneTopLevelClass">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="ThrowsCount">
      <subsection name="Description">
        <p>
          Restricts throws statements to a specified count (4 by default).
          Methods with "Override" or "java.lang.Override" annotation are skipped
          from validation as current class cannot change signature of these methods.
        </p>

        <p>
          Rationale: Exceptions form part of a method's interface. Declaring a
          method to throw too many differently rooted exceptions makes
          exception handling onerous and leads to poor programming practices
          such as writing code like <code>catch(Exception ex)</code>.
          4 is the empirical value which is based on reports that we had for
          the ThrowsCountCheck over big projects such as OpenJDK.
          This check also forces developers to put exceptions into a hierarchy
          such that in the simplest case, only one type of exception need be
          checked for by a caller but any subclasses can be caught specifically
          if necessary.For more information on rules for the exceptions and
          their issues, see Effective Java: Programming Language Guide
          Second Edition by Joshua Bloch pages 264-273.
        </p>

        <p>
          <b>ignorePrivateMethods</b> - allows to skip private methods as they do
          not cause problems for other classes.
        </p>
      </subsection>

      <subsection name="Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
          </tr>
          <tr>
            <td>max</td>
            <td>maximum allowed number of throws statements</td>
            <td><a href="property_types.html#integer">Integer</a></td>
            <td><code>4</code></td>
          </tr>
          <tr>
            <td>ignorePrivateMethods</td>
            <td>whether private methods must be ignored</td>
            <td><a href="property_types.html#boolean">Boolean</a></td>
            <td><code>true</code></td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check so that it doesn't allow more than two throws
          per method:
        </p>
        <source>
&lt;module name=&quot;ThrowsCount&quot;&gt;
    &lt;property name=&quot;max&quot; value=&quot;2&quot;/&gt;
&lt;/module&gt;
        </source>

        <p>
          To configure the check so that it doesn't skip private methods:
        </p>
        <source>
&lt;module name=&quot;ThrowsCount&quot;&gt;
    &lt;property name=&quot;ignorePrivateMethods&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ThrowsCount">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="VisibilityModifier">
      <subsection name="Description">
        <p>
          Checks visibility of class members. Only static final, immutable or annotated
          by specified annotation members may be public; other class members must be private
          unless the property <code>protectedAllowed</code> or <code>packageAllowed</code> is set.
        </p>

        <p>
          Public members are not flagged if the name matches the public
          member regular expression (contains <code>"^serialVersionUID$"</code> by default).
        </p>
        <p>Note that
          Checkstyle 2 used to include <code>"^f[A-Z][a-zA-Z0-9]*$"</code> in the default
          pattern to allow names used in container-managed persistence for Enterprise JavaBeans (EJB) 1.1 with the default settings.
          With EJB 2.0 it is no longer necessary to have public access
          for persistent fields, so the default has been changed.
        </p>

        <p>
          Rationale: Enforce encapsulation.
        </p>
        <p>
          Check also has options making it less strict:
        </p>
        <p>
          <b>ignoreAnnotationCanonicalNames</b> - the list of annotations which ignore variables
          in consideration. If user will provide short annotation name that type will match to any
          named the same type without consideration of package
        </p>
        <p>
          <b>allowPublicImmutableFields</b> - which allows immutable fields be declared as
          public if defined in final class. Default value is <b>true</b>
        </p>
        <p>
          Field is known to be immutable if:
          - It's declared as final
          - Has either a primitive type or instance of class user defined to be immutable
          (such as String, ImmutableCollection from Guava and etc)
        </p>
        <p>
          Classes known to be immutable are listed in <b>immutableClassCanonicalNames</b> by their
          <b>canonical</b> names.
        </p>
        <p>
          Rationale: Forcing all fields of class to have private modified by default is good
          in most cases, but in some cases it drawbacks in too much boilerplate get/set code.
          One of such cases are immutable classes.
        </p>
        <p>
          <b>Restriction</b>: Check doesn't check if class is immutable, there's no
          checking if accessory methods are missing and all fields are immutable, we only check
          <b>if current field is immutable and defined in final class</b>
        </p>
        <p>
          Star imports are out of scope of this Check. So if one of type imported via
          <b>star import</b> collides with user specified one by its short name -
          there won't be Check's violation.
        </p>
      </subsection>

      <subsection name="Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
          </tr>
          <tr>
            <td>packageAllowed</td>
            <td>whether package visible members are allowed</td>
            <td><a href="property_types.html#boolean">boolean</a></td>
            <td><code>false</code></td>
          </tr>
          <tr>
            <td>protectedAllowed</td>
            <td>whether protected members are allowed</td>
            <td><a href="property_types.html#boolean">boolean</a></td>
            <td><code>false</code></td>
          </tr>
          <tr>
            <td>publicMemberPattern</td>
            <td>pattern for public members that should be ignored</td>
            <td><a href="property_types.html#regexp">regular expression</a></td>
            <td><code>^serialVersionUID$</code></td>
          </tr>
          <tr>
            <td>allowPublicImmutableFields</td>
            <td>allows immutable fields be declared as public if defined in final class</td>
            <td><a href="property_types.html#boolean">boolean</a></td>
            <td><code>true</code></td>
          </tr>
          <tr>
            <td>immutableClassCanonicalNames</td>
            <td>immutable classes canonical names</td>
            <td><a href="property_types.html#stringSet">String Set</a></td>
            <td>java.lang.String, java.lang.Integer, java.lang.Byte, java.lang.Character,
            java.lang.Short, java.lang.Boolean, java.lang.Long, java.lang.Double, java.lang.Float,
            java.lang.StackTraceElement, java.math.BigInteger, java.math.BigDecimal, java.io.File,
            java.util.Locale, java.util.UUID, java.net.URL, java.net.URI,
            java.net.Inet4Address, java.net.Inet6Address, java.net.InetSocketAddress,</td>
          </tr>
          <tr>
            <td>ignoreAnnotationCanonicalNames</td>
            <td>ignore annotations canonical names</td>
            <td><a href="property_types.html#stringSet">String Set</a></td>
            <td>org.junit.Rule, com.google.common.annotations.VisibleForTesting</td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check:
        </p>
        <source>
&lt;module name=&quot;VisibilityModifier&quot;/&gt;
        </source>

        <p>
          To configure the check so that it allows package visible members:
        </p>
        <source>
&lt;module name=&quot;VisibilityModifier&quot;&gt;
    &lt;property name=&quot;packageAllowed&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
        </source>

        <p>
          To configure the check so that it allows no public members:
        </p>
        <source>
&lt;module name=&quot;VisibilityModifier&quot;&gt;
    &lt;property name=&quot;publicMemberPattern&quot; value=&quot;^$&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          To configure the Check so that it allows public immutable fields
          (mostly for immutable classes):
        </p>
        <source>
&lt;module name=&quot;VisibilityModifier&quot;/&gt;
        </source>
        <p>
          Example of allowed public immutable fields:
        </p>
        <source>
public class ImmutableClass
{
    public final ImmutableSet&lt;String&gt; includes; // No warning
    public final ImmutableSet&lt;String&gt; excludes; // No warning
    public final java.lang.String notes; // No warning
    public final BigDecimal value; // No warning

    public ImmutableClass(Collection&lt;String&gt; includes, Collection&lt;String&gt; excludes,
                 BigDecimal value, String notes)
    {
        this.includes = ImmutableSet.copyOf(includes);
        this.excludes = ImmutableSet.copyOf(excludes);
        this.value = value;
        this.notes = notes;
    }
}
        </source>
        <p>
          To configure the Check which allows user specified immutable class names:
        </p>
        <source>
&lt;module name=&quot;VisibilityModifier&quot;&gt;
    &lt;property name=&quot;immutableClassCanonicalNames&quot; value=&quot;
    com.google.common.collect.ImmutableSet&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          Example of allowed public immutable fields:
        </p>
        <source>
public class ImmutableClass
{
    public final ImmutableSet&lt;String&gt; includes; // No warning
    public final ImmutableSet&lt;String&gt; excludes; // No warning
    public final java.lang.String notes; // Warning here because
                                         //'java.lang.String' wasn't specified as allowed class
    public final int someValue; // No warning

    public ImmutableClass(Collection&lt;String&gt; includes, Collection&lt;String&gt; excludes,
                 String notes, int someValue)
    {
        this.includes = ImmutableSet.copyOf(includes);
        this.excludes = ImmutableSet.copyOf(excludes);
        this.value = value;
        this.notes = notes;
        this.someValue = someValue;
    }
}
        </source>

        <p>
          To configure the Check passing fields annotated with @com.annotation.CustomAnnotation:
        </p>
        <source>
&lt;module name=&quot;VisibilityModifier&quot;&gt;
  &lt;property name=&quot;ignoreAnnotationCanonicalNames&quot; value=
  &quot;com.annotation.CustomAnnotation&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          Example of allowed field:
        </p>
        <source>
class SomeClass
{
    @com.annotation.CustomAnnotation
    String annotatedString; // no warning
    @CustomAnnotation
    String shortCustomAnnotated; // no warning
}
        </source>

        <p>
          To configure the Check passing fields annotated with @org.junit.Rule and
          @com.google.common.annotations.VisibleForTesting annotations:
        </p>
        <source>
&lt;module name=&quot;VisibilityModifier&quot;/&gt;
        </source>
        <p>
          Example of allowed fields:
        </p>
        <source>
class SomeClass
{
    @org.junit.Rule
    public TemporaryFolder publicJUnitRule = new TemporaryFolder(); // no warning
    @com.google.common.annotations.VisibleForTesting
    public String testString = ""; // no warning
}
        </source>

        <p>
          To configure the Check passing fields annotated with short annotation name:
        </p>
        <source>
&lt;module name=&quot;VisibilityModifier&quot;&gt;
  &lt;property name=&quot;ignoreAnnotationCanonicalNames&quot;
  value=&quot;CustomAnnotation&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          Example of allowed fields:
        </p>
        <source>
class SomeClass
{
    @CustomAnnotation
    String customAnnotated; // no warning
    @com.annotation.CustomAnnotation
    String customAnnotated1; // no warning
    @mypackage.annotation.CustomAnnotation
    String customAnnotatedAnotherPackage; // another package but short name matches
                                          // so no violation
}
        </source>
      </subsection>

      <subsection name="Example of Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+VisibilityModifier">
            Sun Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+VisibilityModifier">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>
  </body>
</document>