-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
SuppressionXpathFilter.java
701 lines (688 loc) · 21.1 KB
/
SuppressionXpathFilter.java
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
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2020 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.filters;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent;
import com.puppycrawl.tools.checkstyle.TreeWalkerFilter;
import com.puppycrawl.tools.checkstyle.api.AutomaticBean;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.ExternalResourceHolder;
import com.puppycrawl.tools.checkstyle.utils.FilterUtil;
/**
* <p>
* Filter {@code SuppressionXpathFilter} works as
* <a href="https://checkstyle.org/config_filters.html#SuppressionFilter">SuppressionFilter</a>.
* Additionally, filter processes {@code suppress-xpath} elements,
* which contains xpath-expressions. Xpath-expressions are queries for
* suppressed nodes inside the AST tree.
* </p>
* <p>
* Currently, filter does not support the following checks:
* </p>
* <ul id="SuppressionXpathFilter_IncompatibleChecks">
* <li>
* AnnotationLocation
* </li>
* <li>
* AnnotationOnSameLine
* </li>
* <li>
* AnnotationUseStyle
* </li>
* <li>
* ArrayTrailingComma
* </li>
* <li>
* AvoidEscapedUnicodeCharacters
* </li>
* <li>
* AvoidStarImport
* </li>
* <li>
* AvoidStaticImport
* </li>
* <li>
* CommentsIndentation
* </li>
* <li>
* CustomImportOrder
* </li>
* <li>
* EmptyCatchBlock
* </li>
* <li>
* EmptyLineSeparator
* </li>
* <li>
* FinalClass
* </li>
* <li>
* IllegalCatch
* </li>
* <li>
* ImportOrder
* </li>
* <li>
* Indentation
* </li>
* <li>
* InterfaceIsType
* </li>
* <li>
* InterfaceMemberImpliedModifier
* </li>
* <li>
* InvalidJavadocPosition
* </li>
* <li>
* JavadocContentLocation
* </li>
* <li>
* JavadocMethod
* </li>
* <li>
* JavadocStyle
* </li>
* <li>
* JavadocType
* </li>
* <li>
* LambdaParameterName
* </li>
* <li>
* MethodCount
* </li>
* <li>
* MissingCtor
* </li>
* <li>
* MissingJavadocMethod
* </li>
* <li>
* MissingJavadocPackage
* </li>
* <li>
* MissingJavadocType
* </li>
* <li>
* MissingOverride
* </li>
* <li>
* MissingSwitchDefault
* </li>
* <li>
* NeedBraces
* </li>
* <li>
* NoClone
* </li>
* <li>
* NoFinalizer
* </li>
* <li>
* NoLineWrap
* </li>
* <li>
* OneTopLevelClass
* </li>
* <li>
* OuterTypeFilename
* </li>
* <li>
* OverloadMethodsDeclarationOrder
* </li>
* <li>
* PackageAnnotation
* </li>
* <li>
* PackageDeclaration
* </li>
* <li>
* Regexp
* </li>
* <li>
* RegexpSinglelineJava
* </li>
* <li>
* SuppressWarningsHolder
* </li>
* <li>
* TodoComment
* </li>
* <li>
* TrailingComment
* </li>
* <li>
* UncommentedMain
* </li>
* <li>
* UnnecessaryParentheses
* </li>
* <li>
* VariableDeclarationUsageDistance
* </li>
* <li>
* WriteTag
* </li>
* </ul>
* <p>
* Also, the filter does not support Javadoc checks:
* </p>
* <ul id="SuppressionXpathFilter_JavadocChecks">
* <li>
* AtclauseOrder
* </li>
* <li>
* JavadocBlockTagLocation
* </li>
* <li>
* JavadocMissingWhitespaceAfterAsterisk
* </li>
* <li>
* JavadocParagraph
* </li>
* <li>
* JavadocTagContinuationIndentation
* </li>
* <li>
* MissingDeprecated
* </li>
* <li>
* NonEmptyAtclauseDescription
* </li>
* <li>
* SingleLineJavadoc
* </li>
* <li>
* SummaryJavadoc
* </li>
* </ul>
* <p>
* Note, that support for these Checks will be available after resolving issues
* <a href="https://github.com/checkstyle/checkstyle/issues/5770">#5770</a> and
* <a href="https://github.com/checkstyle/checkstyle/issues/5777">#5777</a>.
* </p>
* <p>
* Currently, filter supports the following xpath axes:
* </p>
* <ul>
* <li>
* ancestor
* </li>
* <li>
* ancestor-or-self
* </li>
* <li>
* attribute
* </li>
* <li>
* child
* </li>
* <li>
* descendant
* </li>
* <li>
* descendant-or-self
* </li>
* <li>
* following
* </li>
* <li>
* following-sibling
* </li>
* <li>
* parent
* </li>
* <li>
* preceding
* </li>
* <li>
* preceding-sibling
* </li>
* <li>
* self
* </li>
* </ul>
* <p>
* You can use the command line helper tool to generate xpath suppressions based on your
* configuration file and input files. See <a href="https://checkstyle.org/cmdline.html">here</a>
* for more details.
* </p>
* <p>
* The suppression file location is checked in following order:
* </p>
* <ol>
* <li>
* as a filesystem location
* </li>
* <li>
* if no file found, and the location starts with either {@code http://} or {@code https://},
* then it is interpreted as a URL
* </li>
* <li>
* if no file found, then passed to the {@code ClassLoader.getResource()} method.
* </li>
* </ol>
* <ul>
* <li>
* Property {@code file} - Specify the location of the <em>suppressions XML document</em> file.
* Default value is {@code null}.
* </li>
* <li>
* Property {@code optional} - Control what to do when the file is not existing.
* If optional is set to false the file must exist, or else it ends with error.
* On the other hand if optional is true and file is not found, the filter accepts all audit events.
* Default value is {@code false}.
* </li>
* </ul>
* <p>
* For example, the following configuration fragment directs the Checker to use a
* {@code SuppressionXpathFilter} with suppressions file {@code config/suppressions.xml}:
* </p>
* <pre>
* <module name="SuppressionXpathFilter">
* <property name="file" value="config/suppressions.xml"/>
* <property name="optional" value="false"/>
* </module>
* </pre>
* <p>
* A <a href="https://checkstyle.org/dtds/suppressions_1_2_xpath_experimental.dtd"><em>
* suppressions XML document</em></a>
* contains a set of {@code suppress} and {@code suppress-xpath} elements,
* where each {@code suppress-xpath} element can have the following attributes:
* </p>
* <ul>
* <li>
* {@code files} - a <a href="https://checkstyle.org/property_types.html#regexp">Regular Expression</a>
* matched against the file name associated with an audit event. It is optional.
* </li>
* <li>
* {@code checks} - a <a href="https://checkstyle.org/property_types.html#regexp">Regular Expression</a>
* matched against the name of the check associated with an audit event.
* Optional as long as {@code id} or {@code message} is specified.
* </li>
* <li>
* {@code message} - a <a href="https://checkstyle.org/property_types.html#regexp">Regular Expression</a>
* matched against the message of the check associated with an audit event.
* Optional as long as {@code checks} or {@code id} is specified.
* </li>
* <li>
* {@code id} - a <a href="https://checkstyle.org/property_types.html#string">string</a> matched against
* the ID of the check associated with an audit event.
* Optional as long as {@code checks} or {@code message} is specified.
* </li>
* <li>
* {@code query} - a <a href="https://checkstyle.org/property_types.html#string">string</a> xpath query. It is optional.
* </li>
* </ul>
* <p>
* Each audit event is checked against each {@code suppress} and {@code suppress-xpath} element.
* It is suppressed if all specified attributes match against the audit event.
* </p>
* <p>
* ATTENTION: filtering by message is dependant on runtime locale.
* If project is running in different languages it is better to avoid filtering by message.
* </p>
* <p>
* The following suppressions XML document directs a {@code SuppressionXpathFilter} to reject
* {@code CyclomaticComplexity} violations for all methods with name <i>sayHelloWorld</i> inside
* <i>FileOne</i> and <i>FileTwo</i> files:
* </p>
* <p>
* Currently, xpath queries support one type of attribute {@code @text}. {@code @text} -
* addresses to the text value of the node. For example: variable name, annotation name,
* text content and etc. Only the following token types support {@code @text} attribute:
* {@code TokenTypes.IDENT}, {@code TokenTypes.STRING_LITERAL}, {@code TokenTypes.CHAR_LITERAL},
* {@code TokenTypes.NUM_LONG}, {@code TokenTypes.NUM_INT}, {@code TokenTypes.NUM_DOUBLE},
* {@code TokenTypes.NUM_FLOAT}.
* These token types were selected because only their text values are different
* in content from token type and represent text value from file and can be used
* in xpath queries for more accurate results. Other token types always have constant values.
* </p>
* <pre>
* <?xml version="1.0"?>
*
* <!DOCTYPE suppressions PUBLIC
* "-//Checkstyle//DTD SuppressionXpathFilter Experimental Configuration 1.2//EN"
* "https://checkstyle.org/dtds/suppressions_1_2_xpath_experimental.dtd">
*
* <suppressions>
* <suppress-xpath checks="CyclomaticComplexity"
* files="FileOne.java,FileTwo.java"
* query="//METHOD_DEF[./IDENT[@text='sayHelloWorld']]"/>
* </suppressions>
* </pre>
* <p>
* Suppress checks for package definitions:
* </p>
* <pre>
* <suppress-xpath checks=".*" query="/PACKAGE_DEF"/>
* </pre>
* <p>
* Suppress checks for parent element of the first variable definition:
* </p>
* <pre>
* <suppress-xpath checks=".*" query="(//VARIABLE_DEF)[1]/.."/>
* </pre>
* <p>
* Suppress checks for elements which are either class definitions, either method definitions.
* </p>
* <pre>
* <suppress-xpath checks=".*" query="//CLASS_DEF | //METHOD_DEF"/>
* </pre>
* <p>
* Suppress checks for certain methods:
* </p>
* <pre>
* <suppress-xpath checks=".*" query="//METHOD_DEF[./IDENT[@text='getSomeVar'
* or @text='setSomeVar']]"/>
* </pre>
* <p>
* Suppress checks for variable <i>testVariable</i> inside <i>testMethod</i>
* method inside <i>TestClass</i> class.
* </p>
* <pre>
* <suppress-xpath checks=".*" query="/CLASS_DEF[@text='TestClass']
* //METHOD_DEF[./IDENT[@text='testMethod']]
* //VARIABLE_DEF[./IDENT[@text='testVariable']]"/>
* </pre>
* <p>
* In the following sample, violations for {@code LeftCurly} check will be suppressed
* for classes with name <i>Main</i> or for methods with name <i>calculate</i>.
* </p>
* <pre>
* <suppress-xpath checks="LeftCurly" query="/CLASS_DEF[./IDENT[@text='Main']]//*
* | //METHOD_DEF[./IDENT[@text='calculate']]/*"/>
* </pre>
* <p>
* The following example demonstrates how to suppress {@code RequireThis} violations
* for variable <i>age</i> inside <i>changeAge</i> method.
* </p>
* <pre>
* <suppress-xpath checks="RequireThis"
* query="/CLASS_DEF[./IDENT[@text='InputTest']]
* //METHOD_DEF[./IDENT[@text='changeAge']]//ASSIGN/IDENT[@text='age']"/>
* </pre>
* <pre>
* public class InputTest {
* private int age = 23;
*
* public void changeAge() {
* age = 24; //violation will be suppressed
* }
* }
* </pre>
* <p>
* Suppress {@code IllegalThrows} violations only for methods with name <i>throwsMethod</i>
* and only for {@code RuntimeException} exceptions. Double colon is used for axis iterations.
* In the following example {@code ancestor} axis is used to iterate all ancestor nodes
* of the current node with type {@code METHOD_DEF} and name <i>throwsMethod</i>.
* Please read more about xpath axes at <a href="https://www.w3schools.com/xml/xpath_axes.asp">
* W3Schools Xpath Axes</a>.
* </p>
* <pre>
* <suppress-xpath checks="IllegalThrows" query="//LITERAL_THROWS
* /IDENT[@text='RuntimeException' and
* ./ancestor::METHOD_DEF[./IDENT[@text='throwsMethod']]]"/>
* </pre>
* <pre>
* public class InputTest {
* public void throwsMethod() throws RuntimeException { // violation will be suppressed
* }
*
* public void sampleMethod() throws RuntimeException { // will throw violation here
* }
* }
* </pre>
* <p>
* The following sample demonstrates how to suppress all violations for method
* itself and all descendants. {@code descendant-or-self} axis iterates through
* current node and all children nodes at any level. Keyword {@code node()}
* selects node elements. Please read more about xpath syntax at
* <a href="https://www.w3schools.com/xml/xpath_syntax.asp">W3Schools Xpath Syntax</a>.
* </p>
* <pre>
* <suppress-xpath checks=".*" query="//METHOD_DEF[./IDENT[@text='legacyMethod']]
* /descendant-or-self::node()"/>
* </pre>
* <p>
* Some elements can be suppressed in different ways. For example, to suppress
* violation on variable {@code wordCount} in following code:
* </p>
* <pre>
* public class InputTest {
* private int wordCount = 11;
* }
* </pre>
* <p>
* You need to look at AST of such code by our CLI tool:
* </p>
* <pre>
* $ java -jar checkstyle-X.XX-all.jar -t InputTest.java
* CLASS_DEF -> CLASS_DEF [1:0]
* |--MODIFIERS -> MODIFIERS [1:0]
* | `--LITERAL_PUBLIC -> public [1:0]
* |--LITERAL_CLASS -> class [1:7]
* |--IDENT -> InputTest [1:13]
* `--OBJBLOCK -> OBJBLOCK [1:23]
* |--LCURLY -> { [1:23]
* |--VARIABLE_DEF -> VARIABLE_DEF [2:4]
* | |--MODIFIERS -> MODIFIERS [2:4]
* | | `--LITERAL_PRIVATE -> private [2:4]
* | |--TYPE -> TYPE [2:12]
* | | `--LITERAL_INT -> int [2:12]
* | |--IDENT -> wordCount [2:16]
* | |--ASSIGN -> = [2:26]
* | | `--EXPR -> EXPR [2:28]
* | | `--NUM_INT -> 11 [2:28]
* | `--SEMI -> ; [2:30]
* `--RCURLY -> } [3:0]
* </pre>
* <p>
* The easiest way is to suppress by variable name. As you can see {@code VARIABLE_DEF}
* node refers to variable declaration statement and has child node with token type
* {@code IDENT} which is used for storing class, method, variable names.
* </p>
* <p>
* The following example demonstrates how variable can be queried by its name:
* </p>
* <pre>
* <suppress-xpath checks="." query="//VARIABLE_DEF[
* ./IDENT[@text='wordCount']]"/>
* </pre>
* <p>
* Another way is to suppress by variable value. Again, if you look at the printed
* AST tree above, you will notice that one of the grandchildren of {@code VARIABLE_DEF}
* node is responsible for storing variable value -{@code NUM_INT} with value <b>11</b>.
* </p>
* <p>
* The following example demonstrates how variable can be queried by its value,
* same approach applies to {@code String, char, float, double, int, long} data types:
* </p>
* <pre>
* <suppress-xpath checks="." query="//VARIABLE_DEF[.//NUM_INT[@text=11]]"/>
* </pre>
* <p>
* Next example is about suppressing method with certain annotation by its name and element value.
* </p>
* <pre>
* public class InputTest {
* @Generated("first") // should not be suppressed
* public void test1() {
* }
*
* @Generated("second") // should be suppressed
* public void test2() {
* }
* }
* </pre>
* <p>
* First of all we need to look at AST tree printed by our CLI tool:
* </p>
* <pre>
* $ java -jar checkstyle-X.XX-all.jar -t InputTest.java
* CLASS_DEF -> CLASS_DEF [1:0]
* |--MODIFIERS -> MODIFIERS [1:0]
* | `--LITERAL_PUBLIC -> public [1:0]
* |--LITERAL_CLASS -> class [1:7]
* |--IDENT -> InputTest [1:13]
* `--OBJBLOCK -> OBJBLOCK [1:23]
* |--LCURLY -> { [1:23]
* |--METHOD_DEF -> METHOD_DEF [2:4]
* | |--MODIFIERS -> MODIFIERS [2:4]
* | | |--ANNOTATION -> ANNOTATION [2:4]
* | | | |--AT -> @ [2:4]
* | | | |--IDENT -> Generated [2:5]
* | | | |--LPAREN -> ( [2:14]
* | | | |--EXPR -> EXPR [2:15]
* | | | | `--STRING_LITERAL -> "first" [2:15]
* | | | `--RPAREN -> ) [2:22]
* | | `--LITERAL_PUBLIC -> public [3:4]
* | |--TYPE -> TYPE [3:11]
* | | `--LITERAL_VOID -> void [3:11]
* | |--IDENT -> test1 [3:16]
* | |--LPAREN -> ( [3:21]
* | |--PARAMETERS -> PARAMETERS [3:22]
* | |--RPAREN -> ) [3:22]
* | `--SLIST -> { [3:24]
* | `--RCURLY -> } [4:4]
* |--METHOD_DEF -> METHOD_DEF [6:4]
* | |--MODIFIERS -> MODIFIERS [6:4]
* | | |--ANNOTATION -> ANNOTATION [6:4]
* | | | |--AT -> @ [6:4]
* | | | |--IDENT -> Generated [6:5]
* | | | |--LPAREN -> ( [6:14]
* | | | |--EXPR -> EXPR [6:15]
* | | | | `--STRING_LITERAL -> "second" [6:15]
* | | | `--RPAREN -> ) [6:23]
* | | `--LITERAL_PUBLIC -> public [7:4]
* | |--TYPE -> TYPE [7:11]
* | | `--LITERAL_VOID -> void [7:11]
* | |--IDENT -> test2 [7:16]
* | |--LPAREN -> ( [7:21]
* | |--PARAMETERS -> PARAMETERS [7:22]
* | |--RPAREN -> ) [7:22]
* | `--SLIST -> { [7:24]
* | `--RCURLY -> } [8:4]
* `--RCURLY -> } [9:0]
* </pre>
* <p>
* AST node {@code ANNOTATION -> ANNOTATION [6:4]} has direct child
* {@code IDENT -> Generated [6:5]}, therefore can be queried by {@code IDENT} value:
* </p>
* <pre>
* <suppress-xpath checks="." query="//METHOD_DEF[
* .//ANNOTATION/IDENT[@text='Generated']]"/>
* </pre>
* <p>
* The problem with query above that it will suppress violations for all methods
* with annotation {@code @Generated}. In order to suppress methods with
* {@code @Generated("second")} annotations only, you need to look at AST tree again.
* Value of the {@code ANNOTATION} node is stored inside sub-node with token type
* {@code STRING_LITERAL}. Use the following query to suppress methods with
* {@code @Generated("second")} annotation:
* </p>
* <pre>
* <suppress-xpath checks="." query="//METHOD_DEF[.//ANNOTATION[
* ./IDENT[@text='Generated'] and ./EXPR/STRING_LITERAL[@text='second']]]"/>
* </pre>
*
* @since 8.6
* @noinspection NonFinalFieldReferenceInEquals, NonFinalFieldReferencedInHashCode
*/
public class SuppressionXpathFilter extends AutomaticBean implements
TreeWalkerFilter, ExternalResourceHolder {
/** Specify the location of the <em>suppressions XML document</em> file. */
private String file;
/**
* Control what to do when the file is not existing.
* If optional is set to false the file must exist, or else it ends with error.
* On the other hand if optional is true and file is not found,
* the filter accepts all audit events.
*/
private boolean optional;
/** Set of individual xpath suppresses. */
private Set<TreeWalkerFilter> filters = new HashSet<>();
/**
* Setter to specify the location of the <em>suppressions XML document</em> file.
* @param fileName name of the suppressions file.
*/
public void setFile(String fileName) {
file = fileName;
}
/**
* Setter to control what to do when the file is not existing.
* If optional is set to false the file must exist, or else it ends with error.
* On the other hand if optional is true and file is not found,
* the filter accepts all audit events.
* @param optional tells if config file existence is optional.
*/
public void setOptional(boolean optional) {
this.optional = optional;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final SuppressionXpathFilter suppressionXpathFilter = (SuppressionXpathFilter) obj;
return Objects.equals(filters, suppressionXpathFilter.filters);
}
@Override
public int hashCode() {
return Objects.hash(filters);
}
@Override
public boolean accept(TreeWalkerAuditEvent treeWalkerAuditEvent) {
boolean result = true;
for (TreeWalkerFilter filter : filters) {
if (!filter.accept(treeWalkerAuditEvent)) {
result = false;
break;
}
}
return result;
}
@Override
public Set<String> getExternalResourceLocations() {
return Collections.singleton(file);
}
@Override
protected void finishLocalSetup() throws CheckstyleException {
if (file != null) {
if (optional) {
if (FilterUtil.isFileExists(file)) {
filters = SuppressionsLoader.loadXpathSuppressions(file);
}
else {
filters = new HashSet<>();
}
}
else {
filters = SuppressionsLoader.loadXpathSuppressions(file);
}
}
}
}