org.netbeans.modules.java.source 0.104.0 23

org.netbeans.api.java.source
Class ClassIndex

java.lang.Object
  extended by org.netbeans.api.java.source.ClassIndex

public final class ClassIndex
extends Object

The ClassIndex provides access to information stored in the persistent index. It can be used to obtain list of packages or declared types. It can be also used to obtain a list of source files referencing given type (usages of given type).


Nested Class Summary
static class ClassIndex.NameKind
          Encodes a type of the name kind used by getDeclaredTypes(java.lang.String, org.netbeans.api.java.source.ClassIndex.NameKind, java.util.Set) method.
static class ClassIndex.SearchKind
          Encodes a reference type, used by getElements(org.netbeans.api.java.source.ElementHandle, java.util.Set, java.util.Set) and getResources(org.netbeans.api.java.source.ElementHandle, java.util.Set, java.util.Set) to restrict the search.
static class ClassIndex.SearchScope
          Default predefined ClassIndex.SearchScopeTypes
static interface ClassIndex.SearchScopeType
          Scope used by ClassIndex to search in
 
Method Summary
 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<TypeElement>> getDeclaredTypes(String name, ClassIndex.NameKind kind, Set<? extends ClassIndex.SearchScopeType> scope)
          Returns ElementHandles 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 ElementHandles 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 ElementHandles 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> 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addClassIndexListener

public void addClassIndexListener(@NonNull
                                  ClassIndexListener listener)
Adds an ClassIndexListener. The listener is notified about the changes of declared types in this ClassIndex

Parameters:
listener - to be added

removeClassIndexListener

public void removeClassIndexListener(@NonNull
                                     ClassIndexListener listener)
Removes an ClassIndexListener. The listener is notified about the changes of declared types in this ClassIndex

Parameters:
listener - to be removed

getElements

@NullUnknown
public Set<ElementHandle<TypeElement>> getElements(@NonNull
                                                               ElementHandle<TypeElement> element,
                                                               @NonNull
                                                               Set<ClassIndex.SearchKind> searchKind,
                                                               @NonNull
                                                               Set<? extends ClassIndex.SearchScopeType> scope)
Returns a set of ElementHandles containing reference(s) to given type element.

Parameters:
element - the ElementHandle of a TypeElement for which usages should be found
searchKind - type of reference, ClassIndex.SearchKind
scope - to search in ClassIndex.SearchScope
Returns:
set of ElementHandles containing the reference(s) It may return null when the caller is a CancellableTask<CompilationInfo> and is cancelled inside call of this method.

getElementsForPackage

@NullUnknown
public Set<ElementHandle<TypeElement>> getElementsForPackage(@NonNull
                                                                         ElementHandle<PackageElement> element,
                                                                         @NonNull
                                                                         Set<ClassIndex.SearchKind> searchKind,
                                                                         @NonNull
                                                                         Set<? extends ClassIndex.SearchScopeType> scope)
Returns a set of ElementHandles containing reference(s) to given package element.

Parameters:
element - the ElementHandle of a PackageElement for which usages should be found
searchKind - type of reference, ClassIndex.SearchKind
scope - to search in ClassIndex.SearchScope
Returns:
set of ElementHandles containing the reference(s) It may return null when the caller is a CancellableTask<CompilationInfo> and is cancelled inside call of this method.
Since:
0.89

getResources

@NullUnknown
public Set<FileObject> getResources(@NonNull
                                                ElementHandle<TypeElement> element,
                                                @NonNull
                                                Set<ClassIndex.SearchKind> searchKind,
                                                @NonNull
                                                Set<? extends ClassIndex.SearchScopeType> scope)
Returns a set of source files containing reference(s) to given type element.

Parameters:
element - the ElementHandle of a TypeElement for which usages should be found
searchKind - type of reference, ClassIndex.SearchKind
scope - to search in ClassIndex.SearchScope
Returns:
set of FileObjects containing the reference(s) It may return null when the caller is a CancellableTask<CompilationInfo> and is cancelled inside call of this method.

getResourcesForPackage

@NullUnknown
public Set<FileObject> getResourcesForPackage(@NonNull
                                                          ElementHandle<PackageElement> element,
                                                          @NonNull
                                                          Set<ClassIndex.SearchKind> searchKind,
                                                          @NonNull
                                                          Set<? extends ClassIndex.SearchScopeType> scope)
Returns a set of source files containing reference(s) to given package element.

Parameters:
element - the ElementHandle of a PackageElement for which usages should be found
searchKind - type of reference, ClassIndex.SearchKind
scope - to search in ClassIndex.SearchScope
Returns:
set of FileObjects containing the reference(s) It may return null when the caller is a CancellableTask<CompilationInfo> and is cancelled inside call of this method.
Since:
0.89

getDeclaredTypes

@NullUnknown
public Set<ElementHandle<TypeElement>> getDeclaredTypes(@NonNull
                                                                    String name,
                                                                    @NonNull
                                                                    ClassIndex.NameKind kind,
                                                                    @NonNull
                                                                    Set<? extends ClassIndex.SearchScopeType> scope)
Returns ElementHandles for all declared types in given classpath corresponding to the name.

Parameters:
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
Returns:
set of all matched declared types It may return null when the caller is a CancellableTask<CompilationInfo> and is cancelled inside call of this method.

getPackageNames

@NullUnknown
public Set<String> getPackageNames(@NonNull
                                               String prefix,
                                               boolean directOnly,
                                               @NonNull
                                               Set<? extends ClassIndex.SearchScopeType> scope)
Returns names af all packages in given classpath starting with prefix.

Parameters:
prefix - of the package name
directOnly - if true treats the packages as folders and returns only the nearest component of the package.
scope - to search in ClassIndex.SearchScope
Returns:
set of all matched package names It may return null when the caller is a CancellableTask<CompilationInfo> and is cancelled inside call of this method.

createPackageSearchScope

@NonNull
public static ClassIndex.SearchScopeType createPackageSearchScope(@NonNull
                                                                          ClassIndex.SearchScopeType base,
                                                                          @NonNull
                                                                          String... pkgs)
Creates a search scope limited to list of packages.

Parameters:
base - the base search scope to restrict
pkgs - a list of packages in which the search should be performed
Returns:
a newly created search scope
Since:
0.82

org.netbeans.modules.java.source 0.104.0 23

Built on May 22 2012.  |  Portions Copyright 1997-2012 Oracle. All rights reserved.