-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
config_annotation.xml
1464 lines (1348 loc) · 57.6 KB
/
config_annotation.xml
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
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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 https://maven.apache.org/xsd/xdoc-2.0.xsd">
<head>
<title>Annotations</title>
</head>
<body>
<section name="Content">
<macro name="toc">
<param name="fromDepth" value="1"/>
<param name="toDepth" value="1"/>
</macro>
</section>
<section name="AnnotationLocation">
<p>Since Checkstyle 6.0</p>
<subsection name="Description" id="AnnotationLocation_Description">
<p>
Checks location of annotation on language elements.
By default, Check enforce to locate annotations immediately after documentation block
and before target element, annotation should be located on separate line from target
element. This check also verifies that the annotations are on the same indenting level as
the annotated element if they are not on the same line.
</p>
<p>
Attention: Elements that cannot have JavaDoc comments like local variables are not in the
scope of this check even though a token type like <code>VARIABLE_DEF</code> would match
them.
</p>
<p>
Attention: Annotations among modifiers are ignored (looks like false-negative)
as there might be a problem with annotations for return types:
</p>
<source>public @Nullable Long getStartTimeOrNull() { ... }</source>
<p>
Such annotations are better to keep close to type.
Due to limitations, Checkstyle can not examine the target of an annotation.
</p>
<p>
Example:
</p>
<source>
@Override
@Nullable
public String getNameIfPresent() { ... }
</source>
</subsection>
<subsection name="Properties" id="AnnotationLocation_Properties">
<div class="wrapper">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>allowSamelineMultipleAnnotations</td>
<td>Allow annotation(s) to be located on the same line as target element.</td>
<td><a href="property_types.html#boolean">boolean</a></td>
<td><code>false</code></td>
<td>6.0</td>
</tr>
<tr>
<td>allowSamelineSingleParameterlessAnnotation</td>
<td>Allow single parameterless annotation to be located on the same line as
target element.</td>
<td><a href="property_types.html#boolean">boolean</a></td>
<td><code>true</code></td>
<td>6.1</td>
</tr>
<tr>
<td>allowSamelineParameterizedAnnotation</td>
<td>Allow one and only parameterized annotation to be located on the same line as
target element.</td>
<td><a href="property_types.html#boolean">boolean</a></td>
<td><code>false</code></td>
<td>6.4</td>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>subset of tokens
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">
CLASS_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INTERFACE_DEF">
INTERFACE_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PACKAGE_DEF">
PACKAGE_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_CONSTANT_DEF">
ENUM_CONSTANT_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_DEF">
ENUM_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">
METHOD_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">
CTOR_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">
VARIABLE_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ANNOTATION_DEF">
ANNOTATION_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ANNOTATION_FIELD_DEF">
ANNOTATION_FIELD_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#RECORD_DEF">
RECORD_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#COMPACT_CTOR_DEF">
COMPACT_CTOR_DEF</a>
.
</td>
<td>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">
CLASS_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INTERFACE_DEF">
INTERFACE_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PACKAGE_DEF">
PACKAGE_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_CONSTANT_DEF">
ENUM_CONSTANT_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_DEF">
ENUM_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">
METHOD_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">
CTOR_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">
VARIABLE_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#RECORD_DEF">
RECORD_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#COMPACT_CTOR_DEF">
COMPACT_CTOR_DEF</a>
.
</td>
<td>6.0</td>
</tr>
</table>
</div>
</subsection>
<subsection name="Examples" id="AnnotationLocation_Examples">
<p>
To configure the default check to allow one single parameterless annotation on the same
line:
</p>
<source>
<module name="AnnotationLocation"/>
</source>
<p>
Example for above configuration:
</p>
<source>
@NotNull private boolean field1; //ok
@Override public int hashCode() { return 1; } //ok
@NotNull //ok
private boolean field2;
@Override //ok
public boolean equals(Object obj) { return true; }
@Mock DataLoader loader; //ok
@SuppressWarnings("deprecation") DataLoader loader; //violation
@SuppressWarnings("deprecation") public int foo() { return 1; } //violation
@NotNull @Mock DataLoader loader; //violation
</source>
<p>
Use the following configuration to allow multiple annotations on the same line:
</p>
<source>
<module name="AnnotationLocation">
<property name="allowSamelineMultipleAnnotations" value="true"/>
<property name="allowSamelineSingleParameterlessAnnotation"
value="false"/>
<property name="allowSamelineParameterizedAnnotation" value="false"/>
</module>
</source>
<p>
Example to allow any location multiple annotations:
</p>
<source>
@NotNull private boolean field1; //ok
@Override public int hashCode() { return 1; } //ok
@NotNull //ok
private boolean field2;
@Override //ok
public boolean equals(Object obj) { return true; }
@Mock DataLoader loader; //ok
@SuppressWarnings("deprecation") DataLoader loader; //ok
@SuppressWarnings("deprecation") public int foo() { return 1; } //ok
@NotNull @Mock DataLoader loader; //ok
</source>
<p>
Use the following configuration to allow only one and only parameterized annotation
on the same line:
</p>
<source>
<module name="AnnotationLocation">
<property name="allowSamelineMultipleAnnotations" value="false"/>
<property name="allowSamelineSingleParameterlessAnnotation"
value="false"/>
<property name="allowSamelineParameterizedAnnotation" value="true"/>
</module>
</source>
<p>
Example to allow only one and only parameterized annotation on the same line:
</p>
<source>
@NotNull private boolean field1; //violation
@Override public int hashCode() { return 1; } //violation
@NotNull //ok
private boolean field2;
@Override //ok
public boolean equals(Object obj) { return true; }
@Mock DataLoader loader; //violation
@SuppressWarnings("deprecation") DataLoader loader; //ok
@SuppressWarnings("deprecation") public int foo() { return 1; } //ok
@NotNull @Mock DataLoader loader; //violation
</source>
<p>
Use the following configuration to only validate annotations on methods to allow one
single parameterless annotation on the same line:
</p>
<source>
<module name="AnnotationLocation">
<property name="tokens" value="METHOD_DEF"/>
<property name="allowSamelineMultipleAnnotations" value="false"/>
<property name="allowSamelineSingleParameterlessAnnotation"
value="true"/>
<property name="allowSamelineParameterizedAnnotation" value="false"/>
</module>
</source>
<p>
Example for above configuration to check only methods:
</p>
<source>
@NotNull private boolean field1; //ok
@Override public int hashCode() { return 1; } //ok
@NotNull //ok
private boolean field2;
@Override //ok
public boolean equals(Object obj) { return true; }
@Mock DataLoader loader; //ok
@SuppressWarnings("deprecation") DataLoader loader; //ok
@SuppressWarnings("deprecation") public int foo() { return 1; } //violation
@NotNull @Mock DataLoader loader; //ok
</source>
</subsection>
<subsection name="Example of Usage" id="AnnotationLocation_Example_of_Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+AnnotationLocation">
Google Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+AnnotationLocation">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Violation Messages" id="AnnotationLocation_Violation_Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fannotation+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22annotation.location%22">
annotation.location</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fannotation+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22annotation.location.alone%22">
annotation.location.alone</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package" id="AnnotationLocation_Package">
<p> com.puppycrawl.tools.checkstyle.checks.annotation </p>
</subsection>
<subsection name="Parent Module" id="AnnotationLocation_Parent_Module">
<p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
</subsection>
</section>
<section name="AnnotationOnSameLine">
<p>Since Checkstyle 8.2</p>
<subsection name="Description" id="AnnotationOnSameLine_Description">
<p>
Checks that annotations are located on the same line with their targets.
Verifying with this check is not good practice, but it is using by some style guides.
</p>
</subsection>
<subsection name="Properties" id="AnnotationOnSameLine_Properties">
<div class="wrapper">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>subset of tokens
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">
CLASS_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INTERFACE_DEF">
INTERFACE_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_DEF">
ENUM_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">
METHOD_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">
CTOR_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">
VARIABLE_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PARAMETER_DEF">
PARAMETER_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ANNOTATION_DEF">
ANNOTATION_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#TYPECAST">
TYPECAST</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_THROWS">
LITERAL_THROWS</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#IMPLEMENTS_CLAUSE">
IMPLEMENTS_CLAUSE</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#TYPE_ARGUMENT">
TYPE_ARGUMENT</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_NEW">
LITERAL_NEW</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#DOT">
DOT</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ANNOTATION_FIELD_DEF">
ANNOTATION_FIELD_DEF</a>
,<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#RECORD_DEF">
RECORD_DEF</a>
,<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#COMPACT_CTOR_DEF">
COMPACT_CTOR_DEF</a>
.
</td>
<td>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">
CLASS_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INTERFACE_DEF">
INTERFACE_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_DEF">
ENUM_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">
METHOD_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">
CTOR_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">
VARIABLE_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#RECORD_DEF">
RECORD_DEF</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#COMPACT_CTOR_DEF">
COMPACT_CTOR_DEF</a>
.
</td>
<td>8.2</td>
</tr>
</table>
</div>
</subsection>
<subsection name="Examples" id="AnnotationOnSameLine_Examples">
<p>
To configure the check:
</p>
<source>
<module name="AnnotationOnSameLine"/>
</source>
<p>
Example:
</p>
<source>
class Foo {
@SuppressWarnings("deprecation") // violation, annotation should be on the same line
public Foo() {
}
@SuppressWarnings("unchecked") public void fun2() { // OK
}
}
@SuppressWarnings("unchecked") class Bar extends Foo { // OK
@Deprecated public Bar() { // OK
}
@Override // violation, annotation should be on the same line
public void fun1() {
}
@Before @Override public void fun2() { // OK
}
@SuppressWarnings("deprecation") // violation, annotation should be on the same line
@Before public void fun3() {
}
}
</source>
<p>
To configure the check to check for annotations applied on
interfaces, variables and constructors:
</p>
<source>
<module name="AnnotationOnSameLine">
<property name="tokens"
value="INTERFACE_DEF, VARIABLE_DEF, CTOR_DEF"/>
</module>
</source>
<p>
Example:
</p>
<source>
@Deprecated interface Foo { // OK
void doSomething();
}
class Bar implements Foo {
@SuppressWarnings("deprecation") // violation, annotation should be on the same line
public Bar() {
}
@Override // OK
public void doSomething() {
}
@Nullable // violation, annotation should be on the same line
String s;
}
</source>
</subsection>
<subsection name="Example of Usage" id="AnnotationOnSameLine_Example_of_Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+AnnotationOnSameLine">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Violation Messages" id="AnnotationOnSameLine_Violation_Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fannotation+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22annotation.same.line%22">
annotation.same.line</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package" id="AnnotationOnSameLine_Package">
<p> com.puppycrawl.tools.checkstyle.checks.annotation </p>
</subsection>
<subsection name="Parent Module" id="AnnotationOnSameLine_Parent_Module">
<p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
</subsection>
</section>
<section name="AnnotationUseStyle">
<p>Since Checkstyle 5.0</p>
<subsection name="Description" id="AnnotationUseStyle_Description">
<p>
Checks the style of elements in annotations.
</p>
<p>
Annotations have three element styles starting with the least verbose.
</p>
<ul>
<li><code>ElementStyleOption.COMPACT_NO_ARRAY</code></li>
<li><code>ElementStyleOption.COMPACT</code></li>
<li><code>ElementStyleOption.EXPANDED</code></li>
</ul>
<p>
To not enforce an element style a <code>ElementStyleOption.IGNORE</code> type is provided.
The desired style can be set through the <code>elementStyle</code> property.
</p>
<p>
Using the <code>ElementStyleOption.EXPANDED</code> style is more verbose.
The expanded version is sometimes referred to as "named parameters" in other languages.
</p>
<p>
Using the <code>ElementStyleOption.COMPACT</code> style is less verbose.
This style can only be used when there is an element called 'value' which is either
the sole element or all other elements have default values.
</p>
<p>
Using the <code>ElementStyleOption.COMPACT_NO_ARRAY</code> style is less verbose.
It is similar to the <code>ElementStyleOption.COMPACT</code> style but single value arrays
are flagged.
With annotations a single value array does not need to be placed in an array initializer.
</p>
<p>
The ending parenthesis are optional when using annotations with no elements.
To always require ending parenthesis use the <code>ClosingParensOption.ALWAYS</code> type.
To never have ending parenthesis use the <code>ClosingParensOption.NEVER</code> type.
To not enforce a closing parenthesis preference a <code>ClosingParensOption.IGNORE</code>
type is provided. Set this through the <code>closingParens</code> property.
</p>
<p>
Annotations also allow you to specify arrays of elements in a standard format.
As with normal arrays, a trailing comma is optional.
To always require a trailing comma use the <code>TrailingArrayCommaOption.ALWAYS</code>
type.
To never have a trailing comma use the <code>TrailingArrayCommaOption.NEVER</code> type.
To not enforce a trailing array comma preference a
<code>TrailingArrayCommaOption.IGNORE</code> type is provided.
Set this through the <code>trailingArrayComma</code> property.
</p>
<p>
By default, the <code>ElementStyleOption</code> is set to <code>COMPACT_NO_ARRAY</code>,
the <code>TrailingArrayCommaOption</code> is set to <code>NEVER</code>,
and the <code>ClosingParensOption</code> is set to <code>NEVER</code>.
</p>
<p>
According to the JLS, it is legal to include a trailing comma
in arrays used in annotations but Sun's Java 5 & 6 compilers will not
compile with this syntax. This may in be a bug in Sun's compilers
since eclipse 3.4's built-in compiler does allow this syntax as
defined in the JLS. Note: this was tested with compilers included with
JDK versions 1.5.0.17 and 1.6.0.11 and the compiler included with eclipse 3.4.1.
</p>
<p>
See <a href="https://docs.oracle.com/javase/specs/jls/se11/html/jls-9.html#jls-9.7">
Java Language specification, §9.7</a>.
</p>
</subsection>
<subsection name="Properties" id="AnnotationUseStyle_Properties">
<div class="wrapper">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>elementStyle</td>
<td>
Define the annotation element styles.
</td>
<td>
<a href="property_types.html#ElementStyleOption">ElementStyleOption</a>
</td>
<td>
<code>compact_no_array</code>
</td>
<td>5.0</td>
</tr>
<tr>
<td>closingParens</td>
<td>
Define the policy for ending parenthesis.
</td>
<td>
<a href="property_types.html#ClosingParensOption">ClosingParensOption</a>
</td>
<td>
<code>never</code>
</td>
<td>5.0</td>
</tr>
<tr>
<td>trailingArrayComma</td>
<td>
Define the policy for trailing comma in arrays.
</td>
<td>
<a href="property_types.html#TrailingArrayCommaOption">TrailingArrayCommaOption</a>
</td>
<td>
<code>never</code>
</td>
<td>5.0</td>
</tr>
</table>
</div>
</subsection>
<subsection name="Examples" id="AnnotationUseStyle_Examples">
<p> To configure the check:</p>
<source>
<module name="AnnotationUseStyle"/>
</source>
<p>
Example:
</p>
<source>
@Deprecated // OK
@SomeArrays(pooches={DOGS.LEO}) // Violation - COMPACT_NO_ARRAY
@SuppressWarnings({""}) // Violation - COMPACT_NO_ARRAY
public class TestOne
{
}
@SomeArrays(pooches={DOGS.LEO}, um={}, test={"bleh"}) // Violation - COMPACT_NO_ARRAY
@SuppressWarnings("") // OK
@Deprecated() // Violation - cannot have closing parenthesis
class TestTwo {
}
</source>
<p>
To configure the check to enforce an <code>expanded</code> style,
with a trailing array comma set to <code>never</code>
and always including the closing parenthesis.
</p>
<source>
<module name="AnnotationUseStyle">
<property name="elementStyle" value="expanded"/>
<property name="trailingArrayComma" value="never"/>
<property name="closingParens" value="always"/>
</module>
</source>
<p>
Example:
</p>
<source>
@Deprecated // Violation - must have closing parenthesis
@SomeArrays(pooches={DOGS.LEO}) // OK
@SuppressWarnings({""}) // Violation - EXPANDED
public class TestOne
{
}
@SomeArrays(pooches={DOGS.LEO}, um={}, test={"bleh"}) // OK
@SuppressWarnings("") // Violation - EXPANDED
@Deprecated() // OK
class TestTwo {
}
</source>
</subsection>
<subsection name="Example of Usage" id="AnnotationUseStyle_Example_of_Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+AnnotationUseStyle">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Violation Messages" id="AnnotationUseStyle_Violation_Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fannotation+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22annotation.incorrect.style%22">
annotation.incorrect.style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fannotation+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22annotation.parens.missing%22">
annotation.parens.missing</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fannotation+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22annotation.parens.present%22">
annotation.parens.present</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fannotation+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22annotation.trailing.comma.missing%22">
annotation.trailing.comma.missing</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fannotation+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22annotation.trailing.comma.present%22">
annotation.trailing.comma.present</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package" id="AnnotationUseStyle_Package">
<p> com.puppycrawl.tools.checkstyle.checks.annotation </p>
</subsection>
<subsection name="Parent Module" id="AnnotationUseStyle_Parent_Module">
<p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
</subsection>
</section>
<section name="MissingDeprecated">
<p>Since Checkstyle 5.0</p>
<subsection name="Description" id="MissingDeprecated_Description">
<p>
Verifies that the annotation <code>@Deprecated</code> and the Javadoc tag
<code>@deprecated</code> are both present when either of them is present.
</p>
<p>
Both ways of flagging deprecation serve their own purpose.
The @Deprecated annotation is used for compilers and development tools.
The @deprecated javadoc tag is used to document why something is deprecated
and what, if any, alternatives exist.
</p>
<p>
In order to properly mark something as deprecated both forms of
deprecation should be present.
</p>
<p>
Package deprecation is an exception to the rule of always using the
javadoc tag and annotation to deprecate. It is not clear if the
javadoc tool will support it or not as newer versions keep flip-flopping
on if it is supported or will cause an error.
See <a href="https://bugs.openjdk.org/browse/JDK-8160601">
JDK-8160601</a>.
The deprecated javadoc tag is currently the only way to say why the package
is deprecated and what to use instead. Until this is resolved, if you
don't want to print violations on package-info, you can use a
<a href="config_filters.html">filter</a> to ignore these files until
the javadoc tool faithfully supports it. An example config using
SuppressionSingleFilter is:
</p>
<source>
<!-- required till https://bugs.openjdk.org/browse/JDK-8160601 -->
<module name="SuppressionSingleFilter">
<property name="checks" value="MissingDeprecatedCheck"/>
<property name="files" value="package-info\.java"/>
</module>
</source>
</subsection>
<subsection name="Properties" id="MissingDeprecated_Properties">
<div class="wrapper">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>violateExecutionOnNonTightHtml</td>
<td>
Control when to print violations if the Javadoc being examined by this check
violates the tight html rules defined at
<a href="writingjavadocchecks.html#Tight-HTML_rules">Tight-HTML Rules</a>.
</td>
<td><a href="property_types.html#boolean">boolean</a></td>
<td><code>false</code></td>
<td>8.24</td>
</tr>
</table>
</div>
</subsection>
<subsection name="Examples" id="MissingDeprecated_Examples">
<p> To configure the check:</p>
<source>
<module name="MissingDeprecated"/>
</source>
<p>Example:</p>
<source>
@Deprecated
public static final int MY_CONST = 13; // ok
/** This javadoc is missing deprecated tag. */
@Deprecated
public static final int COUNTER = 10; // violation
/**
* @deprecated
* <p></p>
*/
@Deprecated
public static final int NUM = 123456; // ok
/**
* @deprecated
* <p>
*/
@Deprecated
public static final int CONST = 12; // ok
</source>
<p>
To configure the check such that it prints violation
messages if tight HTML rules are not obeyed
</p>
<source>
<module name="MissingDeprecated">
<property name="violateExecutionOnNonTightHtml" value="true"/>
</module>
</source>
<p>
Example:
</p>
<source>
@Deprecated
public static final int MY_CONST = 13; // ok
/** This javadoc is missing deprecated tag. */
@Deprecated
public static final int COUNTER = 10; // violation
/**
* @deprecated
* <p></p>
*/
@Deprecated
public static final int NUM = 123456; // ok
/**
* @deprecated
* <p>
*/
@Deprecated
public static final int CONST = 12; // violation, tight HTML rules not obeyed
</source>
</subsection>
<subsection name="Example of Usage" id="MissingDeprecated_Example_of_Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MissingDeprecated">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Violation Messages" id="MissingDeprecated_Violation_Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fannotation+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22annotation.missing.deprecated%22">
annotation.missing.deprecated</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fannotation+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22javadoc.duplicateTag%22">
javadoc.duplicateTag</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fannotation+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22javadoc.missed.html.close%22">
javadoc.missed.html.close</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fannotation+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22javadoc.parse.rule.error%22">
javadoc.parse.rule.error</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fannotation+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22javadoc.wrong.singleton.html.tag%22">
javadoc.wrong.singleton.html.tag</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package" id="MissingDeprecated_Package">
<p> com.puppycrawl.tools.checkstyle.checks.annotation </p>
</subsection>
<subsection name="Parent Module" id="MissingDeprecated_Parent_Module">
<p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
</subsection>
</section>
<section name="MissingOverride">
<p>Since Checkstyle 5.0</p>
<subsection name="Description" id="MissingOverride_Description">
<p>
Verifies that the <code>@Override</code> annotation is present
when the <code>@inheritDoc</code> javadoc tag is present.
</p>
<p>
Rationale: The @Override annotation helps
compiler tools ensure that an override is actually occurring. It is
quite easy to accidentally overload a method or hide a static method
and using the @Override annotation points out these problems.
</p>
<p>
This check will log a violation if using the @inheritDoc tag on a method that
is not valid (ex: private, or static method).
</p>
<p>
There is a slight difference between the @Override annotation in Java 5 versus
Java 6 and above. In Java 5, any method overridden from an interface cannot
be annotated with @Override. In Java 6 this behavior is allowed.
</p>
<p>
As a result of the aforementioned difference between Java 5 and Java 6, a
property called <code>javaFiveCompatibility</code> is available. This
property will only check classes, interfaces, etc. that do not contain the
extends or implements keyword or are not anonymous classes. This means it
only checks methods overridden from <code>java.lang.Object</code>.
<b>Java 5 Compatibility mode severely limits this check. It is recommended to
only use it on Java 5 source.</b>
</p>
</subsection>
<subsection name="Properties" id="MissingOverride_Properties">
<div class="wrapper">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>javaFiveCompatibility</td>
<td>
Enable java 5 compatibility mode.
</td>
<td>
<a href="property_types.html#boolean">boolean</a>
</td>
<td>
<code>false</code>
</td>
<td>5.0</td>
</tr>
</table>
</div>
</subsection>
<subsection name="Examples" id="MissingOverride_Examples">
<p> To configure the check:</p>
<source>
<module name="MissingOverride"/>
</source>
<p>Example:</p>
<source>
class Test extends SuperClass {
/** {@inheritDoc} */
@Override
public void test1() { // OK
}
/** {@inheritDoc} */
public void test2() { // violation, should be annotated with @Override
}
/** {@inheritDoc} */
private void test3() { // violation, using the @inheritDoc tag on private method
}
/** {@inheritDoc} */
public static void test4() { // violation, using the @inheritDoc tag on static method
}
}
</source>
<p>
To configure the check for the <code>javaFiveCompatibility</code>
mode:
</p>
<source>
<module name="MissingOverride">
<property name="javaFiveCompatibility"
value="true"/>
</module>
</source>
<p>Example:</p>
<source>
class Test1 {
/** {@inheritDoc} */
public void equals() { // violation, should be annotated with @Override
}
}
interface Test2 {
/** {@inheritDoc} */
void test(); // violation, should be annotated with @Override
}
class Test3 extends SuperClass {
/** {@inheritDoc} */
public void test() { // OK, is ignored because class extends other class