-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsuppressionxpathsinglefilter.html
793 lines (675 loc) · 31.4 KB
/
suppressionxpathsinglefilter.html
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
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 2.0.0 from src/site/xdoc/filters/suppressionxpathsinglefilter.xml at 2025-04-02
| Rendered using Apache Maven Fluido Skin 2.0.1
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="Apache Maven Doxia Site Renderer 2.0.0" />
<title>SuppressionXpathSingleFilter – checkstyle</title>
<link rel="stylesheet" href="../css/apache-maven-fluido-2.0.1.min.css" />
<link rel="stylesheet" href="../css/site.css" />
<link rel="stylesheet" href="../css/print.css" media="print" />
<script src="../js/apache-maven-fluido-2.0.1.min.js"></script>
<script type="text/javascript" src="../js/checkstyle.js"></script>
<script type="text/javascript" src="../js/anchors.js"></script>
<script type="text/javascript" src="../js/google-analytics.js"></script>
<script type="text/javascript" src="../js/copy-clipboard.js"></script>
<link rel="icon" href="../images/favicon.png" type="image/x-icon" />
<link rel="shortcut icon" href="../images/favicon.ico" type="image/ico" />
</head>
<body>
<div class="container-fluid container-fluid-top">
<header>
<div id="banner">
<div class="pull-left"><div id="bannerLeft"><h1><a href=".././"><img class="class java.lang.Object" src="../images/header-checkstyle-logo.png" alt="Checkstyle" /></a></h1></div></div>
<div class="pull-right"><div id="bannerRight"><h1><img class="class java.lang.Object" src="../images/header-right-ruller.png" alt="Checkstyle" /></h1></div></div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate" class="pull-right"><span class="divider">|</span> Last Published: 2025-04-02</li>
<li id="projectVersion" class="pull-right"><span class="divider">|</span>Version: 10.23.0</li>
<li class="pull-right"><a>toTop</a></li>
</ul>
</div>
</header>
<div class="row-fluid">
<header id="leftColumn" class="span2">
<nav class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">About</li>
<li><a href="../index.html">Checkstyle</a></li>
<li><a href="../releasenotes.html">Release Notes</a></li>
<li><a href="../consulting.html">Consulting</a></li>
<li><a href="../sponsoring.html">Sponsoring</a></li>
<li class="nav-header">Documentation</li>
<li><a href="../config.html"><span class="icon-chevron-down"></span>Configuration</a>
<ul class="nav nav-list">
<li><a href="../property_types.html">Property Types</a></li>
<li><a href="../config_system_properties.html">System Properties</a></li>
</ul></li>
<li><a href="../running.html"><span class="icon-chevron-down"></span>Running</a>
<ul class="nav nav-list">
<li><a href="../anttask.html">Ant Task</a></li>
<li><a href="../cmdline.html">Command Line</a></li>
</ul></li>
<li><a href="../checks.html"><span class="icon-chevron-down"></span>Checks</a>
<ul class="nav nav-list">
<li><a href="../checks/annotation/index.html"><span class="icon-chevron-right"></span>Annotations</a></li>
<li><a href="../checks/blocks/index.html"><span class="icon-chevron-right"></span>Block Checks</a></li>
<li><a href="../checks/design/index.html"><span class="icon-chevron-right"></span>Class Design</a></li>
<li><a href="../checks/coding/index.html"><span class="icon-chevron-right"></span>Coding</a></li>
<li><a href="../checks/header/index.html"><span class="icon-chevron-right"></span>Headers</a></li>
<li><a href="../checks/imports/index.html"><span class="icon-chevron-right"></span>Imports</a></li>
<li><a href="../checks/javadoc/index.html"><span class="icon-chevron-right"></span>Javadoc Comments</a></li>
<li><a href="../checks/metrics/index.html"><span class="icon-chevron-right"></span>Metrics</a></li>
<li><a href="../checks/misc/index.html"><span class="icon-chevron-right"></span>Miscellaneous</a></li>
<li><a href="../checks/modifier/index.html"><span class="icon-chevron-right"></span>Modifiers</a></li>
<li><a href="../checks/naming/index.html"><span class="icon-chevron-right"></span>Naming Conventions</a></li>
<li><a href="../checks/regexp/index.html"><span class="icon-chevron-right"></span>Regexp</a></li>
<li><a href="../checks/sizes/index.html"><span class="icon-chevron-right"></span>Size Violations</a></li>
<li><a href="../checks/whitespace/index.html"><span class="icon-chevron-right"></span>Whitespace</a></li>
</ul></li>
<li><a href="../filters/index.html"><span class="icon-chevron-down"></span>Filters</a>
<ul class="nav nav-list">
<li><a href="../filters/severitymatchfilter.html">SeverityMatchFilter</a></li>
<li><a href="../filters/suppresswarningsfilter.html">SuppressWarningsFilter</a></li>
<li><a href="../filters/suppresswithnearbycommentfilter.html">SuppressWithNearbyCommentFilter</a></li>
<li><a href="../filters/suppresswithnearbytextfilter.html">SuppressWithNearbyTextFilter</a></li>
<li><a href="../filters/suppresswithplaintextcommentfilter.html">SuppressWithPlainTextCommentFilter</a></li>
<li><a href="../filters/suppressioncommentfilter.html">SuppressionCommentFilter</a></li>
<li><a href="../filters/suppressionfilter.html">SuppressionFilter</a></li>
<li><a href="../filters/suppressionsinglefilter.html">SuppressionSingleFilter</a></li>
<li><a href="../filters/suppressionxpathfilter.html">SuppressionXpathFilter</a></li>
<li class="active"><a>SuppressionXpathSingleFilter</a></li>
</ul></li>
<li><a href="../filefilters/index.html"><span class="icon-chevron-right"></span>File Filters</a></li>
<li><a href="../style_configs.html"><span class="icon-chevron-down"></span>Style Configurations</a>
<ul class="nav nav-list">
<li><a href="../google_style.html">Google's Style</a></li>
<li><a href="../sun_style.html">Sun's Style</a></li>
</ul></li>
<li class="nav-header">Developers</li>
<li><a href="../extending.html"><span class="icon-chevron-down"></span>Extending Checkstyle</a>
<ul class="nav nav-list">
<li><a href="../writingchecks.html">Writing Checks</a></li>
<li><a href="../writingjavadocchecks.html">Writing Javadoc Checks</a></li>
<li><a href="../writingfilters.html">Writing Filters</a></li>
<li><a href="../writingfilefilters.html">Writing File Filters</a></li>
<li><a href="../writinglisteners.html">Writing Listeners</a></li>
</ul></li>
<li><a href="../contributing.html">Contributing</a></li>
<li><a href="../beginning_development.html"><span class="icon-chevron-down"></span>Beginning Development</a>
<ul class="nav nav-list">
<li><a href="../eclipse.html">Eclipse IDE</a></li>
<li><a href="../netbeans.html">NetBeans IDE</a></li>
<li><a href="../idea.html">IntelliJ IDE</a></li>
</ul></li>
<li><a href="../apidocs/index.html">Javadoc</a></li>
<li class="nav-header">Project Documentation</li>
<li><a href="../project-info.html"><span class="icon-chevron-right"></span>Project Information</a></li>
<li><a href="../project-reports.html"><span class="icon-chevron-right"></span>Project Reports</a></li>
</ul>
</nav>
<div class="well sidebar-nav">
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<a href="https://github.com/checkstyle/checkstyle" class="builtBy"><img class="builtBy" src="../images/github_logo_social_coding_outlined.png" alt="GitHub" /></a>
<a href="https://twitter.com/checkstyle_java/" class="builtBy"><img class="builtBy" src="../images/twitter_button.png" alt="Twitter" /></a>
<a href="https://stackoverflow.com/questions/tagged/checkstyle" class="builtBy"><img class="builtBy" src="../images/stackoverflow.jpeg" alt="Stackoverflow" /></a>
<a href="https://groups.google.com/forum/#!forum/checkstyle" class="builtBy"><img class="builtBy" src="../images/groups.png" alt="GoogleGroups" /></a>
<a href="https://www.ej-technologies.com/products/jprofiler/overview.html" class="builtBy"><img class="builtBy" src="https://www.ej-technologies.com/images/product_banners/jprofiler_medium.png" alt="JProfiler" /></a>
</div>
</div>
</header>
<main id="bodyColumn" class="span10">
<section><a id="SuppressionXpathSingleFilter"></a>
<h1>SuppressionXpathSingleFilter</h1>
<p>Since Checkstyle 8.18</p>
<a id="Description"></a><section id="Description"><a id="Description"></a>
<h2>Description</h2>
<div>
Filter <code>SuppressionXpathSingleFilter</code> suppresses audit events for
Checks violations in the specified file, class, checks, message, module id,
and xpath.
</div>
<p>
Rationale: To allow users to use suppressions configured in the same config as other
modules. <code>SuppressionFilter</code> and <code>SuppressionXpathFilter</code> require
a separate file.
</p>
<p>
Advice: If checkstyle configuration is used for several projects, single suppressions
on common files/folders is better to put in checkstyle configuration as common rule.
All suppression that are for specific file names is better to keep in project specific
config file.
</p>
<p>
Attention: This filter only supports single suppression, and will need
multiple instances if users wants to suppress multiple violations.
</p>
</section>
<a id="Notes"></a><section id="Notes"><a id="Notes"></a>
<h2>Notes</h2>
<p>
<code>SuppressionXpathSingleFilter</code> can suppress Checks that have
<code>Treewalker</code> as parent module.
</p>
</section>
<a id="Properties"></a><section id="Properties"><a id="Properties"></a>
<h2>Properties</h2>
<div class="wrapper">
<table class="table table-striped">
<tr class="a">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr class="b">
<td>checks</td>
<td>Define a Regular Expression matched against the name of the check associated with an audit event.</td>
<td><a href="../property_types.html#Pattern">Pattern</a></td>
<td><code>null</code></td>
<td>8.18</td>
</tr>
<tr class="a">
<td>files</td>
<td>Define a Regular Expression matched against the file name associated with an audit event.</td>
<td><a href="../property_types.html#Pattern">Pattern</a></td>
<td><code>null</code></td>
<td>8.18</td>
</tr>
<tr class="b">
<td>id</td>
<td>Define a string matched against the ID of the check associated with an audit event.</td>
<td><a href="../property_types.html#String">String</a></td>
<td><code>null</code></td>
<td>8.18</td>
</tr>
<tr class="a">
<td>message</td>
<td>Define a Regular Expression matched against the message of the check associated with an audit event.</td>
<td><a href="../property_types.html#Pattern">Pattern</a></td>
<td><code>null</code></td>
<td>8.18</td>
</tr>
<tr class="b">
<td>query</td>
<td>Define a string xpath query.</td>
<td><a href="../property_types.html#String">String</a></td>
<td><code>null</code></td>
<td>8.18</td>
</tr>
</table>
</div>
</section>
<a id="Examples"></a><section id="Examples"><a id="Examples"></a>
<h2>Examples</h2>
<p id="Example1-config">
To configure to suppress the MethodName check
for all methods with name MyMethod
inside Example1 and Example3 files:
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="MethodName"/>
<module name="SuppressionXpathSingleFilter">
<property name="files" value="Example(1|3)\.java"/>
<property name="checks" value="MethodName"/>
<property name="query" value="(//CLASS_DEF[./IDENT[@text='Example1']]
/OBJBLOCK/METHOD_DEF/IDENT[@text='MyMethod'])|
(//CLASS_DEF[./IDENT[@text='Example3']]/OBJBLOCK
/METHOD_DEF/IDENT[@text='MyMethod'])"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example1-code">Code example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
public class Example1 {
public void MyMethod() {}
// filtered violation above 'Name 'MyMethod' must match pattern'
}
</code></pre></div>
<p id="Example2-config">
To suppress MethodName check for method names matched pattern 'MyMethod[0-9]':
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="MethodName"/>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="MethodName"/>
<property name="message" value="MyMethod[0-9]"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example2-code">Code Example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
public class Example2 {
// filtered violation below 'Name 'MyMethod1' must match pattern'
public void MyMethod1() {}
// filtered violation below 'Name 'MyMethod2' must match pattern'
public void MyMethod2() {}
// violation below 'Name 'MyMethodA' must match pattern'
public void MyMethodA() {}
}
</code></pre></div>
<p id="Example3-config">
To suppress checks being specified by id property:
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="MethodName">
<property name="id" value="MethodName1"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="files" value="Example3\.java"/>
<property name="id" value="MethodName1"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example3-code">Code example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
public class Example3 {
// filtered violation below 'Name 'MyMethod' must match pattern'
public void MyMethod() {}
}
</code></pre></div>
<p id="Example4-config">
To suppress checks for all package definitions:
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="PackageName">
<property name="format"
value="^[A-Z]+(\.[A-Z]*)*$"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="PackageName"/>
<property name="query" value="(//PACKAGE_DEF[.//IDENT
[@text='suppressionxpathsinglefilter']])
//IDENT[not(preceding::IDENT)]"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example4-code">Code example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
package com.puppycrawl.tools.checkstyle.filters.suppressionxpathsinglefilter;
// filtered violation above 'must match pattern'
public class Example4 {}
</code></pre></div>
<p id="Example5-config">
To suppress RedundantModifier check for interface definitions:
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="RedundantModifier"/>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="RedundantModifier"/>
<property name="query" value="//INTERFACE_DEF//*"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example5-code">Code Example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
public interface Example5 {
public int CONSTANT1 = 1; // filtered violation 'Redundant 'public' modifier.'
}
</code></pre></div>
<p id="Example6-config">
To suppress checks in the Example6 file by non-query:
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="MagicNumber"/>
<module name="SuppressionXpathSingleFilter">
<property name="files" value="Example6"/>
<property name="checks" value="MagicNumber"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example6-code">Code example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
public class Example6 {
private int field = 177; // filtered violation ''177' is a magic number.'
}
</code></pre></div>
<p id="Example7-config">
Suppress checks for elements which are either class definitions,
or method definitions:
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="AbstractClassName"/>
<module name="MethodName"/>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value=".*"/>
<property name="query"
value="(//CLASS_DEF[./IDENT[@text='Example7']])|
(//CLASS_DEF[./IDENT[@text='Example7']]/OBJBLOCK/METHOD_DEF
/IDENT[@text='MyMethod'])"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example7-code">Code example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
// filtered violation below 'Name 'Example7' must match pattern'
abstract class Example7 {
public void MyMethod() {}
// filtered violation above 'Name 'MyMethod' must match pattern'
}
// violation below, 'Name 'AnotherClass' must match pattern'
abstract class AnotherClass {
public void MyMethod() {}
// violation above, 'Name 'MyMethod' must match pattern'
}
</code></pre></div>
<p id="Example8-config">
Suppress checks for MyMethod1 or MyMethod2 methods:
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="MethodName"/>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="MethodName"/>
<property name="query" value="//CLASS_DEF[./IDENT[@text='Example8']]/OBJBLOCK/
METHOD_DEF/IDENT[@text='MyMethod1' or @text='MyMethod2']"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example8-code">Code example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
class Example8 {
// filtered violation below 'Name 'MyMethod1' must match pattern'
public void MyMethod1() {}
// filtered violation below 'Name 'MyMethod2' must match pattern'
public void MyMethod2() {}
// violation below, 'Name 'MyMethod3' must match pattern'
public void MyMethod3() {}
}
</code></pre></div>
<p id="Example9-config">
Suppress checks for variable testVariable1 inside
testMethod method inside Example9 class:
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="LocalFinalVariableName">
<property name="format" value="^[A-Z][A-Z0-9]*$"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="LocalFinalVariableName"/>
<property name="query" value="//CLASS_DEF[./IDENT[@text='Example9']]/OBJBLOCK
/METHOD_DEF[./IDENT[@text='testMethod']]/SLIST
/VARIABLE_DEF/IDENT[@text='testVariable1']"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example9-code">Code Example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
public class Example9 {
public void testMethod() {
// filtered violation below 'Name 'testVariable1' must match pattern'
final int testVariable1 = 10;
// violation below, 'Name 'testVariable2' must match pattern'
final int testVariable2 = 10;
}
}
</code></pre></div>
<p id="Example10-config">
In the following sample, violations for LeftCurly check
will be suppressed for methods with name testMethod1 inside
Example10 file.
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="LeftCurly"/>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="LeftCurly"/>
<property name="query" value="//CLASS_DEF[./IDENT[@text='Example10']]/OBJBLOCK
/METHOD_DEF[./IDENT[@text='testMethod1']]/SLIST"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example10-code">Code Example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
public class Example10 {
public void testMethod1()
{ // filtered violation ''{' at column 3 should be on the previous line.'
}
public void testMethod2()
{ // violation, ''{' at column 3 should be on the previous line.'
}
}
</code></pre></div>
<p id="Example11-config">
The following example demonstrates how to suppress
RequireThis violations for variable age inside changeAge method.
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="RequireThis">
<property name="validateOnlyOverlapping" value="false"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="RequireThis"/>
<property name="query" value="//CLASS_DEF[./IDENT[@text='Example11']]
//METHOD_DEF[./IDENT[@text='changeAge']]//ASSIGN/IDENT[@text='age']"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example11-code">Code Example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
public class Example11 {
private int age = 23;
private int number = 100;
public void changeAge() {
// filtered violation below 'Reference to instance variable 'age' needs "this.".'
age = 24;
}
public void changeNumber(int number) {
// violation below, 'Reference to instance variable 'number' needs "this.".'
number = number;
}
}
</code></pre></div>
<p id="Example12-config">
Suppress <code>IllegalThrows</code> violations only for methods with name
<i>throwsMethod</i> and only for <code>RuntimeException</code> exceptions.
Double colon is used for axis iterations. In the following example <code>ancestor</code>
axis is used to iterate all ancestor nodes of the current node with type
<code>METHOD_DEF</code> and name <i>throwsMethod</i>. Please read more about xpath axes at
<a href="https://www.w3schools.com/xml/xpath_axes.asp" class="externalLink">W3Schools Xpath Axes</a>.
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="IllegalThrows"/>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="IllegalThrows"/>
<property name="query" value="//LITERAL_THROWS/IDENT[@text='RuntimeException'
and ./ancestor::METHOD_DEF[./IDENT[@text='throwsMethod']]]"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example12-code">Code Example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
public class Example12 {
// filtered violation below 'Throwing 'RuntimeException' is not allowed.'
public void throwsMethod() throws RuntimeException {
}
// violation below, 'Throwing 'RuntimeException' is not allowed.'
public void sampleMethod() throws RuntimeException {
}
}
</code></pre></div>
<p id="Example13-config">
The following sample demonstrates how to suppress all violations for method itself and
all descendants. <code>descendant-or-self</code> axis iterates through current node and
all children nodes at any level. Keyword <code>node()</code> selects node elements.
Please read more about xpath syntax at
<a href="https://www.w3schools.com/xml/xpath_syntax.asp" class="externalLink">W3Schools Xpath Syntax</a>.
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="LocalFinalVariableName">
<property name="format" value="^[A-Z][A-Z0-9]*$"/>
</module>
<module name="MethodName">
<property name="format" value="^[a-z](_?[a-zA-Z0-9]+)*$"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value=".*"/>
<property name="query" value="//METHOD_DEF[./IDENT[@text='TestMethod1']]
/descendant-or-self::node()"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example13-code">Code Example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
public class Example13 {
// filtered violation below 'Name 'TestMethod1' must match pattern'
public void TestMethod1() {
// filtered violation below 'Name 'num' must match pattern'
final int num = 10;
}
// violation below, 'Name 'TestMethod2' must match pattern'
public void TestMethod2() {
// violation below, 'Name 'num' must match pattern'
final int num = 10;
}
}
</code></pre></div>
<p id="Example14-config">
The following example is an example of what checks would be suppressed
while building Spring projects with checkstyle plugin.
Please find more information at:
<a href="https://github.com/spring-io/spring-javaformat" class="externalLink">spring-javaformat</a>
</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml">
<module name="Checker">
<module name="TreeWalker">
<module name="IllegalIdentifierName">
<property name="format" value="^[A-Z][a-zA-Z0-9]*$"/>
<property name="tokens" value="CLASS_DEF"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="files" value="[\\/]src[\\/]test[\\/]java[\\/]"/>
<property name="checks" value="IllegalIdentifierName"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="files" value=".*Tests\.java"/>
<property name="checks" value="IllegalIdentifierName"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="files" value="generated-sources"/>
<property name="checks" value="[a-zA-Z0-9]*"/>
</module>
</module>
</module>
</code></pre></div>
<p id="Example14-code">Code Example:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">
.../src/myApplication.java // violation, Name 'myApplication' must match pattern.
.../src/myApplicationTests.java // filtered violation 'must match pattern'
.../src/test/java/insidePackage.java // filtered violation 'must match pattern'
</code></pre></div>
</section>
<a id="Example_of_Usage"></a><section id="Example_of_Usage"><a id="Example_of_Usage"></a>
<h2>Example of Usage</h2>
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig%20path%3A**%2Fcheckstyle-checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressionXpathSingleFilter" class="externalLink">
Checkstyle Style</a>
</li>
</ul>
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressionXpathSingleFilter" class="externalLink">
Google Style</a>
</li>
</ul>
</section>
<a id="Package"></a><section id="Package"><a id="Package"></a>
<h2>Package</h2>
<p> com.puppycrawl.tools.checkstyle.filters </p>
</section>
<a id="Parent_Module"></a><section id="Parent_Module"><a id="Parent_Module"></a>
<h2>Parent Module</h2>
<p>
<a href="../config.html#TreeWalker">TreeWalker</a>
</p>
</section>
</section>
</main>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<p>© 2001–2025
</p>
</div>
</div>
</footer>
</body>
</html>