public class SearchEngine
extends java.lang.Object
SearchEngine
searches for JavaScript elements following a search pattern.
The search can be limited to a search scope.
Various search patterns can be created using the factory methods
SearchPattern.createPattern(String, int, int, int)
, SearchPattern.createPattern(IJavaScriptElement, int)
,
SearchPattern.createOrPattern(SearchPattern, SearchPattern)
.
For example, one can search for references to a method in the hierarchy of a type, or one can search for the declarations of types starting with "Abstract" in a project.
This class may be instantiated; it is not intended to be subclassed.
Provisional API: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.Constructor and Description |
---|
SearchEngine()
Creates a new search engine.
|
SearchEngine(IJavaScriptUnit[] workingCopies)
Creates a new search engine with a list of working copies that will take precedence over
their original javascript unit s in the subsequent search operations.
|
SearchEngine(WorkingCopyOwner workingCopyOwner)
Creates a new search engine with the given working copy owner.
|
Modifier and Type | Method and Description |
---|---|
static IJavaScriptSearchScope |
createHierarchyScope(IType type)
Returns a JavaScript search scope limited to the hierarchy of the given type.
|
static IJavaScriptSearchScope |
createHierarchyScope(IType type,
WorkingCopyOwner owner)
Returns a JavaScript search scope limited to the hierarchy of the given type.
|
static IJavaScriptSearchScope |
createJavaSearchScope(IJavaScriptElement[] elements)
Returns a JavaScript search scope limited to the given JavaScript elements.
|
static IJavaScriptSearchScope |
createJavaSearchScope(IJavaScriptElement[] elements,
boolean includeReferencedProjects)
Returns a JavaScript search scope limited to the given JavaScript elements.
|
static IJavaScriptSearchScope |
createJavaSearchScope(IJavaScriptElement[] elements,
int includeMask)
Returns a JavaScript search scope limited to the given JavaScript elements.
|
static TypeNameMatch |
createTypeNameMatch(IType type,
int modifiers)
Create a type name match on a given type with specific modifiers.
|
static IJavaScriptSearchScope |
createWorkspaceScope()
Returns a JavaScript search scope with the workspace as the only limit.
|
static char[][] |
getAllSubtypeNames(char[] typeName,
IJavaScriptSearchScope scope,
int waitingPolicy,
IProgressMonitor progressMonitor)
Gets all the names of subtypes of a given type name in the given
scope.
|
static char[][] |
getAllSynonyms(char[] typeName,
IJavaScriptSearchScope scope,
int waitingPolicy,
IProgressMonitor progressMonitor)
Gets all the synonyms of a given type, including itself, in the given
scope.
|
static SearchParticipant |
getDefaultSearchParticipant()
Returns a new default JavaScript search participant.
|
void |
search(SearchPattern pattern,
SearchParticipant[] participants,
IJavaScriptSearchScope scope,
SearchRequestor requestor,
IProgressMonitor monitor)
Searches for matches of a given search pattern.
|
void |
searchAllTypeNames(char[][] qualifications,
char[][] typeNames,
IJavaScriptSearchScope scope,
TypeNameMatchRequestor nameMatchRequestor,
int waitingPolicy,
IProgressMonitor progressMonitor)
Searches for all top-level types and member types in the given scope matching any of the given qualifications
and type names in a case sensitive way.
|
void |
searchAllTypeNames(char[][] qualifications,
char[][] typeNames,
IJavaScriptSearchScope scope,
TypeNameRequestor nameRequestor,
int waitingPolicy,
IProgressMonitor progressMonitor)
Searches for all top-level types and member types in the given scope matching any of the given qualifications
and type names in a case sensitive way.
|
void |
searchAllTypeNames(char[] packageName,
int packageMatchRule,
char[] typeName,
int typeMatchRule,
int searchFor,
IJavaScriptSearchScope scope,
TypeNameMatchRequestor nameMatchRequestor,
int waitingPolicy,
IProgressMonitor progressMonitor)
Searches for all top-level types and member types in the given scope.
|
void |
searchAllTypeNames(char[] packageName,
int packageMatchRule,
char[] typeName,
int typeMatchRule,
int searchFor,
IJavaScriptSearchScope scope,
TypeNameRequestor nameRequestor,
int waitingPolicy,
IProgressMonitor progressMonitor)
Searches for all top-level types and member types in the given scope.
|
void |
searchAllTypeNames(char[] prefix,
int typeMatchRule,
int searchFor,
IJavaScriptSearchScope scope,
TypeNameMatchRequestor nameMatchRequestor,
int waitingPolicy,
IProgressMonitor progressMonitor)
Searches for all top-level types and member types in the given scope.
|
void |
searchDeclarationsOfAccessedFields(IJavaScriptElement enclosingElement,
SearchRequestor requestor,
IProgressMonitor monitor)
Searches for all declarations of the fields accessed in the given element.
|
void |
searchDeclarationsOfReferencedTypes(IJavaScriptElement enclosingElement,
SearchRequestor requestor,
IProgressMonitor monitor)
Searches for all declarations of the types referenced in the given element.
|
void |
searchDeclarationsOfSentMessages(IJavaScriptElement enclosingElement,
SearchRequestor requestor,
IProgressMonitor monitor)
Searches for all declarations of the methods invoked in the given element.
|
public SearchEngine()
public SearchEngine(IJavaScriptUnit[] workingCopies)
Note that passing an empty working copy will be as if the original compilation unit had been deleted.
Since 3.0 the given working copies take precedence over primary working copies (if any).
workingCopies
- the working copies that take precedence over their original javascript unit spublic SearchEngine(WorkingCopyOwner workingCopyOwner)
workingCopyOwner
- the owner of the working copies that take precedence over their original javascript unit spublic static IJavaScriptSearchScope createHierarchyScope(IType type) throws JavaScriptModelException
type
- the focus of the hierarchy scopeJavaScriptModelException
- if the hierarchy could not be computed on the given typepublic static IJavaScriptSearchScope createHierarchyScope(IType type, WorkingCopyOwner owner) throws JavaScriptModelException
type
- the focus of the hierarchy scopeowner
- the owner of working copies that take precedence over original javascript unit sJavaScriptModelException
- if the hierarchy could not be computed on the given typepublic static IJavaScriptSearchScope createJavaSearchScope(IJavaScriptElement[] elements)
If an element is an IJavaScriptProject, then the project's source folders, its jars (external and internal) and its referenced projects (with their source folders and jars, recursively) will be included. If an element is an IPackageFragmentRoot, then only the package fragments of this package fragment root will be included. If an element is an IPackageFragment, then only the javascript unit and class files of this package fragment will be included. Subpackages will NOT be included.
In other words, this is equivalent to using SearchEngine.createJavaSearchScope(elements, true).
elements
- the JavaScript elements the scope is limited topublic static IJavaScriptSearchScope createJavaSearchScope(IJavaScriptElement[] elements, boolean includeReferencedProjects)
elements
- the JavaScript elements the scope is limited toincludeReferencedProjects
- a flag indicating if referenced projects must be
recursively includedpublic static IJavaScriptSearchScope createJavaSearchScope(IJavaScriptElement[] elements, int includeMask)
elements
- the JavaScript elements the scope is limited toincludeMask
- the bit-wise OR of all include types of interestIJavaScriptSearchScope.SOURCES
,
IJavaScriptSearchScope.APPLICATION_LIBRARIES
,
IJavaScriptSearchScope.SYSTEM_LIBRARIES
,
IJavaScriptSearchScope.REFERENCED_PROJECTS
public static TypeNameMatch createTypeNameMatch(IType type, int modifiers)
type
- The javascript model handle of the typemodifiers
- Modifiers of the typepublic static IJavaScriptSearchScope createWorkspaceScope()
public static SearchParticipant getDefaultSearchParticipant()
public void search(SearchPattern pattern, SearchParticipant[] participants, IJavaScriptSearchScope scope, SearchRequestor requestor, IProgressMonitor monitor) throws CoreException
pattern
- the pattern to searchparticipants
- the particpants in the searchscope
- the search scoperequestor
- the requestor to report the matches tomonitor
- the progress monitor used to report progressCoreException
- if the search failed. Reasons include:
public void searchAllTypeNames(char[] packageName, int packageMatchRule, char[] typeName, int typeMatchRule, int searchFor, IJavaScriptSearchScope scope, TypeNameRequestor nameRequestor, int waitingPolicy, IProgressMonitor progressMonitor) throws JavaScriptModelException
packageName
- the full name of the package of the searched types, or a prefix for this
package, or a wild-carded string for this package.
May be null
, then any package name is accepted.typeName
- the dot-separated qualified name of the searched type (the qualification include
the enclosing types if the searched type is a member type), or a prefix
for this type, or a wild-carded string for this type.
May be null
, then any type name is accepted.packageMatchRule
- ignoredtypeMatchRule
- one of
SearchPattern.R_EXACT_MATCH
if the package name and type name are the full names
of the searched types.SearchPattern.R_PREFIX_MATCH
if the package name and type name are prefixes of the names
of the searched types.SearchPattern.R_PATTERN_MATCH
if the package name and type name contain wild-cards.SearchPattern.R_CAMELCASE_MATCH
if type name are camel case of the names of the searched types.SearchPattern.R_CASE_SENSITIVE
,
e.g. SearchPattern.R_EXACT_MATCH
| SearchPattern.R_CASE_SENSITIVE
if an exact and case sensitive match is requested,
or SearchPattern.R_PREFIX_MATCH
if a prefix non case sensitive match is requested.searchFor
- determines the nature of the searched elements
IJavaScriptSearchConstants.CLASS
: only look for classesIJavaScriptSearchConstants#INTERFACE
: only look for interfacesIJavaScriptSearchConstants.ENUM
: only look for enumerationIJavaScriptSearchConstants#ANNOTATION_TYPE
: only look for annotation typeIJavaScriptSearchConstants#CLASS_AND_ENUM
: only look for classes and enumerationsIJavaScriptSearchConstants#CLASS_AND_INTERFACE
: only look for classes and interfacesIJavaScriptSearchConstants.TYPE
: look for all types (ie. classes, interfaces, enum and annotation types)scope
- the scope to search innameRequestor
- the requestor that collects the results of the searchwaitingPolicy
- one of
IJavaScriptSearchConstants.FORCE_IMMEDIATE_SEARCH
if the search should start immediatelyIJavaScriptSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH
if the search should be cancelled if the
underlying indexer has not finished indexing the workspaceIJavaScriptSearchConstants.WAIT_UNTIL_READY_TO_SEARCH
if the search should wait for the
underlying indexer to finish indexing the workspaceprogressMonitor
- the progress monitor to report progress to, or null
if no progress
monitor is providedJavaScriptModelException
- if the search failed. Reasons include:
public void searchAllTypeNames(char[] prefix, int typeMatchRule, int searchFor, IJavaScriptSearchScope scope, TypeNameMatchRequestor nameMatchRequestor, int waitingPolicy, IProgressMonitor progressMonitor) throws JavaScriptModelException
Provided TypeNameMatchRequestor
requestor will collect TypeNameMatch
matches found during the search.
prefix
- The prefix could be part of the qualification or simple name for a type,
or it could be a camel case statement for a simple name of a type.typeMatchRule
- one of
SearchPattern.R_EXACT_MATCH
if the package name and type name are the full names
of the searched types.SearchPattern.R_PREFIX_MATCH
if the package name and type name are prefixes of the names
of the searched types.SearchPattern.R_PATTERN_MATCH
if the package name and type name contain wild-cards.SearchPattern.R_CAMELCASE_MATCH
if type name are camel case of the names of the searched types.SearchPattern.R_CASE_SENSITIVE
,
e.g. SearchPattern.R_EXACT_MATCH
| SearchPattern.R_CASE_SENSITIVE
if an exact and case sensitive match is requested,
or SearchPattern.R_PREFIX_MATCH
if a prefix non case sensitive match is requested.searchFor
- determines the nature of the searched elements
IJavaScriptSearchConstants.CLASS
: only look for classesIJavaScriptSearchConstants#INTERFACE
: only look for interfacesIJavaScriptSearchConstants.ENUM
: only look for enumerationIJavaScriptSearchConstants#ANNOTATION_TYPE
: only look for annotation typeIJavaScriptSearchConstants#CLASS_AND_ENUM
: only look for classes and enumerationsIJavaScriptSearchConstants#CLASS_AND_INTERFACE
: only look for classes and interfacesIJavaScriptSearchConstants.TYPE
: look for all types (ie. classes, interfaces, enum and annotation types)scope
- the scope to search innameMatchRequestor
- the requestor
that collects
matches
of the search.waitingPolicy
- one of
IJavaScriptSearchConstants.FORCE_IMMEDIATE_SEARCH
if the search should start immediatelyIJavaScriptSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH
if the search should be cancelled if the
underlying indexer has not finished indexing the workspaceIJavaScriptSearchConstants.WAIT_UNTIL_READY_TO_SEARCH
if the search should wait for the
underlying indexer to finish indexing the workspaceprogressMonitor
- the progress monitor to report progress to, or null
if no progress
monitor is providedJavaScriptModelException
- if the search failed. Reasons include:
public void searchAllTypeNames(char[] packageName, int packageMatchRule, char[] typeName, int typeMatchRule, int searchFor, IJavaScriptSearchScope scope, TypeNameMatchRequestor nameMatchRequestor, int waitingPolicy, IProgressMonitor progressMonitor) throws JavaScriptModelException
Provided TypeNameMatchRequestor
requestor will collect TypeNameMatch
matches found during the search.
packageName
- the full name of the package of the searched types, or a prefix for this
package, or a wild-carded string for this package.
May be null
, then any package name is accepted.packageMatchRule
- IGNOREDtypeName
- the dot-separated qualified name of the searched type (the qualification include
the enclosing types if the searched type is a member type), or a prefix
for this type, or a wild-carded string for this type.
May be null
, then any type name is accepted.typeMatchRule
- one of
SearchPattern.R_EXACT_MATCH
if the package name and type name are the full names
of the searched types.SearchPattern.R_PREFIX_MATCH
if the package name and type name are prefixes of the names
of the searched types.SearchPattern.R_PATTERN_MATCH
if the package name and type name contain wild-cards.SearchPattern.R_CAMELCASE_MATCH
if type name are camel case of the names of the searched types.SearchPattern.R_CASE_SENSITIVE
,
e.g. SearchPattern.R_EXACT_MATCH
| SearchPattern.R_CASE_SENSITIVE
if an exact and case sensitive match is requested,
or SearchPattern.R_PREFIX_MATCH
if a prefix non case sensitive match is requested.searchFor
- determines the nature of the searched elements
IJavaScriptSearchConstants.CLASS
: only look for classesIJavaScriptSearchConstants#INTERFACE
: only look for interfacesIJavaScriptSearchConstants.ENUM
: only look for enumerationIJavaScriptSearchConstants#ANNOTATION_TYPE
: only look for annotation typeIJavaScriptSearchConstants#CLASS_AND_ENUM
: only look for classes and enumerationsIJavaScriptSearchConstants#CLASS_AND_INTERFACE
: only look for classes and interfacesIJavaScriptSearchConstants.TYPE
: look for all types (ie. classes, interfaces, enum and annotation types)scope
- the scope to search innameMatchRequestor
- the requestor
that collects
matches
of the search.waitingPolicy
- one of
IJavaScriptSearchConstants.FORCE_IMMEDIATE_SEARCH
if the search should start immediatelyIJavaScriptSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH
if the search should be cancelled if the
underlying indexer has not finished indexing the workspaceIJavaScriptSearchConstants.WAIT_UNTIL_READY_TO_SEARCH
if the search should wait for the
underlying indexer to finish indexing the workspaceprogressMonitor
- the progress monitor to report progress to, or null
if no progress
monitor is providedJavaScriptModelException
- if the search failed. Reasons include:
public void searchAllTypeNames(char[][] qualifications, char[][] typeNames, IJavaScriptSearchScope scope, TypeNameRequestor nameRequestor, int waitingPolicy, IProgressMonitor progressMonitor) throws JavaScriptModelException
qualifications
- the qualified name of the package/enclosing type of the searched types.
May be null
, then any package name is accepted.typeNames
- the simple names of the searched types.
If this parameter is null
, then no type will be found.scope
- the scope to search innameRequestor
- the requestor that collects the results of the searchwaitingPolicy
- one of
IJavaScriptSearchConstants.FORCE_IMMEDIATE_SEARCH
if the search should start immediatelyIJavaScriptSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH
if the search should be cancelled if the
underlying indexer has not finished indexing the workspaceIJavaScriptSearchConstants.WAIT_UNTIL_READY_TO_SEARCH
if the search should wait for the
underlying indexer to finish indexing the workspaceprogressMonitor
- the progress monitor to report progress to, or null
if no progress
monitor is providedJavaScriptModelException
- if the search failed. Reasons include:
public void searchAllTypeNames(char[][] qualifications, char[][] typeNames, IJavaScriptSearchScope scope, TypeNameMatchRequestor nameMatchRequestor, int waitingPolicy, IProgressMonitor progressMonitor) throws JavaScriptModelException
Provided TypeNameMatchRequestor
requestor will collect TypeNameMatch
matches found during the search.
qualifications
- the qualified name of the package/enclosing type of the searched types.
May be null
, then any package name is accepted.typeNames
- the simple names of the searched types.
If this parameter is null
, then no type will be found.scope
- the scope to search innameMatchRequestor
- the requestor
that collects
matches
of the search.waitingPolicy
- one of
IJavaScriptSearchConstants.FORCE_IMMEDIATE_SEARCH
if the search should start immediatelyIJavaScriptSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH
if the search should be cancelled if the
underlying indexer has not finished indexing the workspaceIJavaScriptSearchConstants.WAIT_UNTIL_READY_TO_SEARCH
if the search should wait for the
underlying indexer to finish indexing the workspaceprogressMonitor
- the progress monitor to report progress to, or null
if no progress
monitor is providedJavaScriptModelException
- if the search failed. Reasons include:
public void searchDeclarationsOfAccessedFields(IJavaScriptElement enclosingElement, SearchRequestor requestor, IProgressMonitor monitor) throws JavaScriptModelException
Consider the following code:
then searching for declarations of accessed fields in method
class A {
int field1;
}
class B extends A {
String value;
}
class X {
void test() {
B b = new B();
System.out.println(b.value + b.field1);
};
}
X.test()
would collect the fields
B.value
and A.field1
.
enclosingElement
- the method, type, or javascript unit to be searched inrequestor
- a callback object to which each match is reportedmonitor
- the progress monitor used to report progressJavaScriptModelException
- if the search failed. Reasons include:
public void searchDeclarationsOfReferencedTypes(IJavaScriptElement enclosingElement, SearchRequestor requestor, IProgressMonitor monitor) throws JavaScriptModelException
Consider the following code:
then searching for declarations of referenced types in method
class A {
}
class B extends A {
}
interface I {
int VALUE = 0;
}
class X {
void test() {
B b = new B();
this.foo(b, I.VALUE);
};
}
X.test()
would collect the class B
and the interface I
.
enclosingElement
- the method, type, or javascript unit to be searched inrequestor
- a callback object to which each match is reportedmonitor
- the progress monitor used to report progressJavaScriptModelException
- if the search failed. Reasons include:
public void searchDeclarationsOfSentMessages(IJavaScriptElement enclosingElement, SearchRequestor requestor, IProgressMonitor monitor) throws JavaScriptModelException
Consider the following code:
then searching for declarations of sent messages in method
class A {
void foo() {};
void bar() {};
}
class B extends A {
void foo() {};
}
class X {
void test() {
A a = new B();
a.foo();
B b = (B)a;
b.bar();
};
}
X.test()
would collect the methods
A.foo()
, B.foo()
, and A.bar()
.
enclosingElement
- the method, type, or javascript unit to be searched inrequestor
- a callback object to which each match is reportedmonitor
- the progress monitor used to report progressJavaScriptModelException
- if the search failed. Reasons include:
public static char[][] getAllSubtypeNames(char[] typeName, IJavaScriptSearchScope scope, int waitingPolicy, IProgressMonitor progressMonitor)
Gets all the names of subtypes of a given type name in the given scope.
typeName
- name of the type whose subtype names will be foundscope
- to search in for all the subtypes of the given type namewaitingPolicy
- one of
IJavaScriptSearchConstants.FORCE_IMMEDIATE_SEARCH
if
the search should start immediatelyIJavaScriptSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH
if the search should be cancelled if the underlying indexer
has not finished indexing the workspaceIJavaScriptSearchConstants.WAIT_UNTIL_READY_TO_SEARCH
if the search should wait for the underlying indexer to
finish indexing the workspaceprogressMonitor
- monitor to report progress topublic static char[][] getAllSynonyms(char[] typeName, IJavaScriptSearchScope scope, int waitingPolicy, IProgressMonitor progressMonitor)
Gets all the synonyms of a given type, including itself, in the given scope.
NOTE: It is guaranteed that itself will be the first synonym in the list.
typeName
- name of the type to get all the synonyms forscope
- to search in for all the synonyms of the given typewaitingPolicy
- one of
IJavaScriptSearchConstants.FORCE_IMMEDIATE_SEARCH
if
the search should start immediatelyIJavaScriptSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH
if the search should be cancelled if the underlying indexer
has not finished indexing the workspaceIJavaScriptSearchConstants.WAIT_UNTIL_READY_TO_SEARCH
if the search should wait for the underlying indexer to
finish indexing the workspaceprogressMonitor
- monitor to report progress toCopyright (c) IBM Corp. and others 2000, 2010. All Rights Reserved.