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