Package com.puppycrawl.tools.checkstyle
Class PackageObjectFactory
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.PackageObjectFactory
-
- All Implemented Interfaces:
ModuleFactory
public class PackageObjectFactory extends Object implements ModuleFactory
A factory for creating objects from package names and names. Consider the below example for better understanding.- module name - name of java class that represents module;
- module full name - fully qualifies name of java class that represents module;
- check module short name - name of Check without 'Check' suffix;
- check module name - name of java class that represents Check (with 'Check' suffix);
- check module full name - fully qualifies name of java class that represents Check (with 'Check' suffix).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPackageObjectFactory.ModuleLoadOptionEnum class to define loading options.
-
Field Summary
Fields Modifier and Type Field Description static StringAMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGEException message when there is ambiguous module name in config file.static StringBASE_PACKAGEBase package of checkstyle modules checks.static StringCHECK_SUFFIXSuffix of checks.static StringNULL_LOADER_MESSAGEException message when null class loader is given.static StringNULL_PACKAGE_MESSAGEException message when null package name is given.static StringPACKAGE_SEPARATORCharacter separate package names in qualified name of java class.static StringSTRING_SEPARATORSeparator to use in strings.static StringUNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGEException message when it is unable to create a class instance.
-
Constructor Summary
Constructors Constructor Description PackageObjectFactory(String packageName, ClassLoader moduleClassLoader)Creates a newPackageObjectFactoryinstance.PackageObjectFactory(Set<String> packageNames, ClassLoader moduleClassLoader)Creates a newPackageObjectFactoryinstance.PackageObjectFactory(Set<String> packageNames, ClassLoader moduleClassLoader, PackageObjectFactory.ModuleLoadOption moduleLoadOption)Creates a newPackageObjectFactoryinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectcreateModule(String name)Creates a new instance of a class from a given name, or that name concatenated with "Check".static StringgetShortFromFullModuleNames(String fullName)Returns simple check name from full modules names map.
-
-
-
Field Detail
-
BASE_PACKAGE
public static final String BASE_PACKAGE
Base package of checkstyle modules checks.- See Also:
- Constant Field Values
-
UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE
public static final String UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE
Exception message when it is unable to create a class instance.- See Also:
- Constant Field Values
-
AMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGE
public static final String AMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGE
Exception message when there is ambiguous module name in config file.- See Also:
- Constant Field Values
-
CHECK_SUFFIX
public static final String CHECK_SUFFIX
Suffix of checks.- See Also:
- Constant Field Values
-
PACKAGE_SEPARATOR
public static final String PACKAGE_SEPARATOR
Character separate package names in qualified name of java class.- See Also:
- Constant Field Values
-
NULL_LOADER_MESSAGE
public static final String NULL_LOADER_MESSAGE
Exception message when null class loader is given.- See Also:
- Constant Field Values
-
NULL_PACKAGE_MESSAGE
public static final String NULL_PACKAGE_MESSAGE
Exception message when null package name is given.- See Also:
- Constant Field Values
-
STRING_SEPARATOR
public static final String STRING_SEPARATOR
Separator to use in strings.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PackageObjectFactory
public PackageObjectFactory(Set<String> packageNames, ClassLoader moduleClassLoader)
Creates a newPackageObjectFactoryinstance.- Parameters:
packageNames- the list of package names to usemoduleClassLoader- class loader used to load Checkstyle core and custom modules
-
PackageObjectFactory
public PackageObjectFactory(Set<String> packageNames, ClassLoader moduleClassLoader, PackageObjectFactory.ModuleLoadOption moduleLoadOption)
Creates a newPackageObjectFactoryinstance.- Parameters:
packageNames- the list of package names to usemoduleClassLoader- class loader used to load Checkstyle core and custom modulesmoduleLoadOption- loading option
-
PackageObjectFactory
public PackageObjectFactory(String packageName, ClassLoader moduleClassLoader)
Creates a newPackageObjectFactoryinstance.- Parameters:
packageName- The package name to usemoduleClassLoader- class loader used to load Checkstyle core and custom modules
-
-
Method Detail
-
createModule
public Object createModule(String name) throws CheckstyleException
Creates a new instance of a class from a given name, or that name concatenated with "Check". If the name is a class name, creates an instance of the named class. Otherwise, creates an instance of a class name obtained by concatenating the given name to a package name from a given list of package names.- Specified by:
createModulein interfaceModuleFactory- Parameters:
name- the name of a class.- Returns:
- the
Objectcreated by loader. - Throws:
CheckstyleException- if an error occurs.
-
-