public final class ClassIndex extends Object
Modifier and Type | Method and Description |
---|---|
void |
addClassIndexListener(ClassIndexListener listener)
Adds an
ClassIndexListener . |
static ClassIndex.SearchScopeType |
createPackageSearchScope(ClassIndex.SearchScopeType base,
String... pkgs)
Creates a search scope limited to list of packages.
|
Set<ElementHandle<ModuleElement>> |
getDeclaredModules(String name,
ClassIndex.NameKind kind,
Set<? extends ClassIndex.SearchScopeType> scope)
Returns
ElementHandle s for all declared modules in given classpath corresponding to the name. |
Iterable<ClassIndex.Symbols> |
getDeclaredSymbols(String name,
ClassIndex.NameKind kind,
Set<? extends ClassIndex.SearchScopeType> scope)
Returns descriptions of symbols found on the given classpath and matching the additional criteria.
|
Set<ElementHandle<TypeElement>> |
getDeclaredTypes(String name,
ClassIndex.NameKind kind,
Set<? extends ClassIndex.SearchScopeType> scope)
Returns
ElementHandle s for all declared types in given classpath corresponding to the name. |
Set<ElementHandle<TypeElement>> |
getElements(ElementHandle<TypeElement> element,
Set<ClassIndex.SearchKind> searchKind,
Set<? extends ClassIndex.SearchScopeType> scope)
Returns a set of
ElementHandle s containing reference(s) to given type element. |
Set<ElementHandle<TypeElement>> |
getElementsForPackage(ElementHandle<PackageElement> element,
Set<ClassIndex.SearchKind> searchKind,
Set<? extends ClassIndex.SearchScopeType> scope)
Returns a set of
ElementHandle s containing reference(s) to given package element. |
Set<String> |
getPackageNames(String prefix,
boolean directOnly,
Set<? extends ClassIndex.SearchScopeType> scope)
Returns names af all packages in given classpath starting with prefix.
|
Set<FileObject> |
getResources(ElementHandle<TypeElement> element,
Set<ClassIndex.SearchKind> searchKind,
Set<? extends ClassIndex.SearchScopeType> scope)
Returns a set of source files containing reference(s) to given type element.
|
Set<FileObject> |
getResources(ElementHandle<TypeElement> element,
Set<ClassIndex.SearchKind> searchKind,
Set<? extends ClassIndex.SearchScopeType> scope,
Set<ClassIndex.ResourceType> resourceType)
Returns a set of source or binary files containing reference(s) to given type element.
|
Set<FileObject> |
getResourcesForPackage(ElementHandle<PackageElement> element,
Set<ClassIndex.SearchKind> searchKind,
Set<? extends ClassIndex.SearchScopeType> scope)
Returns a set of source files containing reference(s) to given package element.
|
void |
removeClassIndexListener(ClassIndexListener listener)
Removes an
ClassIndexListener . |
public void addClassIndexListener(@NonNull ClassIndexListener listener)
ClassIndexListener
. The listener is notified about the
changes of declared types in this ClassIndex
listener
- to be addedpublic void removeClassIndexListener(@NonNull ClassIndexListener listener)
ClassIndexListener
. The listener is notified about the
changes of declared types in this ClassIndex
listener
- to be removed@NullUnknown public Set<ElementHandle<TypeElement>> getElements(@NonNull ElementHandle<TypeElement> element, @NonNull Set<ClassIndex.SearchKind> searchKind, @NonNull Set<? extends ClassIndex.SearchScopeType> scope)
ElementHandle
s containing reference(s) to given type element.element
- the ElementHandle
of a TypeElement
for which usages should be foundsearchKind
- type of reference, ClassIndex.SearchKind
scope
- to search in ClassIndex.SearchScope
ElementHandle
s containing the reference(s)
It may return null when the caller is a CancellableTask<CompilationInfo> and is cancelled
inside call of this method.@NullUnknown public Set<ElementHandle<TypeElement>> getElementsForPackage(@NonNull ElementHandle<PackageElement> element, @NonNull Set<ClassIndex.SearchKind> searchKind, @NonNull Set<? extends ClassIndex.SearchScopeType> scope)
ElementHandle
s containing reference(s) to given package element.element
- the ElementHandle
of a PackageElement
for which usages should be foundsearchKind
- type of reference, ClassIndex.SearchKind
scope
- to search in ClassIndex.SearchScope
ElementHandle
s containing the reference(s)
It may return null when the caller is a CancellableTask<CompilationInfo> and is cancelled
inside call of this method.@NullUnknown public Set<FileObject> getResources(@NonNull ElementHandle<TypeElement> element, @NonNull Set<ClassIndex.SearchKind> searchKind, @NonNull Set<? extends ClassIndex.SearchScopeType> scope)
element
- the ElementHandle
of a TypeElement
for which usages should be foundsearchKind
- type of reference, ClassIndex.SearchKind
scope
- to search in ClassIndex.SearchScope
FileObject
s containing the reference(s)
It may return null when the caller is a CancellableTask<CompilationInfo> and is cancelled
inside call of this method.@NullUnknown public Set<FileObject> getResources(@NonNull ElementHandle<TypeElement> element, @NonNull Set<ClassIndex.SearchKind> searchKind, @NonNull Set<? extends ClassIndex.SearchScopeType> scope, @NonNull Set<ClassIndex.ResourceType> resourceType)
element
- the ElementHandle
of a TypeElement
for which usages should be foundsearchKind
- type of reference, ClassIndex.SearchKind
scope
- to search in ClassIndex.SearchScope
resourceType
- to return resource in, ClassIndex.ResourceType
. The ClassIndex.ResourceType.BINARY
produces no result for source roots. For binary roots it does not do SourceForBinaryQuery translation and
returns class files. The ClassIndex.ResourceType.SOURCE
for binary roots does SourceForBinaryQuery translation
and returns corresponding java files or no result when there is no SourceForBinaryQuery configured for given binary root.
The ClassIndex.ResourceType.SOURCE
is preferred to ClassIndex.ResourceType.BINARY
.FileObject
s containing the reference(s)
It may return null when the caller is a CancellableTask<CompilationInfo> and is cancelled
inside call of this method.@NullUnknown public Set<FileObject> getResourcesForPackage(@NonNull ElementHandle<PackageElement> element, @NonNull Set<ClassIndex.SearchKind> searchKind, @NonNull Set<? extends ClassIndex.SearchScopeType> scope)
element
- the ElementHandle
of a PackageElement
for which usages should be foundsearchKind
- type of reference, ClassIndex.SearchKind
scope
- to search in ClassIndex.SearchScope
FileObject
s containing the reference(s)
It may return null when the caller is a CancellableTask<CompilationInfo> and is cancelled
inside call of this method.@NullUnknown public Set<ElementHandle<TypeElement>> getDeclaredTypes(@NonNull String name, @NonNull ClassIndex.NameKind kind, @NonNull Set<? extends ClassIndex.SearchScopeType> scope)
ElementHandle
s for all declared types in given classpath corresponding to the name.name
- case sensitive prefix, case insensitive prefix, exact simple name,
camel case or regular expression depending on the kind parameter.kind
- of the name ClassIndex.NameKind
scope
- to search in ClassIndex.SearchScope
@NullUnknown public Set<ElementHandle<ModuleElement>> getDeclaredModules(@NonNull String name, @NonNull ClassIndex.NameKind kind, @NonNull Set<? extends ClassIndex.SearchScopeType> scope)
ElementHandle
s for all declared modules in given classpath corresponding to the name.name
- case sensitive prefix, case insensitive prefix, exact simple name,
camel case or regular expression depending on the kind parameter.kind
- of the name ClassIndex.NameKind
scope
- to search in ClassIndex.SearchScope
@NullUnknown public Iterable<ClassIndex.Symbols> getDeclaredSymbols(@NonNull String name, @NonNull ClassIndex.NameKind kind, @NonNull Set<? extends ClassIndex.SearchScopeType> scope)
name
- case sensitive prefix, case insensitive prefix, exact simple name,
camel case or regular expression depending on the kind parameter.kind
- of the name ClassIndex.NameKind
scope
- to search in ClassIndex.SearchScope
ClassIndex.Symbols
describing found symbols matching the specified criteria.
It may return null when the caller is a CancellableTask<CompilationInfo> and is cancelled
inside call of this method.@NullUnknown public Set<String> getPackageNames(@NonNull String prefix, boolean directOnly, @NonNull Set<? extends ClassIndex.SearchScopeType> scope)
prefix
- of the package namedirectOnly
- if true treats the packages as folders and returns only
the nearest component of the package.scope
- to search in ClassIndex.SearchScope
@NonNull public static ClassIndex.SearchScopeType createPackageSearchScope(@NonNull ClassIndex.SearchScopeType base, @NonNull String... pkgs)
base
- the base search scope to restrictpkgs
- a list of packages in which the search should be performed