public final class GlobalPathRegistry extends Object
ClassPaths to the registry
and listen to changes in them.
It is permitted to register the same classpath more than once; unregistration
keeps track of the number of registrations so that the operation is symmetric.
GlobalPathRegistry.getPaths(java.lang.String) only ever returns one copy of the classpath, and
listeners are only notified the first time a given classpath is added to the
registry, or the last time it is removed.
ClassPath equality is based on equality of the
which by default is based on object identity, so there could be multiple paths
returned that at the time share the same list of roots. There may also be
several paths which contain some shared roots.)
The registry is not persisted between JVM sessions.
Intended usage patterns:
When a project is opened using
org.netbeans.spi.project.ui.ProjectOpenedHook it should add any paths
it defines, i.e. paths it might return from a
When closed it should remove them.
The Fast Open feature of the editor and other features which
require a global list of relevant sources should use
The Javadoc Index Search feature and View →
Documentation Indices submenu should operate on open Javadoc paths,
meaning that Javadoc corresponding to registered compile and boot classpaths
Stack trace hyperlinking can use the global list of source paths
to find sources, in case no more specific information about their origin is
available. The same would be true of debugging: if the debugger cannot find
Java-like sources using more precise means (
GlobalPathRegistry.findResource(java.lang.String) as a fallback.
|Modifier and Type
|Method and Description
Add a listener to the registry.
Convenience method to find a particular source file by resource path.
Get the singleton instance of the registry.
Find all paths of a certain type.
Convenience method to find all relevant source roots.
Register some classpaths of a certain type.
Remove a listener to the registry.
Unregister some classpaths of a certain type.
@NonNull public static GlobalPathRegistry getDefault()
id - a classpath type, e.g.
paths - a list of classpaths to add to the registry
public void unregister(@NonNull String id, @NonNull ClassPath paths) throws IllegalArgumentException
public void addGlobalPathRegistryListener(GlobalPathRegistryListener l)
l - a listener to add
public void removeGlobalPathRegistryListener(GlobalPathRegistryListener l)
l - a listener to remove
public Set<FileObject> getSourceRoots()
SourceForBinaryQuery) of all registered
Currently there is no reliable way to listen for changes in the
value of this method: while you can listen to changes in the paths
mentioned, it is possible for
SourceForBinaryQuery results to
change. In the future a change listener might be added for the value
of the source roots.
Note that this method takes no account of package includes/excludes.
FileObject source roots
public FileObject findResource(String resource)
GlobalPathRegistry.getSourceRoots() to find possible roots and
looks up the resource among them.
In case more than one source root contains the resource, one is chosen
ClassPath.findResource(java.lang.String), include/exclude lists can affect the result.
resource - a resource path, e.g. somepkg/Foo.java