View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2017 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  
20  package com.puppycrawl.tools.checkstyle;
21  
22  import java.io.IOException;
23  import java.lang.reflect.Constructor;
24  import java.util.Collections;
25  import java.util.HashMap;
26  import java.util.LinkedHashSet;
27  import java.util.Map;
28  import java.util.Set;
29  import java.util.stream.Collectors;
30  
31  import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
32  import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
33  import com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtils;
34  
35  /**
36   * A factory for creating objects from package names and names.
37   * Consider the below example for better understanding.
38   * <ul>
39   *     <li>module name - name of java class that represents module;</li>
40   *     <li>module full name - fully qualifies name of java class that represents module;</li>
41   *     <li>check module short name - name of Check without 'Check' suffix;</li>
42   *     <li>check module name - name of java class that represents Check (with 'Check' suffix);</li>
43   *     <li>
44   *         check module full name - fully qualifies name of java class
45   *         that represents Check (with 'Check' suffix).
46   *     </li>
47   * </ul>
48   * @author Rick Giles
49   * @author lkuehne
50   */
51  public class PackageObjectFactory implements ModuleFactory {
52  
53      /**
54       * Enum class to define loading options.
55       */
56      public enum ModuleLoadOption {
57          /**
58           * Searching from registered checkstyle modules and from packages given in constructor.
59           **/
60          SEARCH_REGISTERED_PACKAGES,
61          /**
62           * As SEARCH_REGISTERED_PACKAGES and also try to load class from all of packages given in
63           * constructor.
64           * Required for eclipse-cs plugin.
65           **/
66          TRY_IN_ALL_REGISTERED_PACKAGES,
67      }
68  
69      /** Base package of checkstyle modules checks. */
70      public static final String BASE_PACKAGE = "com.puppycrawl.tools.checkstyle";
71  
72      /** Exception message when it is unable to create a class instance. */
73      public static final String UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE =
74              "PackageObjectFactory.unableToInstantiateExceptionMessage";
75  
76      /** Exception message when there is ambiguous module name in config file. */
77      public static final String AMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGE =
78              "PackageObjectFactory.ambiguousModuleNameExceptionMessage";
79  
80      /** Suffix of checks. */
81      public static final String CHECK_SUFFIX = "Check";
82  
83      /** Character separate package names in qualified name of java class. */
84      public static final String PACKAGE_SEPARATOR = ".";
85  
86      /** Exception message when null class loader is given. */
87      public static final String NULL_LOADER_MESSAGE = "moduleClassLoader must not be null";
88  
89      /** Exception message when null package name is given. */
90      public static final String NULL_PACKAGE_MESSAGE = "package name must not be null";
91  
92      /** Separator to use in strings. */
93      public static final String STRING_SEPARATOR = ", ";
94  
95      /** Map of Checkstyle module names to their fully qualified names. */
96      private static final Map<String, String> NAME_TO_FULL_MODULE_NAME = new HashMap<>();
97  
98      /** A list of package names to prepend to class names. */
99      private final Set<String> packages;
100 
101     /** The class loader used to load Checkstyle core and custom modules. */
102     private final ClassLoader moduleClassLoader;
103 
104     /** Map of third party Checkstyle module names to the set of their fully qualified names. */
105     private Map<String, Set<String>> thirdPartyNameToFullModuleNames;
106 
107     /** Module load option which defines class search type. */
108     private ModuleLoadOption moduleLoadOption;
109 
110     static {
111         fillShortToFullModuleNamesMap();
112     }
113 
114     /**
115      * Creates a new {@code PackageObjectFactory} instance.
116      * @param packageNames the list of package names to use
117      * @param moduleClassLoader class loader used to load Checkstyle
118      *          core and custom modules
119      */
120     public PackageObjectFactory(Set<String> packageNames, ClassLoader moduleClassLoader) {
121         this(packageNames, moduleClassLoader, ModuleLoadOption.SEARCH_REGISTERED_PACKAGES);
122     }
123 
124     /**
125      * Creates a new {@code PackageObjectFactory} instance.
126      * @param packageNames the list of package names to use
127      * @param moduleClassLoader class loader used to load Checkstyle
128      *          core and custom modules
129      * @param moduleLoadOption loading option
130      */
131     public PackageObjectFactory(Set<String> packageNames, ClassLoader moduleClassLoader,
132             ModuleLoadOption moduleLoadOption) {
133         if (moduleClassLoader == null) {
134             throw new IllegalArgumentException(NULL_LOADER_MESSAGE);
135         }
136         if (packageNames.contains(null)) {
137             throw new IllegalArgumentException(NULL_PACKAGE_MESSAGE);
138         }
139 
140         //create a copy of the given set, but retain ordering
141         packages = new LinkedHashSet<>(packageNames);
142         this.moduleClassLoader = moduleClassLoader;
143         this.moduleLoadOption = moduleLoadOption;
144     }
145 
146     /**
147      * Creates a new {@code PackageObjectFactory} instance.
148      * @param packageName The package name to use
149      * @param moduleClassLoader class loader used to load Checkstyle
150      *          core and custom modules
151      */
152     public PackageObjectFactory(String packageName, ClassLoader moduleClassLoader) {
153         if (moduleClassLoader == null) {
154             throw new IllegalArgumentException(NULL_LOADER_MESSAGE);
155         }
156         if (packageName == null) {
157             throw new IllegalArgumentException(NULL_PACKAGE_MESSAGE);
158         }
159 
160         packages = new LinkedHashSet<>(1);
161         packages.add(packageName);
162         this.moduleClassLoader = moduleClassLoader;
163     }
164 
165     /**
166      * Creates a new instance of a class from a given name, or that name
167      * concatenated with &quot;Check&quot;. If the name is
168      * a class name, creates an instance of the named class. Otherwise, creates
169      * an instance of a class name obtained by concatenating the given name
170      * to a package name from a given list of package names.
171      * @param name the name of a class.
172      * @return the {@code Object} created by loader.
173      * @throws CheckstyleException if an error occurs.
174      */
175     @Override
176     public Object createModule(String name) throws CheckstyleException {
177         Object instance = null;
178         // if the name is a simple class name, try to find it in maps at first
179         if (!name.contains(PACKAGE_SEPARATOR)) {
180             instance = createFromStandardCheckSet(name);
181             // find the name in third party map
182             if (instance == null) {
183                 if (thirdPartyNameToFullModuleNames == null) {
184                     thirdPartyNameToFullModuleNames =
185                             generateThirdPartyNameToFullModuleName(moduleClassLoader);
186                 }
187                 instance = createObjectFromMap(name, thirdPartyNameToFullModuleNames);
188             }
189         }
190         if (instance == null) {
191             instance = createObject(name);
192         }
193         if (instance == null
194                 && moduleLoadOption == ModuleLoadOption.TRY_IN_ALL_REGISTERED_PACKAGES) {
195             instance = createModuleByTryInEachPackage(name);
196         }
197         if (instance == null) {
198             String attemptedNames = null;
199             if (!name.contains(PACKAGE_SEPARATOR)) {
200                 final String nameCheck = name + CHECK_SUFFIX;
201                 attemptedNames = joinPackageNamesWithClassName(name, packages)
202                         + STRING_SEPARATOR + nameCheck + STRING_SEPARATOR
203                         + joinPackageNamesWithClassName(nameCheck, packages);
204             }
205             final LocalizedMessage exceptionMessage = new LocalizedMessage(0,
206                 Definitions.CHECKSTYLE_BUNDLE, UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE,
207                 new String[] {name, attemptedNames}, null, getClass(), null);
208             throw new CheckstyleException(exceptionMessage.getMessage());
209         }
210         return instance;
211     }
212 
213     /**
214      * Create object from one of Checkstyle module names.
215      * @param name name of module.
216      * @return instance of module.
217      * @throws CheckstyleException if the class fails to instantiate or there are ambiguous classes.
218      */
219     private Object createFromStandardCheckSet(String name) throws CheckstyleException {
220         final String fullModuleName = NAME_TO_FULL_MODULE_NAME.get(name);
221         Object instance = null;
222         if (fullModuleName == null) {
223             final String fullCheckModuleName =
224                     NAME_TO_FULL_MODULE_NAME.get(name + CHECK_SUFFIX);
225             if (fullCheckModuleName != null) {
226                 instance = createObject(fullCheckModuleName);
227             }
228         }
229         else {
230             instance = createObject(fullModuleName);
231         }
232         return instance;
233     }
234 
235     /**
236      * Create object with the help of the supplied map.
237      * @param name name of module.
238      * @param map the supplied map.
239      * @return instance of module if it is found in modules map and no ambiguous classes exist.
240      * @throws CheckstyleException if the class fails to instantiate or there are ambiguous classes.
241      */
242     private Object createObjectFromMap(String name, Map<String, Set<String>> map)
243             throws CheckstyleException {
244         final Set<String> fullModuleNames = map.get(name);
245         Object instance = null;
246         if (fullModuleNames == null) {
247             final Set<String> fullCheckModuleNames = map.get(name + CHECK_SUFFIX);
248             if (fullCheckModuleNames != null) {
249                 instance = createObjectFromFullModuleNames(name, fullCheckModuleNames);
250             }
251         }
252         else {
253             instance = createObjectFromFullModuleNames(name, fullModuleNames);
254         }
255         return instance;
256     }
257 
258     /**
259      * Create Object from optional full module names.
260      * In most case, there should be only one element in {@code fullModuleName}, otherwise
261      * an exception would be thrown.
262      * @param name name of module
263      * @param fullModuleNames the supplied full module names set
264      * @return instance of module if there is only one element in {@code fullModuleName}
265      * @throws CheckstyleException if the class fails to instantiate or there are more than one
266      *      element in {@code fullModuleName}
267      */
268     private Object createObjectFromFullModuleNames(String name, Set<String> fullModuleNames)
269             throws CheckstyleException {
270         final Object returnValue;
271         if (fullModuleNames.size() == 1) {
272             returnValue = createObject(fullModuleNames.iterator().next());
273         }
274         else {
275             final String optionalNames = fullModuleNames.stream()
276                     .sorted()
277                     .collect(Collectors.joining(STRING_SEPARATOR));
278             final LocalizedMessage exceptionMessage = new LocalizedMessage(0,
279                     Definitions.CHECKSTYLE_BUNDLE, AMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGE,
280                     new String[] {name, optionalNames}, null, getClass(), null);
281             throw new CheckstyleException(exceptionMessage.getMessage());
282         }
283         return returnValue;
284     }
285 
286     /**
287      * Generate the map of third party Checkstyle module names to the set of their fully qualified
288      * names.
289      * @param loader the class loader used to load Checkstyle package names
290      * @return the map of third party Checkstyle module names to the set of their fully qualified
291      *      names
292      */
293     private Map<String, Set<String>> generateThirdPartyNameToFullModuleName(ClassLoader loader) {
294         Map<String, Set<String>> returnValue;
295         try {
296             returnValue = ModuleReflectionUtils.getCheckstyleModules(packages, loader).stream()
297                     .collect(Collectors.toMap(
298                         Class::getSimpleName,
299                         cls -> Collections.singleton(cls.getCanonicalName()),
300                         (fullNames1, fullNames2) -> {
301                             final Set<String> mergedNames = new LinkedHashSet<>(fullNames1);
302                             mergedNames.addAll(fullNames2);
303                             return mergedNames;
304                         }));
305         }
306         catch (IOException ignore) {
307             returnValue = new HashMap<>();
308         }
309         return returnValue;
310     }
311 
312     /**
313      * Creates a string by joining package names with a class name.
314      * @param className name of the class for joining.
315      * @param packages packages names.
316      * @return a string which is obtained by joining package names with a class name.
317      */
318     private static String joinPackageNamesWithClassName(String className, Set<String> packages) {
319         return packages.stream().collect(
320             Collectors.joining(PACKAGE_SEPARATOR + className + STRING_SEPARATOR, "",
321                     PACKAGE_SEPARATOR + className));
322     }
323 
324     /**
325      * Creates a new instance of a named class.
326      * @param className the name of the class to instantiate.
327      * @return the {@code Object} created by loader or null.
328      * @throws CheckstyleException if the class fails to instantiate.
329      */
330     private Object createObject(String className) throws CheckstyleException {
331         Class<?> clazz = null;
332 
333         try {
334             clazz = Class.forName(className, true, moduleClassLoader);
335         }
336         catch (final ReflectiveOperationException | NoClassDefFoundError ignored) {
337             // ignore the exception
338         }
339 
340         Object instance = null;
341 
342         if (clazz != null) {
343             try {
344                 final Constructor<?> declaredConstructor = clazz.getDeclaredConstructor();
345                 declaredConstructor.setAccessible(true);
346                 instance = declaredConstructor.newInstance();
347             }
348             catch (final ReflectiveOperationException ex) {
349                 throw new CheckstyleException("Unable to instantiate " + className, ex);
350             }
351         }
352 
353         return instance;
354     }
355 
356     /**
357      * Searching to class with given name (or name concatenated with &quot;Check&quot;) in existing
358      * packages. Returns instance if class found or, otherwise, null.
359      * @param name the name of a class.
360      * @return the {@code Object} created by loader.
361      * @throws CheckstyleException if an error occurs.
362      */
363     private Object createModuleByTryInEachPackage(String name) throws CheckstyleException {
364         final Set<String> possibleNames = packages.stream()
365                 .map(packageName -> packageName + PACKAGE_SEPARATOR + name)
366                 .collect(Collectors.toSet());
367         possibleNames.addAll(possibleNames.stream()
368                 .map(possibleName -> possibleName + CHECK_SUFFIX)
369                 .collect(Collectors.toSet()));
370         Object instance = null;
371         for (String possibleName : possibleNames) {
372             instance = createObject(possibleName);
373             if (instance != null) {
374                 break;
375             }
376         }
377         return instance;
378     }
379 
380     /**
381      * Fill short-to-full module names map.
382      */
383     private static void fillShortToFullModuleNamesMap() {
384         fillChecksFromAnnotationPackage();
385         fillChecksFromBlocksPackage();
386         fillChecksFromCodingPackage();
387         fillChecksFromDesignPackage();
388         fillChecksFromHeaderPackage();
389         fillChecksFromImportsPackage();
390         fillChecksFromIndentationPackage();
391         fillChecksFromJavadocPackage();
392         fillChecksFromMetricsPackage();
393         fillChecksFromModifierPackage();
394         fillChecksFromNamingPackage();
395         fillChecksFromRegexpPackage();
396         fillChecksFromSizesPackage();
397         fillChecksFromWhitespacePackage();
398         fillModulesFromChecksPackage();
399         fillModulesFromFilefiltersPackage();
400         fillModulesFromFiltersPackage();
401         fillModulesFromCheckstylePackage();
402     }
403 
404     /**
405      * Fill short-to-full module names map with Checks from annotation package.
406      */
407     private static void fillChecksFromAnnotationPackage() {
408         NAME_TO_FULL_MODULE_NAME.put("AnnotationLocationCheck",
409                 BASE_PACKAGE + ".checks.annotation.AnnotationLocationCheck");
410         NAME_TO_FULL_MODULE_NAME.put("AnnotationOnSameLineCheck",
411                 BASE_PACKAGE + ".checks.annotation.AnnotationOnSameLineCheck");
412         NAME_TO_FULL_MODULE_NAME.put("AnnotationUseStyleCheck",
413                 BASE_PACKAGE + ".checks.annotation.AnnotationUseStyleCheck");
414         NAME_TO_FULL_MODULE_NAME.put("MissingDeprecatedCheck",
415                 BASE_PACKAGE + ".checks.annotation.MissingDeprecatedCheck");
416         NAME_TO_FULL_MODULE_NAME.put("MissingOverrideCheck",
417                 BASE_PACKAGE + ".checks.annotation.MissingOverrideCheck");
418         NAME_TO_FULL_MODULE_NAME.put("PackageAnnotationCheck",
419                 BASE_PACKAGE + ".checks.annotation.PackageAnnotationCheck");
420         NAME_TO_FULL_MODULE_NAME.put("SuppressWarningsCheck",
421                 BASE_PACKAGE + ".checks.annotation.SuppressWarningsCheck");
422     }
423 
424     /**
425      * Fill short-to-full module names map with Checks from blocks package.
426      */
427     private static void fillChecksFromBlocksPackage() {
428         NAME_TO_FULL_MODULE_NAME.put("AvoidNestedBlocksCheck",
429                 BASE_PACKAGE + ".checks.blocks.AvoidNestedBlocksCheck");
430         NAME_TO_FULL_MODULE_NAME.put("EmptyBlockCheck",
431                 BASE_PACKAGE + ".checks.blocks.EmptyBlockCheck");
432         NAME_TO_FULL_MODULE_NAME.put("EmptyCatchBlockCheck",
433                 BASE_PACKAGE + ".checks.blocks.EmptyCatchBlockCheck");
434         NAME_TO_FULL_MODULE_NAME.put("LeftCurlyCheck",
435                 BASE_PACKAGE + ".checks.blocks.LeftCurlyCheck");
436         NAME_TO_FULL_MODULE_NAME.put("NeedBracesCheck",
437                 BASE_PACKAGE + ".checks.blocks.NeedBracesCheck");
438         NAME_TO_FULL_MODULE_NAME.put("RightCurlyCheck",
439                 BASE_PACKAGE + ".checks.blocks.RightCurlyCheck");
440     }
441 
442     /**
443      * Fill short-to-full module names map with Checks from coding package.
444      */
445     // -@cs[ExecutableStatementCount] splitting this method is not reasonable.
446     private static void fillChecksFromCodingPackage() {
447         NAME_TO_FULL_MODULE_NAME.put("ArrayTrailingCommaCheck",
448                 BASE_PACKAGE + ".checks.coding.ArrayTrailingCommaCheck");
449         NAME_TO_FULL_MODULE_NAME.put("AvoidInlineConditionalsCheck",
450                 BASE_PACKAGE + ".checks.coding.AvoidInlineConditionalsCheck");
451         NAME_TO_FULL_MODULE_NAME.put("CovariantEqualsCheck",
452                 BASE_PACKAGE + ".checks.coding.CovariantEqualsCheck");
453         NAME_TO_FULL_MODULE_NAME.put("DeclarationOrderCheck",
454                 BASE_PACKAGE + ".checks.coding.DeclarationOrderCheck");
455         NAME_TO_FULL_MODULE_NAME.put("DefaultComesLastCheck",
456                 BASE_PACKAGE + ".checks.coding.DefaultComesLastCheck");
457         NAME_TO_FULL_MODULE_NAME.put("EmptyStatementCheck",
458                 BASE_PACKAGE + ".checks.coding.EmptyStatementCheck");
459         NAME_TO_FULL_MODULE_NAME.put("EqualsAvoidNullCheck",
460                 BASE_PACKAGE + ".checks.coding.EqualsAvoidNullCheck");
461         NAME_TO_FULL_MODULE_NAME.put("EqualsHashCodeCheck",
462                 BASE_PACKAGE + ".checks.coding.EqualsHashCodeCheck");
463         NAME_TO_FULL_MODULE_NAME.put("ExplicitInitializationCheck",
464                 BASE_PACKAGE + ".checks.coding.ExplicitInitializationCheck");
465         NAME_TO_FULL_MODULE_NAME.put("FallThroughCheck",
466                 BASE_PACKAGE + ".checks.coding.FallThroughCheck");
467         NAME_TO_FULL_MODULE_NAME.put("FinalLocalVariableCheck",
468                 BASE_PACKAGE + ".checks.coding.FinalLocalVariableCheck");
469         NAME_TO_FULL_MODULE_NAME.put("HiddenFieldCheck",
470                 BASE_PACKAGE + ".checks.coding.HiddenFieldCheck");
471         NAME_TO_FULL_MODULE_NAME.put("IllegalCatchCheck",
472                 BASE_PACKAGE + ".checks.coding.IllegalCatchCheck");
473         NAME_TO_FULL_MODULE_NAME.put("IllegalInstantiationCheck",
474                 BASE_PACKAGE + ".checks.coding.IllegalInstantiationCheck");
475         NAME_TO_FULL_MODULE_NAME.put("IllegalThrowsCheck",
476                 BASE_PACKAGE + ".checks.coding.IllegalThrowsCheck");
477         NAME_TO_FULL_MODULE_NAME.put("IllegalTokenCheck",
478                 BASE_PACKAGE + ".checks.coding.IllegalTokenCheck");
479         NAME_TO_FULL_MODULE_NAME.put("IllegalTokenTextCheck",
480                 BASE_PACKAGE + ".checks.coding.IllegalTokenTextCheck");
481         NAME_TO_FULL_MODULE_NAME.put("IllegalTypeCheck",
482                 BASE_PACKAGE + ".checks.coding.IllegalTypeCheck");
483         NAME_TO_FULL_MODULE_NAME.put("InnerAssignmentCheck",
484                 BASE_PACKAGE + ".checks.coding.InnerAssignmentCheck");
485         NAME_TO_FULL_MODULE_NAME.put("MagicNumberCheck",
486                 BASE_PACKAGE + ".checks.coding.MagicNumberCheck");
487         NAME_TO_FULL_MODULE_NAME.put("MissingCtorCheck",
488                 BASE_PACKAGE + ".checks.coding.MissingCtorCheck");
489         NAME_TO_FULL_MODULE_NAME.put("MissingSwitchDefaultCheck",
490                 BASE_PACKAGE + ".checks.coding.MissingSwitchDefaultCheck");
491         NAME_TO_FULL_MODULE_NAME.put("ModifiedControlVariableCheck",
492                 BASE_PACKAGE + ".checks.coding.ModifiedControlVariableCheck");
493         NAME_TO_FULL_MODULE_NAME.put("MultipleStringLiteralsCheck",
494                 BASE_PACKAGE + ".checks.coding.MultipleStringLiteralsCheck");
495         NAME_TO_FULL_MODULE_NAME.put("MultipleVariableDeclarationsCheck",
496                 BASE_PACKAGE + ".checks.coding.MultipleVariableDeclarationsCheck");
497         NAME_TO_FULL_MODULE_NAME.put("NestedForDepthCheck",
498                 BASE_PACKAGE + ".checks.coding.NestedForDepthCheck");
499         NAME_TO_FULL_MODULE_NAME.put("NestedIfDepthCheck",
500                 BASE_PACKAGE + ".checks.coding.NestedIfDepthCheck");
501         NAME_TO_FULL_MODULE_NAME.put("NestedTryDepthCheck",
502                 BASE_PACKAGE + ".checks.coding.NestedTryDepthCheck");
503         NAME_TO_FULL_MODULE_NAME.put("NoCloneCheck",
504                 BASE_PACKAGE + ".checks.coding.NoCloneCheck");
505         NAME_TO_FULL_MODULE_NAME.put("NoFinalizerCheck",
506                 BASE_PACKAGE + ".checks.coding.NoFinalizerCheck");
507         NAME_TO_FULL_MODULE_NAME.put("OneStatementPerLineCheck",
508                 BASE_PACKAGE + ".checks.coding.OneStatementPerLineCheck");
509         NAME_TO_FULL_MODULE_NAME.put("OverloadMethodsDeclarationOrderCheck",
510                 BASE_PACKAGE + ".checks.coding.OverloadMethodsDeclarationOrderCheck");
511         NAME_TO_FULL_MODULE_NAME.put("PackageDeclarationCheck",
512                 BASE_PACKAGE + ".checks.coding.PackageDeclarationCheck");
513         NAME_TO_FULL_MODULE_NAME.put("ParameterAssignmentCheck",
514                 BASE_PACKAGE + ".checks.coding.ParameterAssignmentCheck");
515         NAME_TO_FULL_MODULE_NAME.put("RequireThisCheck",
516                 BASE_PACKAGE + ".checks.coding.RequireThisCheck");
517         NAME_TO_FULL_MODULE_NAME.put("ReturnCountCheck",
518                 BASE_PACKAGE + ".checks.coding.ReturnCountCheck");
519         NAME_TO_FULL_MODULE_NAME.put("SimplifyBooleanExpressionCheck",
520                 BASE_PACKAGE + ".checks.coding.SimplifyBooleanExpressionCheck");
521         NAME_TO_FULL_MODULE_NAME.put("SimplifyBooleanReturnCheck",
522                 BASE_PACKAGE + ".checks.coding.SimplifyBooleanReturnCheck");
523         NAME_TO_FULL_MODULE_NAME.put("StringLiteralEqualityCheck",
524                 BASE_PACKAGE + ".checks.coding.StringLiteralEqualityCheck");
525         NAME_TO_FULL_MODULE_NAME.put("SuperCloneCheck",
526                 BASE_PACKAGE + ".checks.coding.SuperCloneCheck");
527         NAME_TO_FULL_MODULE_NAME.put("SuperFinalizeCheck",
528                 BASE_PACKAGE + ".checks.coding.SuperFinalizeCheck");
529         NAME_TO_FULL_MODULE_NAME.put("UnnecessaryParenthesesCheck",
530                 BASE_PACKAGE + ".checks.coding.UnnecessaryParenthesesCheck");
531         NAME_TO_FULL_MODULE_NAME.put("VariableDeclarationUsageDistanceCheck",
532                 BASE_PACKAGE + ".checks.coding.VariableDeclarationUsageDistanceCheck");
533     }
534 
535     /**
536      * Fill short-to-full module names map with Checks from design package.
537      */
538     private static void fillChecksFromDesignPackage() {
539         NAME_TO_FULL_MODULE_NAME.put("DesignForExtensionCheck",
540                 BASE_PACKAGE + ".checks.design.DesignForExtensionCheck");
541         NAME_TO_FULL_MODULE_NAME.put("FinalClassCheck",
542                 BASE_PACKAGE + ".checks.design.FinalClassCheck");
543         NAME_TO_FULL_MODULE_NAME.put("HideUtilityClassConstructorCheck",
544                 BASE_PACKAGE + ".checks.design.HideUtilityClassConstructorCheck");
545         NAME_TO_FULL_MODULE_NAME.put("InnerTypeLastCheck",
546                 BASE_PACKAGE + ".checks.design.InnerTypeLastCheck");
547         NAME_TO_FULL_MODULE_NAME.put("InterfaceIsTypeCheck",
548                 BASE_PACKAGE + ".checks.design.InterfaceIsTypeCheck");
549         NAME_TO_FULL_MODULE_NAME.put("MutableExceptionCheck",
550                 BASE_PACKAGE + ".checks.design.MutableExceptionCheck");
551         NAME_TO_FULL_MODULE_NAME.put("OneTopLevelClassCheck",
552                 BASE_PACKAGE + ".checks.design.OneTopLevelClassCheck");
553         NAME_TO_FULL_MODULE_NAME.put("ThrowsCountCheck",
554                 BASE_PACKAGE + ".checks.design.ThrowsCountCheck");
555         NAME_TO_FULL_MODULE_NAME.put("VisibilityModifierCheck",
556                 BASE_PACKAGE + ".checks.design.VisibilityModifierCheck");
557     }
558 
559     /**
560      * Fill short-to-full module names map with Checks from header package.
561      */
562     private static void fillChecksFromHeaderPackage() {
563         NAME_TO_FULL_MODULE_NAME.put("HeaderCheck",
564                 BASE_PACKAGE + ".checks.header.HeaderCheck");
565         NAME_TO_FULL_MODULE_NAME.put("RegexpHeaderCheck",
566                 BASE_PACKAGE + ".checks.header.RegexpHeaderCheck");
567     }
568 
569     /**
570      * Fill short-to-full module names map with Checks from imports package.
571      */
572     private static void fillChecksFromImportsPackage() {
573         NAME_TO_FULL_MODULE_NAME.put("AvoidStarImportCheck",
574                 BASE_PACKAGE + ".checks.imports.AvoidStarImportCheck");
575         NAME_TO_FULL_MODULE_NAME.put("AvoidStaticImportCheck",
576                 BASE_PACKAGE + ".checks.imports.AvoidStaticImportCheck");
577         NAME_TO_FULL_MODULE_NAME.put("CustomImportOrderCheck",
578                 BASE_PACKAGE + ".checks.imports.CustomImportOrderCheck");
579         NAME_TO_FULL_MODULE_NAME.put("IllegalImportCheck",
580                 BASE_PACKAGE + ".checks.imports.IllegalImportCheck");
581         NAME_TO_FULL_MODULE_NAME.put("ImportControlCheck",
582                 BASE_PACKAGE + ".checks.imports.ImportControlCheck");
583         NAME_TO_FULL_MODULE_NAME.put("ImportOrderCheck",
584                 BASE_PACKAGE + ".checks.imports.ImportOrderCheck");
585         NAME_TO_FULL_MODULE_NAME.put("RedundantImportCheck",
586                 BASE_PACKAGE + ".checks.imports.RedundantImportCheck");
587         NAME_TO_FULL_MODULE_NAME.put("UnusedImportsCheck",
588                 BASE_PACKAGE + ".checks.imports.UnusedImportsCheck");
589     }
590 
591     /**
592      * Fill short-to-full module names map with Checks from indentation package.
593      */
594     private static void fillChecksFromIndentationPackage() {
595         NAME_TO_FULL_MODULE_NAME.put("CommentsIndentationCheck",
596                 BASE_PACKAGE + ".checks.indentation.CommentsIndentationCheck");
597         NAME_TO_FULL_MODULE_NAME.put("IndentationCheck",
598                 BASE_PACKAGE + ".checks.indentation.IndentationCheck");
599     }
600 
601     /**
602      * Fill short-to-full module names map with Checks from javadoc package.
603      */
604     private static void fillChecksFromJavadocPackage() {
605         NAME_TO_FULL_MODULE_NAME.put("AtclauseOrderCheck",
606                 BASE_PACKAGE + ".checks.javadoc.AtclauseOrderCheck");
607         NAME_TO_FULL_MODULE_NAME.put("JavadocMethodCheck",
608                 BASE_PACKAGE + ".checks.javadoc.JavadocMethodCheck");
609         NAME_TO_FULL_MODULE_NAME.put("JavadocPackageCheck",
610                 BASE_PACKAGE + ".checks.javadoc.JavadocPackageCheck");
611         NAME_TO_FULL_MODULE_NAME.put("JavadocParagraphCheck",
612                 BASE_PACKAGE + ".checks.javadoc.JavadocParagraphCheck");
613         NAME_TO_FULL_MODULE_NAME.put("JavadocStyleCheck",
614                 BASE_PACKAGE + ".checks.javadoc.JavadocStyleCheck");
615         NAME_TO_FULL_MODULE_NAME.put("JavadocTagContinuationIndentationCheck",
616                 BASE_PACKAGE + ".checks.javadoc.JavadocTagContinuationIndentationCheck");
617         NAME_TO_FULL_MODULE_NAME.put("JavadocTypeCheck",
618                 BASE_PACKAGE + ".checks.javadoc.JavadocTypeCheck");
619         NAME_TO_FULL_MODULE_NAME.put("JavadocVariableCheck",
620                 BASE_PACKAGE + ".checks.javadoc.JavadocVariableCheck");
621         NAME_TO_FULL_MODULE_NAME.put("NonEmptyAtclauseDescriptionCheck",
622                 BASE_PACKAGE + ".checks.javadoc.NonEmptyAtclauseDescriptionCheck");
623         NAME_TO_FULL_MODULE_NAME.put("SingleLineJavadocCheck",
624                 BASE_PACKAGE + ".checks.javadoc.SingleLineJavadocCheck");
625         NAME_TO_FULL_MODULE_NAME.put("SummaryJavadocCheck",
626                 BASE_PACKAGE + ".checks.javadoc.SummaryJavadocCheck");
627         NAME_TO_FULL_MODULE_NAME.put("WriteTagCheck",
628                 BASE_PACKAGE + ".checks.javadoc.WriteTagCheck");
629     }
630 
631     /**
632      * Fill short-to-full module names map with Checks from metrics package.
633      */
634     private static void fillChecksFromMetricsPackage() {
635         NAME_TO_FULL_MODULE_NAME.put("BooleanExpressionComplexityCheck",
636                 BASE_PACKAGE + ".checks.metrics.BooleanExpressionComplexityCheck");
637         NAME_TO_FULL_MODULE_NAME.put("ClassDataAbstractionCouplingCheck",
638                 BASE_PACKAGE + ".checks.metrics.ClassDataAbstractionCouplingCheck");
639         NAME_TO_FULL_MODULE_NAME.put("ClassFanOutComplexityCheck",
640                 BASE_PACKAGE + ".checks.metrics.ClassFanOutComplexityCheck");
641         NAME_TO_FULL_MODULE_NAME.put("CyclomaticComplexityCheck",
642                 BASE_PACKAGE + ".checks.metrics.CyclomaticComplexityCheck");
643         NAME_TO_FULL_MODULE_NAME.put("JavaNCSSCheck",
644                 BASE_PACKAGE + ".checks.metrics.JavaNCSSCheck");
645         NAME_TO_FULL_MODULE_NAME.put("NPathComplexityCheck",
646                 BASE_PACKAGE + ".checks.metrics.NPathComplexityCheck");
647     }
648 
649     /**
650      * Fill short-to-full module names map with Checks from modifier package.
651      */
652     private static void fillChecksFromModifierPackage() {
653         NAME_TO_FULL_MODULE_NAME.put("ModifierOrderCheck",
654                 BASE_PACKAGE + ".checks.modifier.ModifierOrderCheck");
655         NAME_TO_FULL_MODULE_NAME.put("RedundantModifierCheck",
656                 BASE_PACKAGE + ".checks.modifier.RedundantModifierCheck");
657     }
658 
659     /**
660      * Fill short-to-full module names map with Checks from naming package.
661      */
662     private static void fillChecksFromNamingPackage() {
663         NAME_TO_FULL_MODULE_NAME.put("AbbreviationAsWordInNameCheck",
664                 BASE_PACKAGE + ".checks.naming.AbbreviationAsWordInNameCheck");
665         NAME_TO_FULL_MODULE_NAME.put("AbstractClassNameCheck",
666                 BASE_PACKAGE + ".checks.naming.AbstractClassNameCheck");
667         NAME_TO_FULL_MODULE_NAME.put("CatchParameterNameCheck",
668                 BASE_PACKAGE + ".checks.naming.CatchParameterNameCheck");
669         NAME_TO_FULL_MODULE_NAME.put("ClassTypeParameterNameCheck",
670                 BASE_PACKAGE + ".checks.naming.ClassTypeParameterNameCheck");
671         NAME_TO_FULL_MODULE_NAME.put("ConstantNameCheck",
672                 BASE_PACKAGE + ".checks.naming.ConstantNameCheck");
673         NAME_TO_FULL_MODULE_NAME.put("InterfaceTypeParameterNameCheck",
674                 BASE_PACKAGE + ".checks.naming.InterfaceTypeParameterNameCheck");
675         NAME_TO_FULL_MODULE_NAME.put("LocalFinalVariableNameCheck",
676                 BASE_PACKAGE + ".checks.naming.LocalFinalVariableNameCheck");
677         NAME_TO_FULL_MODULE_NAME.put("LocalVariableNameCheck",
678                 BASE_PACKAGE + ".checks.naming.LocalVariableNameCheck");
679         NAME_TO_FULL_MODULE_NAME.put("MemberNameCheck",
680                 BASE_PACKAGE + ".checks.naming.MemberNameCheck");
681         NAME_TO_FULL_MODULE_NAME.put("MethodNameCheck",
682                 BASE_PACKAGE + ".checks.naming.MethodNameCheck");
683         NAME_TO_FULL_MODULE_NAME.put("MethodTypeParameterNameCheck",
684                 BASE_PACKAGE + ".checks.naming.MethodTypeParameterNameCheck");
685         NAME_TO_FULL_MODULE_NAME.put("PackageNameCheck",
686                 BASE_PACKAGE + ".checks.naming.PackageNameCheck");
687         NAME_TO_FULL_MODULE_NAME.put("ParameterNameCheck",
688                 BASE_PACKAGE + ".checks.naming.ParameterNameCheck");
689         NAME_TO_FULL_MODULE_NAME.put("StaticVariableNameCheck",
690                 BASE_PACKAGE + ".checks.naming.StaticVariableNameCheck");
691         NAME_TO_FULL_MODULE_NAME.put("TypeNameCheck",
692                 BASE_PACKAGE + ".checks.naming.TypeNameCheck");
693     }
694 
695     /**
696      * Fill short-to-full module names map with Checks from regexp package.
697      */
698     private static void fillChecksFromRegexpPackage() {
699         NAME_TO_FULL_MODULE_NAME.put("RegexpCheck",
700                 BASE_PACKAGE + ".checks.regexp.RegexpCheck");
701         NAME_TO_FULL_MODULE_NAME.put("RegexpMultilineCheck",
702                 BASE_PACKAGE + ".checks.regexp.RegexpMultilineCheck");
703         NAME_TO_FULL_MODULE_NAME.put("RegexpOnFilenameCheck",
704                 BASE_PACKAGE + ".checks.regexp.RegexpOnFilenameCheck");
705         NAME_TO_FULL_MODULE_NAME.put("RegexpSinglelineCheck",
706                 BASE_PACKAGE + ".checks.regexp.RegexpSinglelineCheck");
707         NAME_TO_FULL_MODULE_NAME.put("RegexpSinglelineJavaCheck",
708                 BASE_PACKAGE + ".checks.regexp.RegexpSinglelineJavaCheck");
709     }
710 
711     /**
712      * Fill short-to-full module names map with Checks from sizes package.
713      */
714     private static void fillChecksFromSizesPackage() {
715         NAME_TO_FULL_MODULE_NAME.put("AnonInnerLengthCheck",
716                 BASE_PACKAGE + ".checks.sizes.AnonInnerLengthCheck");
717         NAME_TO_FULL_MODULE_NAME.put("ExecutableStatementCountCheck",
718                 BASE_PACKAGE + ".checks.sizes.ExecutableStatementCountCheck");
719         NAME_TO_FULL_MODULE_NAME.put("FileLengthCheck",
720                 BASE_PACKAGE + ".checks.sizes.FileLengthCheck");
721         NAME_TO_FULL_MODULE_NAME.put("LineLengthCheck",
722                 BASE_PACKAGE + ".checks.sizes.LineLengthCheck");
723         NAME_TO_FULL_MODULE_NAME.put("MethodCountCheck",
724                 BASE_PACKAGE + ".checks.sizes.MethodCountCheck");
725         NAME_TO_FULL_MODULE_NAME.put("MethodLengthCheck",
726                 BASE_PACKAGE + ".checks.sizes.MethodLengthCheck");
727         NAME_TO_FULL_MODULE_NAME.put("OuterTypeNumberCheck",
728                 BASE_PACKAGE + ".checks.sizes.OuterTypeNumberCheck");
729         NAME_TO_FULL_MODULE_NAME.put("ParameterNumberCheck",
730                 BASE_PACKAGE + ".checks.sizes.ParameterNumberCheck");
731     }
732 
733     /**
734      * Fill short-to-full module names map with Checks from whitespace package.
735      */
736     private static void fillChecksFromWhitespacePackage() {
737         NAME_TO_FULL_MODULE_NAME.put("EmptyForInitializerPadCheck",
738                 BASE_PACKAGE + ".checks.whitespace.EmptyForInitializerPadCheck");
739         NAME_TO_FULL_MODULE_NAME.put("EmptyForIteratorPadCheck",
740                 BASE_PACKAGE + ".checks.whitespace.EmptyForIteratorPadCheck");
741         NAME_TO_FULL_MODULE_NAME.put("EmptyLineSeparatorCheck",
742                 BASE_PACKAGE + ".checks.whitespace.EmptyLineSeparatorCheck");
743         NAME_TO_FULL_MODULE_NAME.put("FileTabCharacterCheck",
744                 BASE_PACKAGE + ".checks.whitespace.FileTabCharacterCheck");
745         NAME_TO_FULL_MODULE_NAME.put("GenericWhitespaceCheck",
746                 BASE_PACKAGE + ".checks.whitespace.GenericWhitespaceCheck");
747         NAME_TO_FULL_MODULE_NAME.put("MethodParamPadCheck",
748                 BASE_PACKAGE + ".checks.whitespace.MethodParamPadCheck");
749         NAME_TO_FULL_MODULE_NAME.put("NoLineWrapCheck",
750                 BASE_PACKAGE + ".checks.whitespace.NoLineWrapCheck");
751         NAME_TO_FULL_MODULE_NAME.put("NoWhitespaceAfterCheck",
752                 BASE_PACKAGE + ".checks.whitespace.NoWhitespaceAfterCheck");
753         NAME_TO_FULL_MODULE_NAME.put("NoWhitespaceBeforeCheck",
754                 BASE_PACKAGE + ".checks.whitespace.NoWhitespaceBeforeCheck");
755         NAME_TO_FULL_MODULE_NAME.put("OperatorWrapCheck",
756                 BASE_PACKAGE + ".checks.whitespace.OperatorWrapCheck");
757         NAME_TO_FULL_MODULE_NAME.put("ParenPadCheck",
758                 BASE_PACKAGE + ".checks.whitespace.ParenPadCheck");
759         NAME_TO_FULL_MODULE_NAME.put("SeparatorWrapCheck",
760                 BASE_PACKAGE + ".checks.whitespace.SeparatorWrapCheck");
761         NAME_TO_FULL_MODULE_NAME.put("SingleSpaceSeparatorCheck",
762                 BASE_PACKAGE + ".checks.whitespace.SingleSpaceSeparatorCheck");
763         NAME_TO_FULL_MODULE_NAME.put("TypecastParenPadCheck",
764                 BASE_PACKAGE + ".checks.whitespace.TypecastParenPadCheck");
765         NAME_TO_FULL_MODULE_NAME.put("WhitespaceAfterCheck",
766                 BASE_PACKAGE + ".checks.whitespace.WhitespaceAfterCheck");
767         NAME_TO_FULL_MODULE_NAME.put("WhitespaceAroundCheck",
768                 BASE_PACKAGE + ".checks.whitespace.WhitespaceAroundCheck");
769     }
770 
771     /**
772      * Fill short-to-full module names map with modules from checks package.
773      */
774     private static void fillModulesFromChecksPackage() {
775         NAME_TO_FULL_MODULE_NAME.put("ArrayTypeStyleCheck",
776                 BASE_PACKAGE + ".checks.ArrayTypeStyleCheck");
777         NAME_TO_FULL_MODULE_NAME.put("AvoidEscapedUnicodeCharactersCheck",
778                 BASE_PACKAGE + ".checks.AvoidEscapedUnicodeCharactersCheck");
779         NAME_TO_FULL_MODULE_NAME.put("DescendantTokenCheck",
780                 BASE_PACKAGE + ".checks.DescendantTokenCheck");
781         NAME_TO_FULL_MODULE_NAME.put("FinalParametersCheck",
782                 BASE_PACKAGE + ".checks.FinalParametersCheck");
783         NAME_TO_FULL_MODULE_NAME.put("NewlineAtEndOfFileCheck",
784                 BASE_PACKAGE + ".checks.NewlineAtEndOfFileCheck");
785         NAME_TO_FULL_MODULE_NAME.put("OuterTypeFilenameCheck",
786                 BASE_PACKAGE + ".checks.OuterTypeFilenameCheck");
787         NAME_TO_FULL_MODULE_NAME.put("SuppressWarningsHolder",
788                 BASE_PACKAGE + ".checks.SuppressWarningsHolder");
789         NAME_TO_FULL_MODULE_NAME.put("TodoCommentCheck",
790                 BASE_PACKAGE + ".checks.TodoCommentCheck");
791         NAME_TO_FULL_MODULE_NAME.put("TrailingCommentCheck",
792                 BASE_PACKAGE + ".checks.TrailingCommentCheck");
793         NAME_TO_FULL_MODULE_NAME.put("TranslationCheck",
794                 BASE_PACKAGE + ".checks.TranslationCheck");
795         NAME_TO_FULL_MODULE_NAME.put("UncommentedMainCheck",
796                 BASE_PACKAGE + ".checks.UncommentedMainCheck");
797         NAME_TO_FULL_MODULE_NAME.put("UniquePropertiesCheck",
798                 BASE_PACKAGE + ".checks.UniquePropertiesCheck");
799         NAME_TO_FULL_MODULE_NAME.put("UpperEllCheck",
800                 BASE_PACKAGE + ".checks.UpperEllCheck");
801     }
802 
803     /**
804      * Fill short-to-full module names map with modules from filefilters package.
805      */
806     private static void fillModulesFromFilefiltersPackage() {
807         NAME_TO_FULL_MODULE_NAME.put("BeforeExecutionExclusionFileFilter",
808                 BASE_PACKAGE + ".filefilters.BeforeExecutionExclusionFileFilter");
809     }
810 
811     /**
812      * Fill short-to-full module names map with modules from filters package.
813      */
814     private static void fillModulesFromFiltersPackage() {
815         NAME_TO_FULL_MODULE_NAME.put("CsvFilter",
816                 BASE_PACKAGE + ".filters.CsvFilter");
817         NAME_TO_FULL_MODULE_NAME.put("IntMatchFilter",
818                 BASE_PACKAGE + ".filters.IntMatchFilter");
819         NAME_TO_FULL_MODULE_NAME.put("IntRangeFilter",
820                 BASE_PACKAGE + ".filters.IntRangeFilter");
821         NAME_TO_FULL_MODULE_NAME.put("SeverityMatchFilter",
822                 BASE_PACKAGE + ".filters.SeverityMatchFilter");
823         NAME_TO_FULL_MODULE_NAME.put("SuppressWithPlainTextCommentFilter",
824             BASE_PACKAGE + ".filters.SuppressWithPlainTextCommentFilter");
825         NAME_TO_FULL_MODULE_NAME.put("SuppressionCommentFilter",
826                 BASE_PACKAGE + ".filters.SuppressionCommentFilter");
827         NAME_TO_FULL_MODULE_NAME.put("SuppressionFilter",
828                 BASE_PACKAGE + ".filters.SuppressionFilter");
829         NAME_TO_FULL_MODULE_NAME.put("SuppressionXpathFilter",
830                 BASE_PACKAGE + ".filters.SuppressionXpathFilter");
831         NAME_TO_FULL_MODULE_NAME.put("SuppressWarningsFilter",
832                 BASE_PACKAGE + ".filters.SuppressWarningsFilter");
833         NAME_TO_FULL_MODULE_NAME.put("SuppressWithNearbyCommentFilter",
834                 BASE_PACKAGE + ".filters.SuppressWithNearbyCommentFilter");
835     }
836 
837     /**
838      * Fill short-to-full module names map with modules from checkstyle package.
839      */
840     private static void fillModulesFromCheckstylePackage() {
841         NAME_TO_FULL_MODULE_NAME.put("Checker", BASE_PACKAGE + ".Checker");
842         NAME_TO_FULL_MODULE_NAME.put("TreeWalker", BASE_PACKAGE + ".TreeWalker");
843     }
844 
845 }