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 java.io.IOException;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.HashSet;
26 import java.util.LinkedHashSet;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Map.Entry;
30 import java.util.Set;
31 import java.util.function.Supplier;
32 import java.util.stream.Collectors;
33 import java.util.stream.Stream;
34
35 import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
36 import com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 public class PackageObjectFactory implements ModuleFactory {
53
54
55
56
57 public enum ModuleLoadOption {
58
59
60
61
62 SEARCH_REGISTERED_PACKAGES,
63
64
65
66
67
68 TRY_IN_ALL_REGISTERED_PACKAGES,
69
70 }
71
72
73 public static final String BASE_PACKAGE = "com.puppycrawl.tools.checkstyle";
74
75
76 public static final String UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE =
77 "PackageObjectFactory.unableToInstantiateExceptionMessage";
78
79
80 public static final String AMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGE =
81 "PackageObjectFactory.ambiguousModuleNameExceptionMessage";
82
83
84 public static final String CHECK_SUFFIX = "Check";
85
86
87 public static final String PACKAGE_SEPARATOR = ".";
88
89
90 public static final String NULL_LOADER_MESSAGE = "moduleClassLoader must not be null";
91
92
93 public static final String NULL_PACKAGE_MESSAGE = "package name must not be null";
94
95
96 public static final String STRING_SEPARATOR = ", ";
97
98
99 private static final Map<String, String> NAME_TO_FULL_MODULE_NAME = new HashMap<>();
100
101
102 private final Set<String> packages;
103
104
105 private final ClassLoader moduleClassLoader;
106
107
108 private Map<String, Set<String>> thirdPartyNameToFullModuleNames;
109
110
111 private ModuleLoadOption moduleLoadOption;
112
113 static {
114 fillShortToFullModuleNamesMap();
115 }
116
117
118
119
120
121
122
123
124 public PackageObjectFactory(Set<String> packageNames, ClassLoader moduleClassLoader) {
125 this(packageNames, moduleClassLoader, ModuleLoadOption.SEARCH_REGISTERED_PACKAGES);
126 }
127
128
129
130
131
132
133
134
135
136
137 public PackageObjectFactory(Set<String> packageNames, ClassLoader moduleClassLoader,
138 ModuleLoadOption moduleLoadOption) {
139 if (moduleClassLoader == null) {
140 throw new IllegalArgumentException(NULL_LOADER_MESSAGE);
141 }
142 if (packageNames.contains(null)) {
143 throw new IllegalArgumentException(NULL_PACKAGE_MESSAGE);
144 }
145
146
147 packages = new LinkedHashSet<>(packageNames);
148 this.moduleClassLoader = moduleClassLoader;
149 this.moduleLoadOption = moduleLoadOption;
150 }
151
152
153
154
155
156
157
158
159
160 public PackageObjectFactory(String packageName, ClassLoader moduleClassLoader) {
161 if (moduleClassLoader == null) {
162 throw new IllegalArgumentException(NULL_LOADER_MESSAGE);
163 }
164 if (packageName == null) {
165 throw new IllegalArgumentException(NULL_PACKAGE_MESSAGE);
166 }
167
168 packages = Collections.singleton(packageName);
169 this.moduleClassLoader = moduleClassLoader;
170 }
171
172
173
174
175
176
177
178
179
180
181
182
183 @Override
184 public Object createModule(String name) throws CheckstyleException {
185 Object instance = null;
186
187 if (!name.contains(PACKAGE_SEPARATOR)) {
188 instance = createFromStandardCheckSet(name);
189
190 if (instance == null) {
191 instance = createObjectFromClassPath(name);
192 }
193 }
194 if (instance == null) {
195 instance = createObject(name);
196 }
197 if (instance == null
198 && moduleLoadOption == ModuleLoadOption.TRY_IN_ALL_REGISTERED_PACKAGES) {
199 instance = createModuleByTryInEachPackage(name);
200 }
201 if (instance == null) {
202 String attemptedNames = null;
203 if (!name.contains(PACKAGE_SEPARATOR)) {
204 final String nameCheck = name + CHECK_SUFFIX;
205 attemptedNames = joinPackageNamesWithClassName(name, packages)
206 + STRING_SEPARATOR + nameCheck + STRING_SEPARATOR
207 + joinPackageNamesWithClassName(nameCheck, packages);
208 }
209 final LocalizedMessage exceptionMessage = new LocalizedMessage(
210 Definitions.CHECKSTYLE_BUNDLE, getClass(),
211 UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE, name, attemptedNames);
212 throw new CheckstyleException(exceptionMessage.getMessage());
213 }
214 return instance;
215 }
216
217
218
219
220
221
222
223
224 private Object createFromStandardCheckSet(String name) throws CheckstyleException {
225 final String fullModuleName = NAME_TO_FULL_MODULE_NAME.get(name);
226 Object instance = null;
227 if (fullModuleName == null) {
228 final String fullCheckModuleName =
229 NAME_TO_FULL_MODULE_NAME.get(name + CHECK_SUFFIX);
230 if (fullCheckModuleName != null) {
231 instance = createObject(fullCheckModuleName);
232 }
233 }
234 else {
235 instance = createObject(fullModuleName);
236 }
237 return instance;
238 }
239
240
241
242
243
244
245
246
247 private Object createObjectFromClassPath(String name)
248 throws CheckstyleException {
249 thirdPartyNameToFullModuleNames = lazyLoad(
250 thirdPartyNameToFullModuleNames,
251 () -> generateThirdPartyNameToFullModuleName(moduleClassLoader)
252 );
253 final Set<String> fullModuleNames = thirdPartyNameToFullModuleNames.get(name);
254 Object instance = null;
255 if (fullModuleNames == null) {
256 final Set<String> fullCheckModuleNames =
257 thirdPartyNameToFullModuleNames.get(name + CHECK_SUFFIX);
258 if (fullCheckModuleNames != null) {
259 instance = createObjectFromFullModuleNames(name, fullCheckModuleNames);
260 }
261 }
262 else {
263 instance = createObjectFromFullModuleNames(name, fullModuleNames);
264 }
265 return instance;
266 }
267
268
269
270
271
272
273
274
275
276
277
278
279 private Object createObjectFromFullModuleNames(String name, Set<String> fullModuleNames)
280 throws CheckstyleException {
281 final Object returnValue;
282 if (fullModuleNames.size() == 1) {
283 returnValue = createObject(fullModuleNames.iterator().next());
284 }
285 else {
286 final String optionalNames = fullModuleNames.stream()
287 .sorted()
288 .collect(Collectors.joining(STRING_SEPARATOR));
289 final LocalizedMessage exceptionMessage = new LocalizedMessage(
290 Definitions.CHECKSTYLE_BUNDLE, getClass(),
291 AMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGE, name, optionalNames);
292 throw new CheckstyleException(exceptionMessage.getMessage());
293 }
294 return returnValue;
295 }
296
297
298
299
300
301
302
303
304
305 private Map<String, Set<String>> generateThirdPartyNameToFullModuleName(ClassLoader loader) {
306 Map<String, Set<String>> returnValue;
307 try {
308 returnValue = ModuleReflectionUtil.getCheckstyleModules(packages, loader).stream()
309 .collect(Collectors.groupingBy(Class::getSimpleName,
310 Collectors.mapping(
311 Class::getCanonicalName,
312 Collectors.toCollection(HashSet::new))));
313 }
314 catch (IOException ignore) {
315 returnValue = Collections.emptyMap();
316 }
317 return returnValue;
318 }
319
320
321
322
323
324
325
326 public static String getShortFromFullModuleNames(String fullName) {
327 return NAME_TO_FULL_MODULE_NAME
328 .entrySet()
329 .stream()
330 .filter(entry -> entry.getValue().equals(fullName))
331 .map(Entry::getKey)
332 .findFirst()
333 .orElse(fullName);
334 }
335
336
337
338
339
340
341
342
343 private static String joinPackageNamesWithClassName(String className, Set<String> packages) {
344 return packages.stream().collect(
345 Collectors.joining(PACKAGE_SEPARATOR + className + STRING_SEPARATOR, "",
346 PACKAGE_SEPARATOR + className));
347 }
348
349
350
351
352
353
354
355
356 private Object createObject(String className) throws CheckstyleException {
357 Class<?> clazz = null;
358
359 try {
360 clazz = Class.forName(className, true, moduleClassLoader);
361 }
362 catch (final ReflectiveOperationException | NoClassDefFoundError ignored) {
363
364 }
365
366 Object instance = null;
367
368 if (clazz != null) {
369 try {
370 instance = clazz.getDeclaredConstructor().newInstance();
371 }
372 catch (final ReflectiveOperationException ex) {
373 throw new CheckstyleException("Unable to instantiate " + className, ex);
374 }
375 }
376
377 return instance;
378 }
379
380
381
382
383
384
385
386
387
388 private Object createModuleByTryInEachPackage(String name) throws CheckstyleException {
389 final List<String> possibleNames = packages.stream()
390 .map(packageName -> packageName + PACKAGE_SEPARATOR + name)
391 .flatMap(className -> Stream.of(className, className + CHECK_SUFFIX))
392 .collect(Collectors.toUnmodifiableList());
393 Object instance = null;
394 for (String possibleName : possibleNames) {
395 instance = createObject(possibleName);
396 if (instance != null) {
397 break;
398 }
399 }
400 return instance;
401 }
402
403
404
405
406
407
408
409
410
411 private static <T> T lazyLoad(T object, Supplier<T> supplier) {
412 final T result;
413 if (object == null) {
414 result = supplier.get();
415 }
416 else {
417 result = object;
418 }
419 return result;
420 }
421
422
423
424
425 private static void fillShortToFullModuleNamesMap() {
426 fillChecksFromAnnotationPackage();
427 fillChecksFromBlocksPackage();
428 fillChecksFromCodingPackage();
429 fillChecksFromDesignPackage();
430 fillChecksFromHeaderPackage();
431 fillChecksFromImportsPackage();
432 fillChecksFromIndentationPackage();
433 fillChecksFromJavadocPackage();
434 fillChecksFromMetricsPackage();
435 fillChecksFromModifierPackage();
436 fillChecksFromNamingPackage();
437 fillChecksFromRegexpPackage();
438 fillChecksFromSizesPackage();
439 fillChecksFromWhitespacePackage();
440 fillModulesFromChecksPackage();
441 fillModulesFromFilefiltersPackage();
442 fillModulesFromFiltersPackage();
443 fillModulesFromCheckstylePackage();
444 }
445
446
447
448
449 private static void fillChecksFromAnnotationPackage() {
450 NAME_TO_FULL_MODULE_NAME.put("AnnotationLocationCheck",
451 BASE_PACKAGE + ".checks.annotation.AnnotationLocationCheck");
452 NAME_TO_FULL_MODULE_NAME.put("AnnotationOnSameLineCheck",
453 BASE_PACKAGE + ".checks.annotation.AnnotationOnSameLineCheck");
454 NAME_TO_FULL_MODULE_NAME.put("AnnotationUseStyleCheck",
455 BASE_PACKAGE + ".checks.annotation.AnnotationUseStyleCheck");
456 NAME_TO_FULL_MODULE_NAME.put("MissingDeprecatedCheck",
457 BASE_PACKAGE + ".checks.annotation.MissingDeprecatedCheck");
458 NAME_TO_FULL_MODULE_NAME.put("MissingOverrideCheck",
459 BASE_PACKAGE + ".checks.annotation.MissingOverrideCheck");
460 NAME_TO_FULL_MODULE_NAME.put("PackageAnnotationCheck",
461 BASE_PACKAGE + ".checks.annotation.PackageAnnotationCheck");
462 NAME_TO_FULL_MODULE_NAME.put("SuppressWarningsCheck",
463 BASE_PACKAGE + ".checks.annotation.SuppressWarningsCheck");
464 }
465
466
467
468
469 private static void fillChecksFromBlocksPackage() {
470 NAME_TO_FULL_MODULE_NAME.put("AvoidNestedBlocksCheck",
471 BASE_PACKAGE + ".checks.blocks.AvoidNestedBlocksCheck");
472 NAME_TO_FULL_MODULE_NAME.put("EmptyBlockCheck",
473 BASE_PACKAGE + ".checks.blocks.EmptyBlockCheck");
474 NAME_TO_FULL_MODULE_NAME.put("EmptyCatchBlockCheck",
475 BASE_PACKAGE + ".checks.blocks.EmptyCatchBlockCheck");
476 NAME_TO_FULL_MODULE_NAME.put("LeftCurlyCheck",
477 BASE_PACKAGE + ".checks.blocks.LeftCurlyCheck");
478 NAME_TO_FULL_MODULE_NAME.put("NeedBracesCheck",
479 BASE_PACKAGE + ".checks.blocks.NeedBracesCheck");
480 NAME_TO_FULL_MODULE_NAME.put("RightCurlyCheck",
481 BASE_PACKAGE + ".checks.blocks.RightCurlyCheck");
482 }
483
484
485
486
487
488
489 private static void fillChecksFromCodingPackage() {
490 NAME_TO_FULL_MODULE_NAME.put("ArrayTrailingCommaCheck",
491 BASE_PACKAGE + ".checks.coding.ArrayTrailingCommaCheck");
492 NAME_TO_FULL_MODULE_NAME.put("AvoidDoubleBraceInitializationCheck",
493 BASE_PACKAGE + ".checks.coding.AvoidDoubleBraceInitializationCheck");
494 NAME_TO_FULL_MODULE_NAME.put("AvoidInlineConditionalsCheck",
495 BASE_PACKAGE + ".checks.coding.AvoidInlineConditionalsCheck");
496 NAME_TO_FULL_MODULE_NAME.put("AvoidNoArgumentSuperConstructorCallCheck",
497 BASE_PACKAGE + ".checks.coding.AvoidNoArgumentSuperConstructorCallCheck");
498 NAME_TO_FULL_MODULE_NAME.put("ConstructorsDeclarationGroupingCheck",
499 BASE_PACKAGE + ".checks.coding.ConstructorsDeclarationGroupingCheck");
500 NAME_TO_FULL_MODULE_NAME.put("CovariantEqualsCheck",
501 BASE_PACKAGE + ".checks.coding.CovariantEqualsCheck");
502 NAME_TO_FULL_MODULE_NAME.put("DeclarationOrderCheck",
503 BASE_PACKAGE + ".checks.coding.DeclarationOrderCheck");
504 NAME_TO_FULL_MODULE_NAME.put("DefaultComesLastCheck",
505 BASE_PACKAGE + ".checks.coding.DefaultComesLastCheck");
506 NAME_TO_FULL_MODULE_NAME.put("EmptyStatementCheck",
507 BASE_PACKAGE + ".checks.coding.EmptyStatementCheck");
508 NAME_TO_FULL_MODULE_NAME.put("EqualsAvoidNullCheck",
509 BASE_PACKAGE + ".checks.coding.EqualsAvoidNullCheck");
510 NAME_TO_FULL_MODULE_NAME.put("EqualsHashCodeCheck",
511 BASE_PACKAGE + ".checks.coding.EqualsHashCodeCheck");
512 NAME_TO_FULL_MODULE_NAME.put("ExplicitInitializationCheck",
513 BASE_PACKAGE + ".checks.coding.ExplicitInitializationCheck");
514 NAME_TO_FULL_MODULE_NAME.put("FallThroughCheck",
515 BASE_PACKAGE + ".checks.coding.FallThroughCheck");
516 NAME_TO_FULL_MODULE_NAME.put("FinalLocalVariableCheck",
517 BASE_PACKAGE + ".checks.coding.FinalLocalVariableCheck");
518 NAME_TO_FULL_MODULE_NAME.put("HiddenFieldCheck",
519 BASE_PACKAGE + ".checks.coding.HiddenFieldCheck");
520 NAME_TO_FULL_MODULE_NAME.put("IllegalCatchCheck",
521 BASE_PACKAGE + ".checks.coding.IllegalCatchCheck");
522 NAME_TO_FULL_MODULE_NAME.put("IllegalInstantiationCheck",
523 BASE_PACKAGE + ".checks.coding.IllegalInstantiationCheck");
524 NAME_TO_FULL_MODULE_NAME.put("IllegalThrowsCheck",
525 BASE_PACKAGE + ".checks.coding.IllegalThrowsCheck");
526 NAME_TO_FULL_MODULE_NAME.put("IllegalTokenCheck",
527 BASE_PACKAGE + ".checks.coding.IllegalTokenCheck");
528 NAME_TO_FULL_MODULE_NAME.put("IllegalTokenTextCheck",
529 BASE_PACKAGE + ".checks.coding.IllegalTokenTextCheck");
530 NAME_TO_FULL_MODULE_NAME.put("IllegalTypeCheck",
531 BASE_PACKAGE + ".checks.coding.IllegalTypeCheck");
532 NAME_TO_FULL_MODULE_NAME.put("InnerAssignmentCheck",
533 BASE_PACKAGE + ".checks.coding.InnerAssignmentCheck");
534 NAME_TO_FULL_MODULE_NAME.put("MagicNumberCheck",
535 BASE_PACKAGE + ".checks.coding.MagicNumberCheck");
536 NAME_TO_FULL_MODULE_NAME.put("MissingCtorCheck",
537 BASE_PACKAGE + ".checks.coding.MissingCtorCheck");
538 NAME_TO_FULL_MODULE_NAME.put("MissingNullCaseInSwitchCheck",
539 BASE_PACKAGE + ".checks.coding.MissingNullCaseInSwitchCheck");
540 NAME_TO_FULL_MODULE_NAME.put("MissingSwitchDefaultCheck",
541 BASE_PACKAGE + ".checks.coding.MissingSwitchDefaultCheck");
542 NAME_TO_FULL_MODULE_NAME.put("ModifiedControlVariableCheck",
543 BASE_PACKAGE + ".checks.coding.ModifiedControlVariableCheck");
544 NAME_TO_FULL_MODULE_NAME.put("MultipleStringLiteralsCheck",
545 BASE_PACKAGE + ".checks.coding.MultipleStringLiteralsCheck");
546 NAME_TO_FULL_MODULE_NAME.put("MultipleVariableDeclarationsCheck",
547 BASE_PACKAGE + ".checks.coding.MultipleVariableDeclarationsCheck");
548 NAME_TO_FULL_MODULE_NAME.put("NestedForDepthCheck",
549 BASE_PACKAGE + ".checks.coding.NestedForDepthCheck");
550 NAME_TO_FULL_MODULE_NAME.put("NestedIfDepthCheck",
551 BASE_PACKAGE + ".checks.coding.NestedIfDepthCheck");
552 NAME_TO_FULL_MODULE_NAME.put("NestedTryDepthCheck",
553 BASE_PACKAGE + ".checks.coding.NestedTryDepthCheck");
554 NAME_TO_FULL_MODULE_NAME.put("NoCloneCheck",
555 BASE_PACKAGE + ".checks.coding.NoCloneCheck");
556 NAME_TO_FULL_MODULE_NAME.put("NoEnumTrailingCommaCheck",
557 BASE_PACKAGE + ".checks.coding.NoEnumTrailingCommaCheck");
558 NAME_TO_FULL_MODULE_NAME.put("NoFinalizerCheck",
559 BASE_PACKAGE + ".checks.coding.NoFinalizerCheck");
560 NAME_TO_FULL_MODULE_NAME.put("OneStatementPerLineCheck",
561 BASE_PACKAGE + ".checks.coding.OneStatementPerLineCheck");
562 NAME_TO_FULL_MODULE_NAME.put("OverloadMethodsDeclarationOrderCheck",
563 BASE_PACKAGE + ".checks.coding.OverloadMethodsDeclarationOrderCheck");
564 NAME_TO_FULL_MODULE_NAME.put("PackageDeclarationCheck",
565 BASE_PACKAGE + ".checks.coding.PackageDeclarationCheck");
566 NAME_TO_FULL_MODULE_NAME.put("ParameterAssignmentCheck",
567 BASE_PACKAGE + ".checks.coding.ParameterAssignmentCheck");
568 NAME_TO_FULL_MODULE_NAME.put("RequireThisCheck",
569 BASE_PACKAGE + ".checks.coding.RequireThisCheck");
570 NAME_TO_FULL_MODULE_NAME.put("ReturnCountCheck",
571 BASE_PACKAGE + ".checks.coding.ReturnCountCheck");
572 NAME_TO_FULL_MODULE_NAME.put("SimplifyBooleanExpressionCheck",
573 BASE_PACKAGE + ".checks.coding.SimplifyBooleanExpressionCheck");
574 NAME_TO_FULL_MODULE_NAME.put("SimplifyBooleanReturnCheck",
575 BASE_PACKAGE + ".checks.coding.SimplifyBooleanReturnCheck");
576 NAME_TO_FULL_MODULE_NAME.put("StringLiteralEqualityCheck",
577 BASE_PACKAGE + ".checks.coding.StringLiteralEqualityCheck");
578 NAME_TO_FULL_MODULE_NAME.put("SuperCloneCheck",
579 BASE_PACKAGE + ".checks.coding.SuperCloneCheck");
580 NAME_TO_FULL_MODULE_NAME.put("SuperFinalizeCheck",
581 BASE_PACKAGE + ".checks.coding.SuperFinalizeCheck");
582 NAME_TO_FULL_MODULE_NAME.put("UnnecessaryParenthesesCheck",
583 BASE_PACKAGE + ".checks.coding.UnnecessaryParenthesesCheck");
584 NAME_TO_FULL_MODULE_NAME.put("UnnecessarySemicolonAfterOuterTypeDeclarationCheck",
585 BASE_PACKAGE
586 + ".checks.coding.UnnecessarySemicolonAfterOuterTypeDeclarationCheck");
587 NAME_TO_FULL_MODULE_NAME.put("UnnecessarySemicolonAfterTypeMemberDeclarationCheck",
588 BASE_PACKAGE
589 + ".checks.coding.UnnecessarySemicolonAfterTypeMemberDeclarationCheck");
590 NAME_TO_FULL_MODULE_NAME.put("UnnecessarySemicolonInEnumerationCheck",
591 BASE_PACKAGE + ".checks.coding.UnnecessarySemicolonInEnumerationCheck");
592 NAME_TO_FULL_MODULE_NAME.put("UnnecessarySemicolonInTryWithResourcesCheck",
593 BASE_PACKAGE + ".checks.coding.UnnecessarySemicolonInTryWithResourcesCheck");
594 NAME_TO_FULL_MODULE_NAME.put("VariableDeclarationUsageDistanceCheck",
595 BASE_PACKAGE + ".checks.coding.VariableDeclarationUsageDistanceCheck");
596 NAME_TO_FULL_MODULE_NAME.put("WhenShouldBeUsed",
597 BASE_PACKAGE + ".checks.coding.WhenShouldBeUsedCheck");
598 NAME_TO_FULL_MODULE_NAME.put("NoArrayTrailingCommaCheck",
599 BASE_PACKAGE + ".checks.coding.NoArrayTrailingCommaCheck");
600 NAME_TO_FULL_MODULE_NAME.put("MatchXpathCheck",
601 BASE_PACKAGE + ".checks.coding.MatchXpathCheck");
602 NAME_TO_FULL_MODULE_NAME.put("UnusedLocalVariableCheck",
603 BASE_PACKAGE + ".checks.coding.UnusedLocalVariableCheck");
604 NAME_TO_FULL_MODULE_NAME.put("UnusedCatchParameterShouldBeUnnamedCheck",
605 BASE_PACKAGE + ".checks.coding.UnusedCatchParameterShouldBeUnnamedCheck");
606 NAME_TO_FULL_MODULE_NAME.put("UnusedLambdaParameterShouldBeUnnamedCheck",
607 BASE_PACKAGE + ".checks.coding.UnusedLambdaParameterShouldBeUnnamedCheck");
608 }
609
610
611
612
613 private static void fillChecksFromDesignPackage() {
614 NAME_TO_FULL_MODULE_NAME.put("DesignForExtensionCheck",
615 BASE_PACKAGE + ".checks.design.DesignForExtensionCheck");
616 NAME_TO_FULL_MODULE_NAME.put("FinalClassCheck",
617 BASE_PACKAGE + ".checks.design.FinalClassCheck");
618 NAME_TO_FULL_MODULE_NAME.put("HideUtilityClassConstructorCheck",
619 BASE_PACKAGE + ".checks.design.HideUtilityClassConstructorCheck");
620 NAME_TO_FULL_MODULE_NAME.put("InnerTypeLastCheck",
621 BASE_PACKAGE + ".checks.design.InnerTypeLastCheck");
622 NAME_TO_FULL_MODULE_NAME.put("InterfaceIsTypeCheck",
623 BASE_PACKAGE + ".checks.design.InterfaceIsTypeCheck");
624 NAME_TO_FULL_MODULE_NAME.put("MutableExceptionCheck",
625 BASE_PACKAGE + ".checks.design.MutableExceptionCheck");
626 NAME_TO_FULL_MODULE_NAME.put("OneTopLevelClassCheck",
627 BASE_PACKAGE + ".checks.design.OneTopLevelClassCheck");
628 NAME_TO_FULL_MODULE_NAME.put("SealedShouldHavePermitsListCheck",
629 BASE_PACKAGE + ".checks.design.SealedShouldHavePermitsListCheck");
630 NAME_TO_FULL_MODULE_NAME.put("ThrowsCountCheck",
631 BASE_PACKAGE + ".checks.design.ThrowsCountCheck");
632 NAME_TO_FULL_MODULE_NAME.put("VisibilityModifierCheck",
633 BASE_PACKAGE + ".checks.design.VisibilityModifierCheck");
634 }
635
636
637
638
639 private static void fillChecksFromHeaderPackage() {
640 NAME_TO_FULL_MODULE_NAME.put("HeaderCheck",
641 BASE_PACKAGE + ".checks.header.HeaderCheck");
642 NAME_TO_FULL_MODULE_NAME.put("RegexpHeaderCheck",
643 BASE_PACKAGE + ".checks.header.RegexpHeaderCheck");
644 }
645
646
647
648
649 private static void fillChecksFromImportsPackage() {
650 NAME_TO_FULL_MODULE_NAME.put("AvoidStarImportCheck",
651 BASE_PACKAGE + ".checks.imports.AvoidStarImportCheck");
652 NAME_TO_FULL_MODULE_NAME.put("AvoidStaticImportCheck",
653 BASE_PACKAGE + ".checks.imports.AvoidStaticImportCheck");
654 NAME_TO_FULL_MODULE_NAME.put("CustomImportOrderCheck",
655 BASE_PACKAGE + ".checks.imports.CustomImportOrderCheck");
656 NAME_TO_FULL_MODULE_NAME.put("IllegalImportCheck",
657 BASE_PACKAGE + ".checks.imports.IllegalImportCheck");
658 NAME_TO_FULL_MODULE_NAME.put("ImportControlCheck",
659 BASE_PACKAGE + ".checks.imports.ImportControlCheck");
660 NAME_TO_FULL_MODULE_NAME.put("ImportOrderCheck",
661 BASE_PACKAGE + ".checks.imports.ImportOrderCheck");
662 NAME_TO_FULL_MODULE_NAME.put("RedundantImportCheck",
663 BASE_PACKAGE + ".checks.imports.RedundantImportCheck");
664 NAME_TO_FULL_MODULE_NAME.put("UnusedImportsCheck",
665 BASE_PACKAGE + ".checks.imports.UnusedImportsCheck");
666 }
667
668
669
670
671 private static void fillChecksFromIndentationPackage() {
672 NAME_TO_FULL_MODULE_NAME.put("CommentsIndentationCheck",
673 BASE_PACKAGE + ".checks.indentation.CommentsIndentationCheck");
674 NAME_TO_FULL_MODULE_NAME.put("IndentationCheck",
675 BASE_PACKAGE + ".checks.indentation.IndentationCheck");
676 }
677
678
679
680
681 private static void fillChecksFromJavadocPackage() {
682 NAME_TO_FULL_MODULE_NAME.put("AtclauseOrderCheck",
683 BASE_PACKAGE + ".checks.javadoc.AtclauseOrderCheck");
684 NAME_TO_FULL_MODULE_NAME.put("InvalidJavadocPositionCheck",
685 BASE_PACKAGE + ".checks.javadoc.InvalidJavadocPositionCheck");
686 NAME_TO_FULL_MODULE_NAME.put("JavadocBlockTagLocationCheck",
687 BASE_PACKAGE + ".checks.javadoc.JavadocBlockTagLocationCheck");
688 NAME_TO_FULL_MODULE_NAME.put("JavadocContentLocationCheck",
689 BASE_PACKAGE + ".checks.javadoc.JavadocContentLocationCheck");
690 NAME_TO_FULL_MODULE_NAME.put("JavadocLeadingAsteriskAlignCheck",
691 BASE_PACKAGE + ".checks.javadoc.JavadocLeadingAsteriskAlignCheck");
692 NAME_TO_FULL_MODULE_NAME.put("JavadocMethodCheck",
693 BASE_PACKAGE + ".checks.javadoc.JavadocMethodCheck");
694 NAME_TO_FULL_MODULE_NAME.put("JavadocMissingLeadingAsteriskCheck",
695 BASE_PACKAGE + ".checks.javadoc.JavadocMissingLeadingAsteriskCheck");
696 NAME_TO_FULL_MODULE_NAME.put("JavadocMissingWhitespaceAfterAsteriskCheck",
697 BASE_PACKAGE + ".checks.javadoc.JavadocMissingWhitespaceAfterAsteriskCheck");
698 NAME_TO_FULL_MODULE_NAME.put("JavadocPackageCheck",
699 BASE_PACKAGE + ".checks.javadoc.JavadocPackageCheck");
700 NAME_TO_FULL_MODULE_NAME.put("JavadocParagraphCheck",
701 BASE_PACKAGE + ".checks.javadoc.JavadocParagraphCheck");
702 NAME_TO_FULL_MODULE_NAME.put("JavadocStyleCheck",
703 BASE_PACKAGE + ".checks.javadoc.JavadocStyleCheck");
704 NAME_TO_FULL_MODULE_NAME.put("JavadocTagContinuationIndentationCheck",
705 BASE_PACKAGE + ".checks.javadoc.JavadocTagContinuationIndentationCheck");
706 NAME_TO_FULL_MODULE_NAME.put("JavadocTypeCheck",
707 BASE_PACKAGE + ".checks.javadoc.JavadocTypeCheck");
708 NAME_TO_FULL_MODULE_NAME.put("JavadocVariableCheck",
709 BASE_PACKAGE + ".checks.javadoc.JavadocVariableCheck");
710 NAME_TO_FULL_MODULE_NAME.put("MissingJavadocMethodCheck",
711 BASE_PACKAGE + ".checks.javadoc.MissingJavadocMethodCheck");
712 NAME_TO_FULL_MODULE_NAME.put("MissingJavadocPackageCheck",
713 BASE_PACKAGE + ".checks.javadoc.MissingJavadocPackageCheck");
714 NAME_TO_FULL_MODULE_NAME.put("MissingJavadocTypeCheck",
715 BASE_PACKAGE + ".checks.javadoc.MissingJavadocTypeCheck");
716 NAME_TO_FULL_MODULE_NAME.put("NonEmptyAtclauseDescriptionCheck",
717 BASE_PACKAGE + ".checks.javadoc.NonEmptyAtclauseDescriptionCheck");
718 NAME_TO_FULL_MODULE_NAME.put("RequireEmptyLineBeforeBlockTagGroupCheck",
719 BASE_PACKAGE + ".checks.javadoc.RequireEmptyLineBeforeBlockTagGroupCheck");
720 NAME_TO_FULL_MODULE_NAME.put("SingleLineJavadocCheck",
721 BASE_PACKAGE + ".checks.javadoc.SingleLineJavadocCheck");
722 NAME_TO_FULL_MODULE_NAME.put("SummaryJavadocCheck",
723 BASE_PACKAGE + ".checks.javadoc.SummaryJavadocCheck");
724 NAME_TO_FULL_MODULE_NAME.put("WriteTagCheck",
725 BASE_PACKAGE + ".checks.javadoc.WriteTagCheck");
726 }
727
728
729
730
731 private static void fillChecksFromMetricsPackage() {
732 NAME_TO_FULL_MODULE_NAME.put("BooleanExpressionComplexityCheck",
733 BASE_PACKAGE + ".checks.metrics.BooleanExpressionComplexityCheck");
734 NAME_TO_FULL_MODULE_NAME.put("ClassDataAbstractionCouplingCheck",
735 BASE_PACKAGE + ".checks.metrics.ClassDataAbstractionCouplingCheck");
736 NAME_TO_FULL_MODULE_NAME.put("ClassFanOutComplexityCheck",
737 BASE_PACKAGE + ".checks.metrics.ClassFanOutComplexityCheck");
738 NAME_TO_FULL_MODULE_NAME.put("CyclomaticComplexityCheck",
739 BASE_PACKAGE + ".checks.metrics.CyclomaticComplexityCheck");
740 NAME_TO_FULL_MODULE_NAME.put("JavaNCSSCheck",
741 BASE_PACKAGE + ".checks.metrics.JavaNCSSCheck");
742 NAME_TO_FULL_MODULE_NAME.put("NPathComplexityCheck",
743 BASE_PACKAGE + ".checks.metrics.NPathComplexityCheck");
744 }
745
746
747
748
749 private static void fillChecksFromModifierPackage() {
750 NAME_TO_FULL_MODULE_NAME.put("ClassMemberImpliedModifierCheck",
751 BASE_PACKAGE + ".checks.modifier.ClassMemberImpliedModifierCheck");
752 NAME_TO_FULL_MODULE_NAME.put("InterfaceMemberImpliedModifierCheck",
753 BASE_PACKAGE + ".checks.modifier.InterfaceMemberImpliedModifierCheck");
754 NAME_TO_FULL_MODULE_NAME.put("ModifierOrderCheck",
755 BASE_PACKAGE + ".checks.modifier.ModifierOrderCheck");
756 NAME_TO_FULL_MODULE_NAME.put("RedundantModifierCheck",
757 BASE_PACKAGE + ".checks.modifier.RedundantModifierCheck");
758 }
759
760
761
762
763 private static void fillChecksFromNamingPackage() {
764 NAME_TO_FULL_MODULE_NAME.put("AbbreviationAsWordInNameCheck",
765 BASE_PACKAGE + ".checks.naming.AbbreviationAsWordInNameCheck");
766 NAME_TO_FULL_MODULE_NAME.put("AbstractClassNameCheck",
767 BASE_PACKAGE + ".checks.naming.AbstractClassNameCheck");
768 NAME_TO_FULL_MODULE_NAME.put("CatchParameterNameCheck",
769 BASE_PACKAGE + ".checks.naming.CatchParameterNameCheck");
770 NAME_TO_FULL_MODULE_NAME.put("ClassTypeParameterNameCheck",
771 BASE_PACKAGE + ".checks.naming.ClassTypeParameterNameCheck");
772 NAME_TO_FULL_MODULE_NAME.put("ConstantNameCheck",
773 BASE_PACKAGE + ".checks.naming.ConstantNameCheck");
774 NAME_TO_FULL_MODULE_NAME.put("InterfaceTypeParameterNameCheck",
775 BASE_PACKAGE + ".checks.naming.InterfaceTypeParameterNameCheck");
776 NAME_TO_FULL_MODULE_NAME.put("LambdaParameterNameCheck",
777 BASE_PACKAGE + ".checks.naming.LambdaParameterNameCheck");
778 NAME_TO_FULL_MODULE_NAME.put("LocalFinalVariableNameCheck",
779 BASE_PACKAGE + ".checks.naming.LocalFinalVariableNameCheck");
780 NAME_TO_FULL_MODULE_NAME.put("LocalVariableNameCheck",
781 BASE_PACKAGE + ".checks.naming.LocalVariableNameCheck");
782 NAME_TO_FULL_MODULE_NAME.put("MemberNameCheck",
783 BASE_PACKAGE + ".checks.naming.MemberNameCheck");
784 NAME_TO_FULL_MODULE_NAME.put("MethodNameCheck",
785 BASE_PACKAGE + ".checks.naming.MethodNameCheck");
786 NAME_TO_FULL_MODULE_NAME.put("MethodTypeParameterNameCheck",
787 BASE_PACKAGE + ".checks.naming.MethodTypeParameterNameCheck");
788 NAME_TO_FULL_MODULE_NAME.put("PackageNameCheck",
789 BASE_PACKAGE + ".checks.naming.PackageNameCheck");
790 NAME_TO_FULL_MODULE_NAME.put("ParameterNameCheck",
791 BASE_PACKAGE + ".checks.naming.ParameterNameCheck");
792 NAME_TO_FULL_MODULE_NAME.put("RecordComponentNameCheck",
793 BASE_PACKAGE + ".checks.naming.RecordComponentNameCheck");
794 NAME_TO_FULL_MODULE_NAME.put("RecordTypeParameterNameCheck",
795 BASE_PACKAGE + ".checks.naming.RecordTypeParameterNameCheck");
796 NAME_TO_FULL_MODULE_NAME.put("StaticVariableNameCheck",
797 BASE_PACKAGE + ".checks.naming.StaticVariableNameCheck");
798 NAME_TO_FULL_MODULE_NAME.put("TypeNameCheck",
799 BASE_PACKAGE + ".checks.naming.TypeNameCheck");
800 NAME_TO_FULL_MODULE_NAME.put("PatternVariableNameCheck",
801 BASE_PACKAGE + ".checks.naming.PatternVariableNameCheck");
802 NAME_TO_FULL_MODULE_NAME.put("IllegalIdentifierNameCheck",
803 BASE_PACKAGE + ".checks.naming.IllegalIdentifierNameCheck");
804 }
805
806
807
808
809 private static void fillChecksFromRegexpPackage() {
810 NAME_TO_FULL_MODULE_NAME.put("RegexpCheck",
811 BASE_PACKAGE + ".checks.regexp.RegexpCheck");
812 NAME_TO_FULL_MODULE_NAME.put("RegexpMultilineCheck",
813 BASE_PACKAGE + ".checks.regexp.RegexpMultilineCheck");
814 NAME_TO_FULL_MODULE_NAME.put("RegexpOnFilenameCheck",
815 BASE_PACKAGE + ".checks.regexp.RegexpOnFilenameCheck");
816 NAME_TO_FULL_MODULE_NAME.put("RegexpSinglelineCheck",
817 BASE_PACKAGE + ".checks.regexp.RegexpSinglelineCheck");
818 NAME_TO_FULL_MODULE_NAME.put("RegexpSinglelineJavaCheck",
819 BASE_PACKAGE + ".checks.regexp.RegexpSinglelineJavaCheck");
820 }
821
822
823
824
825 private static void fillChecksFromSizesPackage() {
826 NAME_TO_FULL_MODULE_NAME.put("AnonInnerLengthCheck",
827 BASE_PACKAGE + ".checks.sizes.AnonInnerLengthCheck");
828 NAME_TO_FULL_MODULE_NAME.put("ExecutableStatementCountCheck",
829 BASE_PACKAGE + ".checks.sizes.ExecutableStatementCountCheck");
830 NAME_TO_FULL_MODULE_NAME.put("FileLengthCheck",
831 BASE_PACKAGE + ".checks.sizes.FileLengthCheck");
832 NAME_TO_FULL_MODULE_NAME.put("LambdaBodyLengthCheck",
833 BASE_PACKAGE + ".checks.sizes.LambdaBodyLengthCheck");
834 NAME_TO_FULL_MODULE_NAME.put("LineLengthCheck",
835 BASE_PACKAGE + ".checks.sizes.LineLengthCheck");
836 NAME_TO_FULL_MODULE_NAME.put("MethodCountCheck",
837 BASE_PACKAGE + ".checks.sizes.MethodCountCheck");
838 NAME_TO_FULL_MODULE_NAME.put("MethodLengthCheck",
839 BASE_PACKAGE + ".checks.sizes.MethodLengthCheck");
840 NAME_TO_FULL_MODULE_NAME.put("OuterTypeNumberCheck",
841 BASE_PACKAGE + ".checks.sizes.OuterTypeNumberCheck");
842 NAME_TO_FULL_MODULE_NAME.put("ParameterNumberCheck",
843 BASE_PACKAGE + ".checks.sizes.ParameterNumberCheck");
844 NAME_TO_FULL_MODULE_NAME.put("RecordComponentNumberCheck",
845 BASE_PACKAGE + ".checks.sizes.RecordComponentNumberCheck");
846 }
847
848
849
850
851 private static void fillChecksFromWhitespacePackage() {
852 NAME_TO_FULL_MODULE_NAME.put("EmptyForInitializerPadCheck",
853 BASE_PACKAGE + ".checks.whitespace.EmptyForInitializerPadCheck");
854 NAME_TO_FULL_MODULE_NAME.put("EmptyForIteratorPadCheck",
855 BASE_PACKAGE + ".checks.whitespace.EmptyForIteratorPadCheck");
856 NAME_TO_FULL_MODULE_NAME.put("EmptyLineSeparatorCheck",
857 BASE_PACKAGE + ".checks.whitespace.EmptyLineSeparatorCheck");
858 NAME_TO_FULL_MODULE_NAME.put("FileTabCharacterCheck",
859 BASE_PACKAGE + ".checks.whitespace.FileTabCharacterCheck");
860 NAME_TO_FULL_MODULE_NAME.put("GenericWhitespaceCheck",
861 BASE_PACKAGE + ".checks.whitespace.GenericWhitespaceCheck");
862 NAME_TO_FULL_MODULE_NAME.put("MethodParamPadCheck",
863 BASE_PACKAGE + ".checks.whitespace.MethodParamPadCheck");
864 NAME_TO_FULL_MODULE_NAME.put("NoLineWrapCheck",
865 BASE_PACKAGE + ".checks.whitespace.NoLineWrapCheck");
866 NAME_TO_FULL_MODULE_NAME.put("NoWhitespaceAfterCheck",
867 BASE_PACKAGE + ".checks.whitespace.NoWhitespaceAfterCheck");
868 NAME_TO_FULL_MODULE_NAME.put("NoWhitespaceBeforeCheck",
869 BASE_PACKAGE + ".checks.whitespace.NoWhitespaceBeforeCheck");
870 NAME_TO_FULL_MODULE_NAME.put("NoWhitespaceBeforeCaseDefaultColonCheck",
871 BASE_PACKAGE + ".checks.whitespace.NoWhitespaceBeforeCaseDefaultColonCheck");
872 NAME_TO_FULL_MODULE_NAME.put("OperatorWrapCheck",
873 BASE_PACKAGE + ".checks.whitespace.OperatorWrapCheck");
874 NAME_TO_FULL_MODULE_NAME.put("ParenPadCheck",
875 BASE_PACKAGE + ".checks.whitespace.ParenPadCheck");
876 NAME_TO_FULL_MODULE_NAME.put("SeparatorWrapCheck",
877 BASE_PACKAGE + ".checks.whitespace.SeparatorWrapCheck");
878 NAME_TO_FULL_MODULE_NAME.put("SingleSpaceSeparatorCheck",
879 BASE_PACKAGE + ".checks.whitespace.SingleSpaceSeparatorCheck");
880 NAME_TO_FULL_MODULE_NAME.put("TypecastParenPadCheck",
881 BASE_PACKAGE + ".checks.whitespace.TypecastParenPadCheck");
882 NAME_TO_FULL_MODULE_NAME.put("WhitespaceAfterCheck",
883 BASE_PACKAGE + ".checks.whitespace.WhitespaceAfterCheck");
884 NAME_TO_FULL_MODULE_NAME.put("WhitespaceAroundCheck",
885 BASE_PACKAGE + ".checks.whitespace.WhitespaceAroundCheck");
886 }
887
888
889
890
891 private static void fillModulesFromChecksPackage() {
892 NAME_TO_FULL_MODULE_NAME.put("ArrayTypeStyleCheck",
893 BASE_PACKAGE + ".checks.ArrayTypeStyleCheck");
894 NAME_TO_FULL_MODULE_NAME.put("AvoidEscapedUnicodeCharactersCheck",
895 BASE_PACKAGE + ".checks.AvoidEscapedUnicodeCharactersCheck");
896 NAME_TO_FULL_MODULE_NAME.put("DescendantTokenCheck",
897 BASE_PACKAGE + ".checks.DescendantTokenCheck");
898 NAME_TO_FULL_MODULE_NAME.put("FinalParametersCheck",
899 BASE_PACKAGE + ".checks.FinalParametersCheck");
900 NAME_TO_FULL_MODULE_NAME.put("NewlineAtEndOfFileCheck",
901 BASE_PACKAGE + ".checks.NewlineAtEndOfFileCheck");
902 NAME_TO_FULL_MODULE_NAME.put("NoCodeInFileCheck",
903 BASE_PACKAGE + ".checks.NoCodeInFileCheck");
904 NAME_TO_FULL_MODULE_NAME.put("OuterTypeFilenameCheck",
905 BASE_PACKAGE + ".checks.OuterTypeFilenameCheck");
906 NAME_TO_FULL_MODULE_NAME.put("OrderedPropertiesCheck",
907 BASE_PACKAGE + ".checks.OrderedPropertiesCheck");
908 NAME_TO_FULL_MODULE_NAME.put("SuppressWarningsHolder",
909 BASE_PACKAGE + ".checks.SuppressWarningsHolder");
910 NAME_TO_FULL_MODULE_NAME.put("TodoCommentCheck",
911 BASE_PACKAGE + ".checks.TodoCommentCheck");
912 NAME_TO_FULL_MODULE_NAME.put("TrailingCommentCheck",
913 BASE_PACKAGE + ".checks.TrailingCommentCheck");
914 NAME_TO_FULL_MODULE_NAME.put("TranslationCheck",
915 BASE_PACKAGE + ".checks.TranslationCheck");
916 NAME_TO_FULL_MODULE_NAME.put("UncommentedMainCheck",
917 BASE_PACKAGE + ".checks.UncommentedMainCheck");
918 NAME_TO_FULL_MODULE_NAME.put("UniquePropertiesCheck",
919 BASE_PACKAGE + ".checks.UniquePropertiesCheck");
920 NAME_TO_FULL_MODULE_NAME.put("UpperEllCheck",
921 BASE_PACKAGE + ".checks.UpperEllCheck");
922 }
923
924
925
926
927 private static void fillModulesFromFilefiltersPackage() {
928 NAME_TO_FULL_MODULE_NAME.put("BeforeExecutionExclusionFileFilter",
929 BASE_PACKAGE + ".filefilters.BeforeExecutionExclusionFileFilter");
930 }
931
932
933
934
935 private static void fillModulesFromFiltersPackage() {
936 NAME_TO_FULL_MODULE_NAME.put("SeverityMatchFilter",
937 BASE_PACKAGE + ".filters.SeverityMatchFilter");
938 NAME_TO_FULL_MODULE_NAME.put("SuppressWithPlainTextCommentFilter",
939 BASE_PACKAGE + ".filters.SuppressWithPlainTextCommentFilter");
940 NAME_TO_FULL_MODULE_NAME.put("SuppressionCommentFilter",
941 BASE_PACKAGE + ".filters.SuppressionCommentFilter");
942 NAME_TO_FULL_MODULE_NAME.put("SuppressionFilter",
943 BASE_PACKAGE + ".filters.SuppressionFilter");
944 NAME_TO_FULL_MODULE_NAME.put("SuppressionSingleFilter",
945 BASE_PACKAGE + ".filters.SuppressionSingleFilter");
946 NAME_TO_FULL_MODULE_NAME.put("SuppressionXpathFilter",
947 BASE_PACKAGE + ".filters.SuppressionXpathFilter");
948 NAME_TO_FULL_MODULE_NAME.put("SuppressionXpathSingleFilter",
949 BASE_PACKAGE + ".filters.SuppressionXpathSingleFilter");
950 NAME_TO_FULL_MODULE_NAME.put("SuppressWarningsFilter",
951 BASE_PACKAGE + ".filters.SuppressWarningsFilter");
952 NAME_TO_FULL_MODULE_NAME.put("SuppressWithNearbyCommentFilter",
953 BASE_PACKAGE + ".filters.SuppressWithNearbyCommentFilter");
954 NAME_TO_FULL_MODULE_NAME.put("SuppressWithNearbyTextFilter",
955 BASE_PACKAGE + ".filters.SuppressWithNearbyTextFilter");
956 }
957
958
959
960
961 private static void fillModulesFromCheckstylePackage() {
962 NAME_TO_FULL_MODULE_NAME.put("Checker", BASE_PACKAGE + ".Checker");
963 NAME_TO_FULL_MODULE_NAME.put("TreeWalker", BASE_PACKAGE + ".TreeWalker");
964 }
965
966 }