1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23
24 import java.io.ByteArrayInputStream;
25 import java.io.ByteArrayOutputStream;
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29 import java.io.LineNumberReader;
30 import java.nio.charset.StandardCharsets;
31 import java.nio.file.Path;
32 import java.text.MessageFormat;
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.Collections;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.Map;
40 import java.util.ResourceBundle;
41 import java.util.stream.Collectors;
42
43 import com.google.common.collect.ImmutableMap;
44 import com.google.common.collect.Maps;
45 import com.puppycrawl.tools.checkstyle.LocalizedMessage.Utf8Control;
46 import com.puppycrawl.tools.checkstyle.api.AuditListener;
47 import com.puppycrawl.tools.checkstyle.api.Configuration;
48 import com.puppycrawl.tools.checkstyle.api.DetailAST;
49 import com.puppycrawl.tools.checkstyle.bdd.InlineConfigParser;
50 import com.puppycrawl.tools.checkstyle.bdd.TestInputConfiguration;
51 import com.puppycrawl.tools.checkstyle.bdd.TestInputViolation;
52 import com.puppycrawl.tools.checkstyle.internal.utils.BriefUtLogger;
53 import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil;
54 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
55 import com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil;
56 import com.puppycrawl.tools.checkstyle.xpath.RootNode;
57
58 public abstract class AbstractModuleTestSupport extends AbstractPathTestSupport {
59
60 protected static final String ROOT_MODULE_NAME = Checker.class.getSimpleName();
61
62 private final ByteArrayOutputStream stream = new ByteArrayOutputStream();
63
64
65
66
67
68
69 protected final ByteArrayOutputStream getStream() {
70 return stream;
71 }
72
73
74
75
76
77
78 protected final BriefUtLogger getBriefUtLogger() {
79 return new BriefUtLogger(stream);
80 }
81
82
83
84
85
86
87
88
89 protected static DefaultConfiguration createModuleConfig(Class<?> clazz) {
90 return new DefaultConfiguration(clazz.getName());
91 }
92
93
94
95
96
97
98
99
100 protected final Checker createChecker(Configuration moduleConfig)
101 throws Exception {
102 final String moduleName = moduleConfig.getName();
103 final Checker checker = new Checker();
104 checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
105
106 if (ROOT_MODULE_NAME.equals(moduleName)) {
107 checker.configure(moduleConfig);
108 }
109 else {
110 configureChecker(checker, moduleConfig);
111 }
112
113 checker.addListener(getBriefUtLogger());
114 return checker;
115 }
116
117
118
119
120
121
122
123
124 protected void configureChecker(Checker checker, Configuration moduleConfig) throws Exception {
125 final Class<?> moduleClass = Class.forName(moduleConfig.getName());
126
127 final Configuration config;
128 if (ModuleReflectionUtil.isCheckstyleTreeWalkerCheck(moduleClass)
129 || ModuleReflectionUtil.isTreeWalkerFilterModule(moduleClass)) {
130 config = createTreeWalkerConfig(moduleConfig);
131 }
132 else {
133 config = createRootConfig(moduleConfig);
134 }
135 checker.configure(config);
136 }
137
138
139
140
141
142
143
144
145
146 protected static DefaultConfiguration createTreeWalkerConfig(Configuration config) {
147 final DefaultConfiguration rootConfig =
148 new DefaultConfiguration(ROOT_MODULE_NAME);
149 final DefaultConfiguration twConf = createModuleConfig(TreeWalker.class);
150
151 rootConfig.addProperty("charset", StandardCharsets.UTF_8.name());
152 rootConfig.addChild(twConf);
153 twConf.addChild(config);
154 return rootConfig;
155 }
156
157
158
159
160
161
162
163 protected static DefaultConfiguration createRootConfig(Configuration config) {
164 final DefaultConfiguration rootConfig = new DefaultConfiguration(ROOT_MODULE_NAME);
165 if (config != null) {
166 rootConfig.addChild(config);
167 }
168 return rootConfig;
169 }
170
171
172
173
174
175
176
177
178
179 protected final String getNonCompilablePath(String filename) throws IOException {
180 return new File("src/" + getResourceLocation()
181 + "/resources-noncompilable/" + getPackageLocation() + "/"
182 + filename).getCanonicalPath();
183 }
184
185
186
187
188
189
190
191
192 protected RootNode getRootNodeForNonCompilable(String fileName) throws Exception {
193 final File file = new File(getNonCompilablePath(fileName));
194 final DetailAST rootAst = JavaParser.parseFile(file, JavaParser.Options.WITHOUT_COMMENTS);
195 return new RootNode(rootAst);
196 }
197
198
199
200
201
202
203
204
205 protected final String getUriString(String filename) {
206 return new File("src/test/resources/" + getPackageLocation() + "/" + filename).toURI()
207 .toString();
208 }
209
210
211
212
213
214
215
216
217
218
219
220 protected final void verifyFilterWithInlineConfigParser(String filePath,
221 String[] expectedUnfiltered,
222 String... expectedFiltered)
223 throws Exception {
224 final TestInputConfiguration testInputConfiguration =
225 InlineConfigParser.parseWithFilteredViolations(filePath);
226 final DefaultConfiguration configWithoutFilters =
227 testInputConfiguration.createConfigurationWithoutFilters();
228 final List<TestInputViolation> violationsWithoutFilters =
229 new ArrayList<>(testInputConfiguration.getViolations());
230 violationsWithoutFilters.addAll(testInputConfiguration.getFilteredViolations());
231 Collections.sort(violationsWithoutFilters);
232 verifyViolations(configWithoutFilters, filePath, violationsWithoutFilters);
233 verify(configWithoutFilters, filePath, expectedUnfiltered);
234 final DefaultConfiguration configWithFilters =
235 testInputConfiguration.createConfiguration();
236 verifyViolations(configWithFilters, filePath, testInputConfiguration.getViolations());
237 verify(configWithFilters, filePath, expectedFiltered);
238 }
239
240
241
242
243
244
245
246
247
248
249 protected final void verifyWithInlineXmlConfig(String filePath, String... expected)
250 throws Exception {
251 final TestInputConfiguration testInputConfiguration =
252 InlineConfigParser.parseWithXmlHeader(filePath);
253 final Configuration xmlConfig =
254 testInputConfiguration.getXmlConfiguration();
255 verifyViolations(xmlConfig, filePath, testInputConfiguration.getViolations());
256 verify(xmlConfig, filePath, expected);
257 }
258
259
260
261
262
263
264
265
266
267
268 protected void verifyWithExternalXmlConfig(
269 String configPath,
270 String filePath,
271 String... expected)
272 throws Exception {
273 final Configuration config =
274 ConfigurationLoader.loadConfiguration(
275 configPath,
276 new PropertiesExpander(System.getProperties()),
277 ConfigurationLoader.IgnoredModulesOptions.EXECUTE);
278 verify(config, filePath, expected);
279 }
280
281
282
283
284
285
286
287
288
289
290 protected final void verifyWithInlineConfigParser(String filePath, String... expected)
291 throws Exception {
292 final TestInputConfiguration testInputConfiguration =
293 InlineConfigParser.parse(filePath);
294 final DefaultConfiguration parsedConfig =
295 testInputConfiguration.createConfiguration();
296 final List<String> actualViolations = getActualViolationsForFile(parsedConfig, filePath);
297 verifyViolations(filePath, testInputConfiguration.getViolations(), actualViolations);
298 assertWithMessage("Violations for %s differ.", filePath)
299 .that(actualViolations)
300 .containsExactlyElementsIn(expected);
301 }
302
303
304
305
306
307
308
309
310
311
312
313
314 protected final void verifyWithInlineConfigParser(String filePath1,
315 String filePath2,
316 String... expected)
317 throws Exception {
318 final TestInputConfiguration testInputConfiguration1 =
319 InlineConfigParser.parse(filePath1);
320 final DefaultConfiguration parsedConfig =
321 testInputConfiguration1.createConfiguration();
322 final TestInputConfiguration testInputConfiguration2 =
323 InlineConfigParser.parse(filePath2);
324 verifyViolations(parsedConfig, filePath1, testInputConfiguration1.getViolations());
325 verifyViolations(parsedConfig, filePath2, testInputConfiguration2.getViolations());
326 verify(createChecker(parsedConfig),
327 new File[] {new File(filePath1), new File(filePath2)},
328 filePath1,
329 expected);
330 }
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345 protected final void verifyWithInlineConfigParser(String filePath1,
346 String filePath2,
347 List<String> expectedFromFile1,
348 List<String> expectedFromFile2)
349 throws Exception {
350 final TestInputConfiguration testInputConfiguration = InlineConfigParser.parse(filePath1);
351 final DefaultConfiguration parsedConfig = testInputConfiguration.createConfiguration();
352 final TestInputConfiguration testInputConfiguration2 = InlineConfigParser.parse(filePath2);
353 final DefaultConfiguration parsedConfig2 = testInputConfiguration.createConfiguration();
354 final File[] inputs = {new File(filePath1), new File(filePath2)};
355 verifyViolations(parsedConfig, filePath1, testInputConfiguration.getViolations());
356 verifyViolations(parsedConfig2, filePath2, testInputConfiguration2.getViolations());
357 verify(createChecker(parsedConfig), inputs, ImmutableMap.of(
358 filePath1, expectedFromFile1,
359 filePath2, expectedFromFile2));
360 }
361
362
363
364
365
366
367
368
369
370
371
372
373 protected final void verifyWithInlineConfigParserSeparateConfigAndTarget(String fileWithConfig,
374 String targetFile,
375 String... expected)
376 throws Exception {
377 final TestInputConfiguration testInputConfiguration1 =
378 InlineConfigParser.parse(fileWithConfig);
379 final DefaultConfiguration parsedConfig =
380 testInputConfiguration1.createConfiguration();
381 final List<TestInputViolation> inputViolations =
382 InlineConfigParser.getViolationsFromInputFile(targetFile);
383 final List<String> actualViolations = getActualViolationsForFile(parsedConfig, targetFile);
384 verifyViolations(targetFile, inputViolations, actualViolations);
385 assertWithMessage("Violations for %s differ.", targetFile)
386 .that(actualViolations)
387 .containsExactlyElementsIn(expected);
388 }
389
390
391
392
393
394
395
396
397
398
399
400
401 protected final void verifyFilterWithInlineConfigParserSeparateConfigAndTarget(
402 String fileWithConfig,
403 String targetFilePath,
404 String[] expectedUnfiltered,
405 String... expectedFiltered)
406 throws Exception {
407 final TestInputConfiguration testInputConfiguration =
408 InlineConfigParser.parseWithFilteredViolations(fileWithConfig);
409 final DefaultConfiguration configWithoutFilters =
410 testInputConfiguration.createConfigurationWithoutFilters();
411 final List<TestInputViolation> violationsWithoutFilters = new ArrayList<>(
412 InlineConfigParser.getFilteredViolationsFromInputFile(targetFilePath));
413 violationsWithoutFilters.addAll(
414 InlineConfigParser.getViolationsFromInputFile(targetFilePath));
415 Collections.sort(violationsWithoutFilters);
416 verifyViolations(configWithoutFilters, targetFilePath, violationsWithoutFilters);
417 verify(configWithoutFilters, targetFilePath, expectedUnfiltered);
418 final DefaultConfiguration configWithFilters =
419 testInputConfiguration.createConfiguration();
420 final List<TestInputViolation> violationsWithFilters =
421 InlineConfigParser.getViolationsFromInputFile(targetFilePath);
422 verifyViolations(configWithFilters, targetFilePath, violationsWithFilters);
423 verify(configWithFilters, targetFilePath, expectedFiltered);
424 }
425
426
427
428
429
430
431
432
433
434
435 protected void verifyWithInlineConfigParserTwice(String filePath, String... expected)
436 throws Exception {
437 final TestInputConfiguration testInputConfiguration =
438 InlineConfigParser.parse(filePath);
439 final DefaultConfiguration parsedConfig =
440 testInputConfiguration.createConfiguration();
441 verifyViolations(parsedConfig, filePath, testInputConfiguration.getViolations());
442 verify(parsedConfig, filePath, expected);
443 }
444
445
446
447
448
449
450
451
452
453
454
455
456 protected void verifyWithInlineConfigParserAndLogger(String inputFile,
457 String expectedReportFile,
458 AuditListener logger,
459 ByteArrayOutputStream outputStream)
460 throws Exception {
461 final TestInputConfiguration testInputConfiguration =
462 InlineConfigParser.parse(inputFile);
463 final DefaultConfiguration parsedConfig =
464 testInputConfiguration.createConfiguration();
465 final List<File> filesToCheck = Collections.singletonList(new File(inputFile));
466 final String basePath = Path.of("").toAbsolutePath().toString();
467
468 final Checker checker = createChecker(parsedConfig);
469 checker.setBasedir(basePath);
470 checker.addListener(logger);
471 checker.process(filesToCheck);
472
473 verifyContent(expectedReportFile, outputStream);
474 }
475
476
477
478
479
480
481
482
483
484
485
486
487 protected final void verifyWithInlineConfigParserAndDefaultLogger(String inputFile,
488 String expectedOutputFile,
489 AuditListener logger,
490 ByteArrayOutputStream outputStream)
491 throws Exception {
492 final TestInputConfiguration testInputConfiguration =
493 InlineConfigParser.parseWithXmlHeader(inputFile);
494 final Configuration parsedConfig =
495 testInputConfiguration.getXmlConfiguration();
496 final List<File> filesToCheck = Collections.singletonList(new File(inputFile));
497 final String basePath = Path.of("").toAbsolutePath().toString();
498
499 final Checker checker = createChecker(parsedConfig);
500 checker.setBasedir(basePath);
501 checker.addListener(logger);
502 checker.process(filesToCheck);
503
504 verifyCleanedMessageContent(expectedOutputFile, outputStream, basePath);
505 }
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524 protected final void verifyWithInlineConfigParserAndDefaultLogger(String inputFile,
525 String expectedInfoFile,
526 String expectedErrorFile,
527 AuditListener logger,
528 ByteArrayOutputStream infoStream,
529 ByteArrayOutputStream errorStream)
530 throws Exception {
531 final TestInputConfiguration testInputConfiguration =
532 InlineConfigParser.parseWithXmlHeader(inputFile);
533 final Configuration parsedConfig =
534 testInputConfiguration.getXmlConfiguration();
535 final List<File> filesToCheck = Collections.singletonList(new File(inputFile));
536 final String basePath = Path.of("").toAbsolutePath().toString();
537
538 final Checker checker = createChecker(parsedConfig);
539 checker.setBasedir(basePath);
540 checker.addListener(logger);
541 checker.process(filesToCheck);
542
543 verifyContent(expectedInfoFile, infoStream);
544 verifyCleanedMessageContent(expectedErrorFile, errorStream, basePath);
545 }
546
547
548
549
550
551
552
553
554
555
556
557
558 protected final void verify(Configuration config, String fileName, String... expected)
559 throws Exception {
560 verify(createChecker(config), fileName, fileName, expected);
561 }
562
563
564
565
566
567
568
569
570
571
572
573
574
575 protected void verify(Checker checker, String fileName, String... expected)
576 throws Exception {
577 verify(checker, fileName, fileName, expected);
578 }
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593 protected final void verify(Checker checker,
594 String processedFilename,
595 String messageFileName,
596 String... expected)
597 throws Exception {
598 verify(checker,
599 new File[] {new File(processedFilename)},
600 messageFileName, expected);
601 }
602
603
604
605
606
607
608
609
610
611
612
613 protected void verify(Checker checker,
614 File[] processedFiles,
615 String messageFileName,
616 String... expected)
617 throws Exception {
618 final Map<String, List<String>> expectedViolations = new HashMap<>();
619 expectedViolations.put(messageFileName, Arrays.asList(expected));
620 verify(checker, processedFiles, expectedViolations);
621 }
622
623
624
625
626
627
628
629
630
631 protected final void verify(Checker checker,
632 File[] processedFiles,
633 Map<String, List<String>> expectedViolations)
634 throws Exception {
635 stream.flush();
636 stream.reset();
637 final List<File> theFiles = new ArrayList<>();
638 Collections.addAll(theFiles, processedFiles);
639 checker.process(theFiles);
640
641
642 final Map<String, List<String>> actualViolations = getActualViolations();
643 final Map<String, List<String>> realExpectedViolations =
644 Maps.filterValues(expectedViolations, input -> !input.isEmpty());
645
646 assertWithMessage("Files with expected violations and actual violations differ.")
647 .that(actualViolations.keySet())
648 .isEqualTo(realExpectedViolations.keySet());
649
650 realExpectedViolations.forEach((fileName, violationList) -> {
651 assertWithMessage("Violations for %s differ.", fileName)
652 .that(actualViolations.get(fileName))
653 .containsExactlyElementsIn(violationList);
654 });
655
656 checker.destroy();
657 }
658
659
660
661
662
663
664
665
666 protected final void verifyWithLimitedResources(String fileName, String... expected)
667 throws Exception {
668 TestUtil.getResultWithLimitedResources(() -> {
669 verifyWithInlineConfigParser(fileName, expected);
670 return null;
671 });
672 }
673
674
675
676
677
678
679
680
681 protected final void execute(Configuration config, String... filenames) throws Exception {
682 final Checker checker = createChecker(config);
683 final List<File> files = Arrays.stream(filenames)
684 .map(File::new)
685 .toList();
686 checker.process(files);
687 checker.destroy();
688 }
689
690
691
692
693
694
695
696
697 protected static void execute(Checker checker, String... filenames) throws Exception {
698 final List<File> files = Arrays.stream(filenames)
699 .map(File::new)
700 .toList();
701 checker.process(files);
702 checker.destroy();
703 }
704
705
706
707
708
709
710
711
712
713 private void verifyViolations(Configuration config,
714 String file,
715 List<TestInputViolation> testInputViolations)
716 throws Exception {
717 final List<String> actualViolations = getActualViolationsForFile(config, file);
718 final List<Integer> actualViolationLines = actualViolations.stream()
719 .map(violation -> violation.substring(0, violation.indexOf(':')))
720 .map(Integer::valueOf)
721 .toList();
722 final List<Integer> expectedViolationLines = testInputViolations.stream()
723 .map(TestInputViolation::getLineNo)
724 .toList();
725 assertWithMessage("Violation lines for %s differ.", file)
726 .that(actualViolationLines)
727 .isEqualTo(expectedViolationLines);
728 for (int index = 0; index < actualViolations.size(); index++) {
729 assertWithMessage("Actual and expected violations differ.")
730 .that(actualViolations.get(index))
731 .matches(testInputViolations.get(index).toRegex());
732 }
733 }
734
735
736
737
738
739
740
741
742 private static void verifyViolations(String file,
743 List<TestInputViolation> testInputViolations,
744 List<String> actualViolations) {
745 final List<Integer> actualViolationLines = actualViolations.stream()
746 .map(violation -> violation.substring(0, violation.indexOf(':')))
747 .map(Integer::valueOf)
748 .toList();
749 final List<Integer> expectedViolationLines = testInputViolations.stream()
750 .map(TestInputViolation::getLineNo)
751 .toList();
752 assertWithMessage("Violation lines for %s differ.", file)
753 .that(actualViolationLines)
754 .isEqualTo(expectedViolationLines);
755 for (int index = 0; index < actualViolations.size(); index++) {
756 assertWithMessage("Actual and expected violations differ.")
757 .that(actualViolations.get(index))
758 .matches(testInputViolations.get(index).toRegex());
759 }
760 }
761
762
763
764
765
766
767
768
769 private static void verifyContent(
770 String expectedOutputFile,
771 ByteArrayOutputStream outputStream) throws IOException {
772 final String expectedContent = readFile(expectedOutputFile);
773 final String actualContent =
774 toLfLineEnding(outputStream.toString(StandardCharsets.UTF_8));
775 assertWithMessage("Content should match")
776 .that(actualContent)
777 .isEqualTo(expectedContent);
778 }
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799 private static void verifyCleanedMessageContent(
800 String expectedOutputFile,
801 ByteArrayOutputStream outputStream,
802 String basePath) throws IOException {
803 final String expectedContent = readFile(expectedOutputFile);
804 final String rawActualContent =
805 toLfLineEnding(outputStream.toString(StandardCharsets.UTF_8));
806
807 final String cleanedActualContent = rawActualContent.lines()
808 .filter(line -> {
809 return line.startsWith("[")
810 || line.contains("Starting audit...")
811 || line.contains("Audit done.");
812 })
813 .map(line -> line.replace(basePath, ""))
814 .map(line -> line.replace('\\', '/'))
815 .collect(Collectors.joining("\n", "", "\n"));
816
817 assertWithMessage("Content should match")
818 .that(cleanedActualContent)
819 .isEqualTo(expectedContent);
820 }
821
822
823
824
825
826
827
828
829
830 private List<String> getActualViolationsForFile(Configuration config,
831 String file) throws Exception {
832 stream.flush();
833 stream.reset();
834 final List<File> files = Collections.singletonList(new File(file));
835 final Checker checker = createChecker(config);
836 checker.process(files);
837 final Map<String, List<String>> actualViolations =
838 getActualViolations();
839 checker.destroy();
840 return actualViolations.getOrDefault(file, new ArrayList<>());
841 }
842
843
844
845
846
847
848
849
850
851 private Map<String, List<String>> getActualViolations() throws IOException {
852
853 try (ByteArrayInputStream inputStream =
854 new ByteArrayInputStream(stream.toByteArray());
855 LineNumberReader lnr = new LineNumberReader(
856 new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
857 final Map<String, List<String>> actualViolations = new HashMap<>();
858 for (String line = lnr.readLine(); line != null;
859 line = lnr.readLine()) {
860 if ("Audit done.".equals(line) || line.contains("at com")) {
861 break;
862 }
863
864
865 final String[] actualViolation = line.split("(?<=.{2}):", 2);
866 final String actualViolationFileName = actualViolation[0];
867 final String actualViolationMessage = actualViolation[1];
868
869 actualViolations
870 .computeIfAbsent(actualViolationFileName, key -> new ArrayList<>())
871 .add(actualViolationMessage);
872 }
873
874 return actualViolations;
875 }
876 }
877
878
879
880
881
882
883
884
885
886 protected final String getCheckMessage(String messageKey, Object... arguments) {
887 return internalGetCheckMessage(getMessageBundle(), messageKey, arguments);
888 }
889
890
891
892
893
894
895
896
897
898
899 protected static String getCheckMessage(
900 Class<?> clazz, String messageKey, Object... arguments) {
901 return internalGetCheckMessage(getMessageBundle(clazz.getName()), messageKey, arguments);
902 }
903
904
905
906
907
908
909
910
911
912
913 private static String internalGetCheckMessage(
914 String messageBundle, String messageKey, Object... arguments) {
915 final ResourceBundle resourceBundle = ResourceBundle.getBundle(
916 messageBundle,
917 Locale.ROOT,
918 Thread.currentThread().getContextClassLoader(),
919 new Utf8Control());
920 final String pattern = resourceBundle.getString(messageKey);
921 final MessageFormat formatter = new MessageFormat(pattern, Locale.ROOT);
922 return formatter.format(arguments);
923 }
924
925
926
927
928
929
930 private String getMessageBundle() {
931 final String className = getClass().getName();
932 return getMessageBundle(className);
933 }
934
935
936
937
938
939
940
941 private static String getMessageBundle(String className) {
942 final String messageBundle;
943 final String messages = "messages";
944 final int endIndex = className.lastIndexOf('.');
945 final Map<String, String> messageBundleMappings = new HashMap<>();
946 messageBundleMappings.put("SeverityMatchFilterExamplesTest",
947 "com.puppycrawl.tools.checkstyle.checks.naming.messages");
948
949 if (endIndex < 0) {
950 messageBundle = messages;
951 }
952 else {
953 final String packageName = className.substring(0, endIndex);
954 if ("com.puppycrawl.tools.checkstyle.filters".equals(packageName)) {
955 messageBundle = messageBundleMappings.get(className.substring(endIndex + 1));
956 }
957 else {
958 messageBundle = packageName + "." + messages;
959 }
960 }
961 return messageBundle;
962 }
963
964
965
966
967
968
969
970
971 protected static String[] removeSuppressed(String[] actualViolations,
972 String... suppressedViolations) {
973 final List<String> actualViolationsList =
974 Arrays.stream(actualViolations).collect(Collectors.toCollection(ArrayList::new));
975 actualViolationsList.removeAll(Arrays.asList(suppressedViolations));
976 return actualViolationsList.toArray(CommonUtil.EMPTY_STRING_ARRAY);
977 }
978
979 }