public abstract class BaseClassLocator extends java.lang.Object implements JavaClassLocator2, JavaResourceLocator, ClasspathTree
BaseClassLocator is an abstract starting point for a
JavaClassLocator that adds the buildIndex()
entry point for instructing the locator to build its index.
Note that that implementations based on the URLClassLocator is intended
to support only top-level classes.| Modifier and Type | Field and Description |
|---|---|
static java.util.Collection |
EMPTY_COLLECTION
Singleton empty collection.
|
static BaseClassLocator |
EMPTY_LOCATOR
Locator implementation that does nothing.
|
static java.lang.String[] |
EMPTY_STRING_ARRAY
Singleton empty list.
|
| Constructor and Description |
|---|
BaseClassLocator() |
| Modifier and Type | Method and Description |
|---|---|
static <T> void |
addToCollection(T[] array,
java.util.Collection<T> collection)
Add an array of objects to a collection.
|
static java.lang.String |
buildFQName(java.lang.String packagePrefix,
java.lang.String className)
Utility routine to build a fully-qualified name.
|
void |
buildIndexInterruptibly()
Instructs this class locator to start building its index for locating
files.
|
protected static void |
checkInterrupt()
Utility method to check if the calling thread has been interrupted.
|
protected static BaseClassLocator |
ensureValid(BaseClassLocator locator)
Utility routine to ensure that there is a valid locator available.
|
java.util.Collection<java.lang.String> |
getAllClasses()
Fetch all of the top-level classes that are known by this locator.
|
java.util.Collection<java.lang.String> |
getAllClasses(ClassNameFilter filter)
Fetch all of the top-level classes that are known by this locator that
satisfies the given filter.
|
abstract void |
getAllClasses(java.util.Collection<java.lang.String> out,
ClassNameFilter filter)
Fetch all of the top-level classes that are known by this locator.
|
java.util.Collection<java.lang.String> |
getAllClassesInterruptibly()
Fetch all of the top-level classes that are known by this locator.
|
java.util.Collection<java.lang.String> |
getAllClassesInterruptibly(ClassNameFilter filter)
Fetch all of the top-level classes that are known by this locator that
satisfies the given filter.
|
void |
getAllClassesInterruptibly(java.util.Collection<java.lang.String> out,
ClassNameFilter filter)
Get all of the top-level classes that are known by this locator.
|
java.util.Collection<java.lang.String> |
getAllPackages()
Fetch all of the full packges that are known by this locator.
|
abstract void |
getAllPackages(java.util.Collection<java.lang.String> out,
PackageNameFilter filter)
Fetch all of the full packges that are known by this locator.
|
java.util.Collection<java.lang.String> |
getAllPackages(PackageNameFilter filter)
Fetch all of the packages that are known by this locator that satisfies
the given filter.
|
java.util.Collection<java.lang.String> |
getAllPackagesInterruptibly()
Fetch all of the full packges that are known by this locator.
|
void |
getAllPackagesInterruptibly(java.util.Collection<java.lang.String> out,
PackageNameFilter filter)
Get all of the full packges that are known by this locator.
|
java.util.Collection<java.lang.String> |
getAllPackagesInterruptibly(PackageNameFilter filter)
Fetch all of the packages that are known by this locator that satisfies
the given filter.
|
protected java.util.Collection<BaseClassLocator> |
getChildLocators(java.util.EnumSet<ClasspathTreeVisitOptions> options)
Get the child class locators to be visited.
|
java.util.Collection<java.lang.String> |
getClassesByName(java.lang.String name,
boolean matchCase)
Fetch all of the top-level classes that are known by this locator with
the given class name.
|
java.util.Collection<java.lang.String> |
getClassesByNameInterruptibly(java.lang.String name,
boolean matchCase)
Fetch all of the top-level classes that are known by this locator with
the given class name.
|
java.util.Collection<java.lang.String> |
getClassesByPrefix(java.lang.String prefix,
boolean matchCase)
Fetch all of the top-level classes that are known by this locator whose
given class name starts with the specified prefix.
|
java.util.Collection<java.lang.String> |
getClassesByPrefixInterruptibly(java.lang.String prefix,
boolean matchCase)
Fetch all of the top-level classes that are known by this locator whose
given class name starts with the specified prefix.
|
protected java.util.Collection<java.lang.String> |
getClassesDirectly()
Get the top-level classes that are known directly by this class locator,
not including those known to child locators.
|
java.util.Collection<java.lang.String> |
getClassesInPackage(java.lang.String packagePrefix)
Fetch the top-level classes within the given package prefix.
|
abstract void |
getClassesInPackage(java.lang.String packagePrefix,
java.util.Collection<java.lang.String> out)
Fetch the list of top-level classes within the given package, adding them
to the out collection provided.
|
java.util.Collection<java.lang.String> |
getClassesInPackageInterruptibly(java.lang.String packagePrefix)
Fetch the top-level classes within the given package prefix.
|
void |
getClassesInPackageInterruptibly(java.lang.String packagePrefix,
java.util.Collection<java.lang.String> out)
Get the list of top-level classes within the package.
|
protected java.lang.Object |
getClasspathTreeNode()
Get the classpath tree node corresponding to this locator.
|
java.net.URL |
getClassURLInterruptibly(java.lang.String fqClassName)
Fetch the URL for the JavaFile for the given fully-qualified Java class
name.
|
protected static java.lang.String[] |
getNameCascades(java.lang.String fqName)
Utility routine to take a fully-qualified name, and split it into
"cascades".
|
protected static java.lang.String[] |
getNameParts(java.lang.String fqName)
Utility routine to take a fully-qualified name, and split it into
its parts.
|
java.util.Collection<java.lang.String> |
getPackages(java.lang.String packagePrefix)
Fetch the list of subpackages within the given package.
|
abstract void |
getPackages(java.lang.String packagePrefix,
java.util.Collection<java.lang.String> out)
Fetch the list of subpackages within the given package, adding them
to the out collection provided.
|
java.util.Collection<java.lang.String> |
getPackagesInterruptibly(java.lang.String packagePrefix)
Fetch the list of subpackages within the given package.
|
void |
getPackagesInterruptibly(java.lang.String packagePrefix,
java.util.Collection<java.lang.String> out)
Get the list of subpackages within the given package.
|
protected java.util.Collection<java.net.URL> |
getResourcesDirectly(java.lang.String name)
Get the resources with the given name that are known directly by this
class locator, not including those known to child locators.
|
java.util.Collection<java.net.URL> |
getResourceURLs(java.lang.String resourceName)
Fetch all the URL's for the Java resource file given the resource name.
|
protected BaseClassLocator |
getSourceLocator(BaseClassLocator locator) |
java.net.URL |
getSourceURLInterruptibly(java.lang.String fqClassName)
Fetch the URL for the SourceFile for the given fully-qualified Java
class name.
|
static java.lang.String[] |
getStringArray(java.util.Collection<java.lang.String> collection)
Convert a collection of Strings into a String array.
|
java.net.URL |
getURLInterruptibly(java.lang.String fqClassName)
Fetch the URL for the JavaFile for the given fully-qualified Java class
name.
|
void |
visitClasspathTree(ClasspathTreeVisitor visitor)
Visit the classpath tree.
|
void |
visitClasspathTree(ClasspathTreeVisitor visitor,
java.util.EnumSet<ClasspathTreeVisitOptions> options)
Visit the classpath tree.
|
void |
visitJavaTypes(JavaTypeVisitor visitor)
Visit the Java types available in the classpath tree.
|
void |
visitJavaTypes(JavaTypeVisitor visitor,
java.util.EnumSet<ClasspathTreeVisitOptions> options)
Visit the Java types available in the classpath tree.
|
void |
visitResources(java.lang.String name,
ResourceVisitor visitor)
Visit the resources available in the classpath tree.
|
void |
visitResources(java.lang.String name,
ResourceVisitor visitor,
java.util.EnumSet<ClasspathTreeVisitOptions> options)
Visit the resources available in the classpath tree.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuildIndex, getClassURL, getSourceURL, getURLgetClassURL, getResourceURLpublic static final BaseClassLocator EMPTY_LOCATOR
public static final java.lang.String[] EMPTY_STRING_ARRAY
public static final java.util.Collection EMPTY_COLLECTION
public void buildIndexInterruptibly()
throws java.lang.InterruptedException
JavaClassLocator2buildIndexInterruptibly in interface JavaClassLocator2java.lang.InterruptedException - if the build is interruptedpublic java.util.Collection<java.net.URL> getResourceURLs(java.lang.String resourceName)
JavaResourceLocatorgetResourceURLs in interface JavaResourceLocatorresourceName - the full name of the resource including any file
extensionspublic java.util.Collection<java.lang.String> getPackages(java.lang.String packagePrefix)
getPackages in interface JavaClassLocatorpackagePrefix - the package prefix, i.e., "java.io"public java.util.Collection<java.lang.String> getPackagesInterruptibly(java.lang.String packagePrefix)
throws java.lang.InterruptedException
JavaClassLocator2getPackagesInterruptibly in interface JavaClassLocator2packagePrefix - the package prefix, i.e., "java.io"java.lang.InterruptedException - if the operation is interruptedpublic abstract void getPackages(java.lang.String packagePrefix,
java.util.Collection<java.lang.String> out)
packagePrefix - the package prefix, i.e., "java.io"out - the collection to add the packagespublic void getPackagesInterruptibly(java.lang.String packagePrefix,
java.util.Collection<java.lang.String> out)
throws java.lang.InterruptedException
packagePrefix - the package prefixout - the collection where packages are addedjava.lang.InterruptedException - if the operation is interruptedpublic java.util.Collection<java.lang.String> getClassesInPackage(java.lang.String packagePrefix)
getClassesInPackage in interface JavaClassLocatorpackagePrefix - the package prefix, i.e., "java.io"public java.util.Collection<java.lang.String> getClassesInPackageInterruptibly(java.lang.String packagePrefix)
throws java.lang.InterruptedException
JavaClassLocator2getClassesInPackageInterruptibly in interface JavaClassLocator2packagePrefix - the package prefix, i.e., "java.io"java.lang.InterruptedException - if the operation is interruptedpublic abstract void getClassesInPackage(java.lang.String packagePrefix,
java.util.Collection<java.lang.String> out)
packagePrefix - the package prefix, i.e., "java.io"out - the collection to add the class namespublic void getClassesInPackageInterruptibly(java.lang.String packagePrefix,
java.util.Collection<java.lang.String> out)
throws java.lang.InterruptedException
packagePrefix - the package prefixout - the collection where packages are addedjava.lang.InterruptedException - if the operation is interruptedpublic java.util.Collection<java.lang.String> getAllClasses()
getAllClasses in interface JavaClassLocatorpublic java.util.Collection<java.lang.String> getAllClassesInterruptibly()
throws java.lang.InterruptedException
JavaClassLocator2getAllClassesInterruptibly in interface JavaClassLocator2java.lang.InterruptedException - if the operation is interruptedpublic java.util.Collection<java.lang.String> getAllClasses(ClassNameFilter filter)
getAllClasses in interface JavaClassLocatorfilter - the class name filter to use for the searchpublic java.util.Collection<java.lang.String> getAllClassesInterruptibly(ClassNameFilter filter) throws java.lang.InterruptedException
JavaClassLocator2getAllClassesInterruptibly in interface JavaClassLocator2filter - the class name filter to use for the searchjava.lang.InterruptedException - if the operation is interruptedpublic abstract void getAllClasses(java.util.Collection<java.lang.String> out,
ClassNameFilter filter)
out - the collection to add the fully-qualified class namesfilter - the class name filter to usepublic void getAllClassesInterruptibly(java.util.Collection<java.lang.String> out,
ClassNameFilter filter)
throws java.lang.InterruptedException
out - the collection where fully qualified class names are addedfilter - the class name filter to usejava.lang.InterruptedException - if the operation is interruptedprotected java.util.Collection<java.lang.String> getClassesDirectly()
protected java.util.Collection<java.net.URL> getResourcesDirectly(java.lang.String name)
name - the resource namepublic java.util.Collection<java.lang.String> getAllPackages()
getAllPackages in interface JavaClassLocatorpublic java.util.Collection<java.lang.String> getAllPackagesInterruptibly()
throws java.lang.InterruptedException
JavaClassLocator2getAllPackagesInterruptibly in interface JavaClassLocator2java.lang.InterruptedException - if the operation is interruptedpublic java.util.Collection<java.lang.String> getAllPackages(PackageNameFilter filter)
getAllPackages in interface JavaClassLocatorfilter - the package name filter to use for the searchpublic java.util.Collection<java.lang.String> getAllPackagesInterruptibly(PackageNameFilter filter) throws java.lang.InterruptedException
JavaClassLocator2getAllPackagesInterruptibly in interface JavaClassLocator2filter - the package name filter to use for the searchjava.lang.InterruptedException - if the operation is interruptedpublic abstract void getAllPackages(java.util.Collection<java.lang.String> out,
PackageNameFilter filter)
out - the collection to add the full package namesfilter - the package name filter to usepublic void getAllPackagesInterruptibly(java.util.Collection<java.lang.String> out,
PackageNameFilter filter)
throws java.lang.InterruptedException
out - the collection where package names are addedfilter - the package name filter to usejava.lang.InterruptedException - if the operation is interruptedpublic java.util.Collection<java.lang.String> getClassesByName(java.lang.String name,
boolean matchCase)
getClassesByName in interface JavaClassLocatorname - the unqualified name of the top-level class to locatematchCase - whether to use case-sensitivity for matching the
class namepublic java.util.Collection<java.lang.String> getClassesByNameInterruptibly(java.lang.String name,
boolean matchCase)
throws java.lang.InterruptedException
JavaClassLocator2getClassesByNameInterruptibly in interface JavaClassLocator2name - the unqualified name of the top-level class to locatematchCase - whether to use case-sensitivity for matching the
class namejava.lang.InterruptedException - if the operation is interruptedpublic java.util.Collection<java.lang.String> getClassesByPrefix(java.lang.String prefix,
boolean matchCase)
getClassesByPrefix in interface JavaClassLocatorprefix - the starting prefix of the class name to locatematchCase - whether to use case-sensitivity for matching the
class namepublic java.util.Collection<java.lang.String> getClassesByPrefixInterruptibly(java.lang.String prefix,
boolean matchCase)
throws java.lang.InterruptedException
JavaClassLocator2getClassesByPrefixInterruptibly in interface JavaClassLocator2prefix - the starting prefix of the class name to locatematchCase - whether to use case-sensitivity for matching the
class namejava.lang.InterruptedException - if the operation is interruptedpublic java.net.URL getURLInterruptibly(java.lang.String fqClassName)
throws java.lang.InterruptedException
JavaClassLocator2getURLInterruptibly in interface JavaClassLocator2fqClassName - the fully-qualified class name in dotted notation,
i.e., java.util.Listjava.lang.InterruptedException - if the operation is interruptedpublic java.net.URL getSourceURLInterruptibly(java.lang.String fqClassName)
throws java.lang.InterruptedException
JavaClassLocator2getSourceURLInterruptibly in interface JavaClassLocator2fqClassName - the fully-qualified class name in dotted notationjava.lang.InterruptedException - if the operation is interruptedpublic java.net.URL getClassURLInterruptibly(java.lang.String fqClassName)
throws java.lang.InterruptedException
JavaClassLocator2getClassURLInterruptibly in interface JavaClassLocator2fqClassName - the fully-qualified class name in dotted notationjava.lang.InterruptedException - if the operation is interruptedprotected java.lang.Object getClasspathTreeNode()
null if there is no classpath
tree node corresponding to this locatorClasspathTreeprotected java.util.Collection<BaseClassLocator> getChildLocators(java.util.EnumSet<ClasspathTreeVisitOptions> options)
options - the classpath tree visit optionsprotected BaseClassLocator getSourceLocator(BaseClassLocator locator)
public final void visitClasspathTree(ClasspathTreeVisitor visitor)
ClasspathTreevisitClasspathTree in interface ClasspathTreevisitor - the visitorpublic final void visitClasspathTree(ClasspathTreeVisitor visitor, java.util.EnumSet<ClasspathTreeVisitOptions> options)
ClasspathTreevisitClasspathTree in interface ClasspathTreevisitor - the visitoroptions - the visit optionspublic final void visitJavaTypes(JavaTypeVisitor visitor)
ClasspathTreevisitJavaTypes in interface ClasspathTreevisitor - the visitorpublic final void visitJavaTypes(JavaTypeVisitor visitor, java.util.EnumSet<ClasspathTreeVisitOptions> options)
ClasspathTreevisitJavaTypes in interface ClasspathTreevisitor - the visitoroptions - the visit optionspublic final void visitResources(java.lang.String name,
ResourceVisitor visitor)
ClasspathTreevisitResources in interface ClasspathTreename - the resource namevisitor - the visitorpublic final void visitResources(java.lang.String name,
ResourceVisitor visitor,
java.util.EnumSet<ClasspathTreeVisitOptions> options)
ClasspathTreevisitResources in interface ClasspathTreename - the resource namevisitor - the visitoroptions - the visit optionsprotected static void checkInterrupt()
throws java.lang.InterruptedException
java.lang.InterruptedException - if the calling thread has been interruptedprotected static BaseClassLocator ensureValid(BaseClassLocator locator)
locator - the locator to ensure is validpublic static <T> void addToCollection(T[] array,
java.util.Collection<T> collection)
array - the array of objectscollection - the collection to add topublic static java.lang.String[] getStringArray(java.util.Collection<java.lang.String> collection)
collection - the collection of Stringspublic static java.lang.String buildFQName(java.lang.String packagePrefix,
java.lang.String className)
packagePrefix - the package prefix to useclassName - the class name to useprotected static java.lang.String[] getNameParts(java.lang.String fqName)
protected static java.lang.String[] getNameCascades(java.lang.String fqName)