Package com.puppycrawl.tools.checkstyle
Class PackageNamesLoader
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- com.puppycrawl.tools.checkstyle.api.AbstractLoader
-
- com.puppycrawl.tools.checkstyle.PackageNamesLoader
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler
,org.xml.sax.DTDHandler
,org.xml.sax.EntityResolver
,org.xml.sax.ErrorHandler
public final class PackageNamesLoader extends AbstractLoader
Loads a list of package names from a package name XML file.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
CHECKSTYLE_PACKAGES
Name of default checkstyle package names resource file.private static java.lang.String
DTD_PUBLIC_ID
The public ID for the configuration dtd.private static java.lang.String
DTD_RESOURCE_NAME
The resource for the configuration dtd.private static java.lang.String
PACKAGE_ELEMENT_NAME
Qualified name for element 'package'.private java.util.Set<java.lang.String>
packageNames
The fully qualified package names.private java.util.Deque<java.lang.String>
packageStack
The temporary stack of package name parts.
-
Constructor Summary
Constructors Modifier Constructor Description private
PackageNamesLoader()
Creates a newPackageNamesLoader
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
private java.lang.String
getPackageName()
Creates a full package name from the package names on the stack.static java.util.Set<java.lang.String>
getPackageNames(java.lang.ClassLoader classLoader)
Returns the set of package names, compiled from all checkstyle_packages.xml files found on the given class loaders classpath.void
startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractLoader
error, fatalError, parseInputSource, resolveEntity
-
-
-
-
Field Detail
-
DTD_PUBLIC_ID
private static final java.lang.String DTD_PUBLIC_ID
The public ID for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_NAME
private static final java.lang.String DTD_RESOURCE_NAME
The resource for the configuration dtd.- See Also:
- Constant Field Values
-
CHECKSTYLE_PACKAGES
private static final java.lang.String CHECKSTYLE_PACKAGES
Name of default checkstyle package names resource file. The file must be in the classpath.- See Also:
- Constant Field Values
-
PACKAGE_ELEMENT_NAME
private static final java.lang.String PACKAGE_ELEMENT_NAME
Qualified name for element 'package'.- See Also:
- Constant Field Values
-
packageStack
private final java.util.Deque<java.lang.String> packageStack
The temporary stack of package name parts.
-
packageNames
private final java.util.Set<java.lang.String> packageNames
The fully qualified package names.
-
-
Constructor Detail
-
PackageNamesLoader
private PackageNamesLoader() throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
Creates a newPackageNamesLoader
instance.- Throws:
javax.xml.parsers.ParserConfigurationException
- if an error occursorg.xml.sax.SAXException
- if an error occurs
-
-
Method Detail
-
startElement
public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
- Specified by:
startElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
startElement
in classorg.xml.sax.helpers.DefaultHandler
-
getPackageName
private java.lang.String getPackageName()
Creates a full package name from the package names on the stack.- Returns:
- the full name of the current package.
-
endElement
public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
- Specified by:
endElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
endElement
in classorg.xml.sax.helpers.DefaultHandler
-
getPackageNames
public static java.util.Set<java.lang.String> getPackageNames(java.lang.ClassLoader classLoader) throws CheckstyleException
Returns the set of package names, compiled from all checkstyle_packages.xml files found on the given class loaders classpath.- Parameters:
classLoader
- the class loader for loading the checkstyle_packages.xml files.- Returns:
- the set of package names.
- Throws:
CheckstyleException
- if an error occurs.
-
-