Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2012 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation Stephan Herrmann - Contributions for bug 215139 and bug 295894 /
  
  package org.eclipse.jdt.core.search;
  
  import  org.eclipse.core.resources.*;
  import  org.eclipse.core.runtime.*;
  
A SearchEngine searches for Java 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(IJavaElement, 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.

Noextend:
This class is not intended to be subclassed by clients.
  
  public class SearchEngine {

Internal adapter class.

Deprecated:
marking deprecated as it uses deprecated ISearchPattern
  
  	static class SearchPatternAdapter implements ISearchPattern {
  			this. = pattern;
  		}
  	}

Internal adapter class.

Deprecated:
marking deprecated as it uses deprecated IJavaSearchResultCollector
  
  	static class ResultCollectorAdapter extends SearchRequestor {
  			this. = resultCollector;
  		}

See also:
org.eclipse.jdt.core.search.SearchRequestor.acceptSearchMatch(org.eclipse.jdt.core.search.SearchMatch)
  
  		public void acceptSearchMatch(SearchMatch matchthrows CoreException {
  				match.getResource(),
  				match.getOffset(),
  				match.getOffset() + match.getLength(),
  				(IJavaElementmatch.getElement(),
  				match.getAccuracy()
  			);
  		}

See also:
org.eclipse.jdt.core.search.SearchRequestor.beginReporting()
  
  		public void beginReporting() {
  		}

See also:
org.eclipse.jdt.core.search.SearchRequestor.endReporting()
  
  		public void endReporting() {
  			this..done();
  		}
  	}

Internal adapter class.

Deprecated:
marking deprecated as it uses deprecated ITypeNameRequestor
  
  			this. = requestor;
  		}
  		public void acceptType(int modifierschar[] packageNamechar[] simpleTypeNamechar[][] enclosingTypeNamesString pathAccessRestriction access) {
  			if (Flags.isInterface(modifiers)) {
  				this..acceptInterface(packageNamesimpleTypeNameenclosingTypeNamespath);
  			} else {
  				this..acceptClass(packageNamesimpleTypeNameenclosingTypeNamespath);
 			}
 		}
 	}
 
 	// Search engine now uses basic engine functionalities
Creates a new search engine.
 
 	public SearchEngine() {
 		this. = new BasicSearchEngine();
 	}

Creates a new search engine with a list of working copies that will take precedence over their original compilation units in the subsequent search operations.

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).

Parameters:
workingCopies the working copies that take precedence over their original compilation units
Since:
3.0
 
 	public SearchEngine(ICompilationUnit[] workingCopies) {
 		this. = new BasicSearchEngine(workingCopies);
 	}
Creates a new search engine with a list of working copies that will take precedence over their original compilation units in the subsequent search operations.

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).

Deprecated:
Use SearchEngine(ICompilationUnit[]) instead.
Parameters:
workingCopies the working copies that take precedence over their original compilation units
Since:
2.0
 
 	public SearchEngine(IWorkingCopy[] workingCopies) {
 		int length = workingCopies.length;
 		ICompilationUnit[] units = new ICompilationUnit[length];
 		System.arraycopy(workingCopies, 0, units, 0, length);
 		this. = new BasicSearchEngine(units);
 	}

Creates a new search engine with the given working copy owner. The working copies owned by this owner will take precedence over the primary compilation units in the subsequent search operations.

Parameters:
workingCopyOwner the owner of the working copies that take precedence over their original compilation units
Since:
3.0
 
 	public SearchEngine(WorkingCopyOwner workingCopyOwner) {
 		this. = new BasicSearchEngine(workingCopyOwner);
 	}

Returns a Java search scope limited to the hierarchy of the given type. The Java elements resulting from a search with this scope will be types in this hierarchy, or members of the types in this hierarchy.

Parameters:
type the focus of the hierarchy scope
Returns:
a new hierarchy scope
Throws:
JavaModelException if the hierarchy could not be computed on the given type
 
 	public static IJavaSearchScope createHierarchyScope(IType typethrows JavaModelException {
 		return BasicSearchEngine.createHierarchyScope(type);
 	}

Returns a Java search scope limited to the hierarchy of the given type. When the hierarchy is computed, the types defined in the working copies owned by the given owner take precedence over the original compilation units. The Java elements resulting from a search with this scope will be types in this hierarchy, or members of the types in this hierarchy.

Parameters:
type the focus of the hierarchy scope
owner the owner of working copies that take precedence over original compilation units
Returns:
a new hierarchy scope
Throws:
JavaModelException if the hierarchy could not be computed on the given type
Since:
3.0
 
 	public static IJavaSearchScope createHierarchyScope(IType typeWorkingCopyOwner ownerthrows JavaModelException {
 		return BasicSearchEngine.createHierarchyScope(typeowner);
 	}

Returns a Java search scope limited to the hierarchy of the given type and to a given project. The Java elements resulting from a search with this scope will be types in this hierarchy.

Unlike the createHierarchyScope methods, this method creates strict scopes that only contain types that actually span the hierarchy of the focus type, but do not include additional enclosing or member types.

By default, hierarchy scopes include all direct and indirect supertypes and subtypes of the focus type. This method, however, allows to restrict the hierarchy to true subtypes, and exclude supertypes. Also, inclusion of the focus type itself is controlled by a parameter.

Parameters:
project the project to which to constrain the search, or null if search should consider all types in the workspace
type the focus of the hierarchy scope
onlySubtypes if true only subtypes of type are considered
includeFocusType if true the focus type type is included in the resulting scope, otherwise it is excluded
owner the owner of working copies that take precedence over original compilation units, or null if the primary working copy owner should be used
Returns:
a new hierarchy scope
Throws:
JavaModelException if the hierarchy could not be computed on the given type
Since:
3.6
 
 	public static IJavaSearchScope createStrictHierarchyScope(IJavaProject projectIType typeboolean onlySubtypesboolean includeFocusTypeWorkingCopyOwner ownerthrows JavaModelException {
 		return BasicSearchEngine.createStrictHierarchyScope(projecttypeonlySubtypesincludeFocusTypeowner);
 	}

Returns a Java search scope limited to the given resources. The Java elements resulting from a search with this scope will have their underlying resource included in or equals to one of the given resources.

Resources must not overlap, for example, one cannot include a folder and its children.

Deprecated:
Use createJavaSearchScope(IJavaElement[]) instead.
Parameters:
resources the resources the scope is limited to
Returns:
a new Java search scope
 
 	public static IJavaSearchScope createJavaSearchScope(IResource[] resources) {
 		int length = resources.length;
 		IJavaElement[] elements = new IJavaElement[length];
 		for (int i = 0; i < lengthi++) {
 			elements[i] = JavaCore.create(resources[i]);
 		}
 		return createJavaSearchScope(elements);
 	}

Returns a Java search scope limited to the given Java elements. The Java elements resulting from a search with this scope will be children of the given elements.

If an element is an IJavaProject, 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 compilation 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).

Parameters:
elements the Java elements the scope is limited to
Returns:
a new Java search scope
Since:
2.0
 
 	public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elements) {
 		return BasicSearchEngine.createJavaSearchScope(elements);
 	}

Returns a Java search scope limited to the given Java elements. The Java elements resulting from a search with this scope will be children of the given elements.

If an element is an IJavaProject, then the project's source folders, its jars (external and internal) and - if specified - 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 compilation unit and class files of this package fragment will be included. Subpackages will NOT be included.

Parameters:
elements the Java elements the scope is limited to
includeReferencedProjects a flag indicating if referenced projects must be recursively included
Returns:
a new Java search scope
Since:
2.0
 
 	public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elementsboolean includeReferencedProjects) {
 		return BasicSearchEngine.createJavaSearchScope(elementsincludeReferencedProjects);
 	}

Returns a Java search scope limited to the given Java elements. The Java elements resulting from a search with this scope will be children of the given elements.

If an element is an IJavaProject, then it includes:

  • its source folders if IJavaSearchScope.SOURCES is specified,
  • its application libraries (internal and external jars, class folders that are on the raw classpath, or the ones that are coming from a classpath path variable, or the ones that are coming from a classpath container with the K_APPLICATION kind) if IJavaSearchScope.APPLICATION_LIBRARIES is specified
  • its system libraries (internal and external jars, class folders that are coming from an IClasspathContainer with the K_SYSTEM kind) if IJavaSearchScope.SYSTEM_LIBRARIES is specified
  • its referenced projects (with their source folders and jars, recursively) if IJavaSearchScope.REFERENCED_PROJECTS is specified.

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 compilation unit and class files of this package fragment will be included. Subpackages will NOT be included.

Parameters:
elements the Java elements the scope is limited to
includeMask the bit-wise OR of all include types of interest
Returns:
a new Java search scope
Since:
3.0
See also:
IJavaSearchScope.SOURCES
IJavaSearchScope.APPLICATION_LIBRARIES
IJavaSearchScope.SYSTEM_LIBRARIES
IJavaSearchScope.REFERENCED_PROJECTS
 
 	public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elementsint includeMask) {
 		return BasicSearchEngine.createJavaSearchScope(elementsincludeMask);
 	}

Returns a search pattern that combines the given two patterns into a "or" pattern. The search result will match either the left pattern or the right pattern.

Deprecated:
Use SearchPattern.createOrPattern(SearchPattern, SearchPattern) instead.
Parameters:
leftPattern the left pattern
rightPattern the right pattern
Returns:
a "or" pattern
 
 	public static ISearchPattern createOrSearchPattern(ISearchPattern leftPatternISearchPattern rightPattern) {
 		SearchPattern left = ((SearchPatternAdapterleftPattern).;
 		SearchPattern right = ((SearchPatternAdapterrightPattern).;
 		SearchPattern pattern = SearchPattern.createOrPattern(leftright);
 		return new SearchPatternAdapter(pattern);
 	}

Returns a search pattern based on a given string pattern. The string patterns support '*' wild-cards. The remaining parameters are used to narrow down the type of expected results.
Examples:
  • search for case insensitive references to Object: createSearchPattern("Object", TYPE, REFERENCES, false);
  • search for case sensitive references to exact Object() constructor: createSearchPattern("java.lang.Object()", CONSTRUCTOR, REFERENCES, true);
  • search for implementers of java.lang.Runnable: createSearchPattern("java.lang.Runnable", TYPE, IMPLEMENTORS, true);

Deprecated:
Use SearchPattern.createPattern(String, int, int, int) instead.
Parameters:
stringPattern the given pattern
searchFor determines the nature of the searched elements
  • IJavaSearchConstants.CLASS: only look for classes
  • IJavaSearchConstants.INTERFACE: only look for interfaces
  • IJavaSearchConstants.TYPE: look for both classes and interfaces
  • IJavaSearchConstants.FIELD: look for fields
  • IJavaSearchConstants.METHOD: look for methods
  • IJavaSearchConstants.CONSTRUCTOR: look for constructors
  • IJavaSearchConstants.PACKAGE: look for packages
limitTo determines the nature of the expected matches
  • IJavaSearchConstants.DECLARATIONS: will search declarations matching with the corresponding element. In case the element is a method, declarations of matching methods in subtypes will also be found, allowing to find declarations of abstract methods, etc.
  • IJavaSearchConstants.REFERENCES: will search references to the given element.
  • IJavaSearchConstants.ALL_OCCURRENCES: will search for either declarations or references as specified above.
  • IJavaSearchConstants.IMPLEMENTORS: for types, will find all types which directly implement/extend a given interface. Note that types may be only classes or only interfaces if or IJavaSearchConstants.INTERFACE is respectively used instead of IJavaSearchConstants.TYPE.
isCaseSensitive indicates whether the search is case sensitive or not.
Returns:
a search pattern on the given string pattern, or null if the string pattern is ill-formed.
 
 	public static ISearchPattern createSearchPattern(String stringPatternint searchForint limitToboolean isCaseSensitive) {
 		int matchMode = stringPattern.indexOf('*') != -1 || stringPattern.indexOf('?') != -1
 		int matchRule = isCaseSensitive ? matchMode | . : matchMode;
 		return  new SearchPatternAdapter(SearchPattern.createPattern(stringPatternsearchForlimitTomatchRule));
 	}

Returns a search pattern based on a given Java element. The pattern is used to trigger the appropriate search, and can be parameterized as follows:

Deprecated:
Use SearchPattern.createPattern(IJavaElement, int) instead.
Parameters:
element the Java element the search pattern is based on
limitTo determines the nature of the expected matches
  • IJavaSearchConstants.DECLARATIONS: will search declarations matching with the corresponding element. In case the element is a method, declarations of matching methods in subtypes will also be found, allowing to find declarations of abstract methods, etc.
  • IJavaSearchConstants.REFERENCES: will search references to the given element.
  • IJavaSearchConstants.ALL_OCCURRENCES: will search for either declarations or references as specified above.
  • IJavaSearchConstants.IMPLEMENTORS: for types, will find all types which directly implement/extend a given interface.
Returns:
a search pattern for a Java element or null if the given element is ill-formed
 
 	public static ISearchPattern createSearchPattern(IJavaElement elementint limitTo) {
 		return new SearchPatternAdapter(SearchPattern.createPattern(elementlimitTo));
 	}

Create a type name match on a given type with specific modifiers.

Parameters:
type The java model handle of the type
modifiers Modifiers of the type
Returns:
A non-null match on the given type.
Since:
3.3
 
 	public static TypeNameMatch createTypeNameMatch(IType typeint modifiers) {
 		return BasicSearchEngine.createTypeNameMatch(typemodifiers);
 	}

Returns a Java search scope with the workspace as the only limit.

Returns:
a new workspace scope
 
 	public static IJavaSearchScope createWorkspaceScope() {
 		return BasicSearchEngine.createWorkspaceScope();
 	}
Returns a new default Java search participant.

Returns:
a new default Java search participant
Since:
3.0
 
 		return BasicSearchEngine.getDefaultSearchParticipant();
 	}

Searches for the Java element determined by the given signature. The signature can be incomplete. For example, a call like search(ws, "run()", METHOD,REFERENCES, col) searches for all references to the method run. Note that by default the pattern will be case insensitive. For specifying case s sensitive search, use search(workspace, createSearchPattern(patternString, searchFor, limitTo, true), scope, resultCollector);

Deprecated:
Use search(SearchPattern, SearchParticipant[], IJavaSearchScope, SearchRequestor, IProgressMonitor) instead.
Parameters:
workspace the workspace
patternString the pattern to be searched for
searchFor a hint what kind of Java element the string pattern represents. Look into IJavaSearchConstants for valid values
limitTo one of the following values:
  • IJavaSearchConstants.DECLARATIONS: search for declarations only
  • IJavaSearchConstants.REFERENCES: search for all references
  • IJavaSearchConstants.ALL_OCCURRENCES: search for both declarations and all references
  • IJavaSearchConstants.IMPLEMENTORS: for types, will find all types which directly implement/extend a given interface.
    Note that types may be only classes or only interfaces if respectively IJavaSearchConstants.CLASS or IJavaSearchConstants.INTERFACE is used for searchFor parameter instead of IJavaSearchConstants.TYPE.
scope the search result has to be limited to the given scope
resultCollector a callback object to which each match is reported
Throws:
JavaModelException if the search failed. Reasons include:
  • the classpath is incorrectly set
 
 	public void search(IWorkspace workspaceString patternStringint searchForint limitToIJavaSearchScope scopeIJavaSearchResultCollector resultCollectorthrows JavaModelException {
 		try {
 			int matchMode = patternString.indexOf('*') != -1 || patternString.indexOf('?') != -1
 				SearchPattern.createPattern(patternStringsearchForlimitTomatchMode | .),
 				scope,
 				new ResultCollectorAdapter(resultCollector),
 				resultCollector.getProgressMonitor());
 		} catch (CoreException e) {
 			if (e instanceof JavaModelException)
 				throw (JavaModelExceptione;
 			throw new JavaModelException(e);
 		}
 	}

Searches for the given Java element.

Deprecated:
Use search(SearchPattern, SearchParticipant[], IJavaSearchScope, SearchRequestor, IProgressMonitor) instead.
Parameters:
workspace the workspace
element the Java element to be searched for
limitTo one of the following values:
  • IJavaSearchConstants.DECLARATIONS: search for declarations only
  • IJavaSearchConstants.REFERENCES: search for all references
  • IJavaSearchConstants.ALL_OCCURRENCES: search for both declarations and all references
  • IJavaSearchConstants.IMPLEMENTORS: for types, will find all types which directly implement/extend a given interface.
scope the search result has to be limited to the given scope
resultCollector a callback object to which each match is reported
Throws:
JavaModelException if the search failed. Reasons include:
  • the element doesn't exist
  • the classpath is incorrectly set
 
 	public void search(IWorkspace workspaceIJavaElement elementint limitToIJavaSearchScope scopeIJavaSearchResultCollector resultCollectorthrows JavaModelException {
 		search(workspacecreateSearchPattern(elementlimitTo), scoperesultCollector);
 	}

Searches for matches of a given search pattern. Search patterns can be created using helper methods (from a String pattern or a Java element) and encapsulate the description of what is being searched (for example, search method declarations in a case sensitive way).

Deprecated:
Use search(SearchPattern, SearchParticipant[], IJavaSearchScope, SearchRequestor, IProgressMonitor) instead.
Parameters:
workspace the workspace
searchPattern the pattern to be searched for
scope the search result has to be limited to the given scope
resultCollector a callback object to which each match is reported
Throws:
JavaModelException if the search failed. Reasons include:
  • the classpath is incorrectly set
 
 	public void search(IWorkspace workspaceISearchPattern searchPatternIJavaSearchScope scopeIJavaSearchResultCollector resultCollectorthrows JavaModelException {
 		try {
 				((SearchPatternAdapter)searchPattern).,
 				scope,
 				new ResultCollectorAdapter(resultCollector),
 				resultCollector.getProgressMonitor());
 		} catch (CoreException e) {
 			if (e instanceof JavaModelException)
 				throw (JavaModelExceptione;
 			throw new JavaModelException(e);
 		}
 	}

Searches for matches of a given search pattern. Search patterns can be created using helper methods (from a String pattern or a Java element) and encapsulate the description of what is being searched (for example, search method declarations in a case sensitive way).

Parameters:
pattern the pattern to search
participants the participants in the search
scope the search scope
requestor the requestor to report the matches to
monitor the progress monitor used to report progress
Throws:
CoreException if the search failed. Reasons include:
  • the classpath is incorrectly set
Since:
3.0
 
 	public void search(SearchPattern patternSearchParticipant[] participantsIJavaSearchScope scopeSearchRequestor requestor, IProgressMonitor monitorthrows CoreException {
 		this..search(patternparticipantsscoperequestormonitor);
 	}

Searches for all top-level types and member types in the given scope. The search can be selecting specific types (given a package exact full name or a type name with specific match mode).

Deprecated:
Use searchAllTypeNames(char[], int, char[], int, int, IJavaSearchScope, TypeNameRequestor, int, IProgressMonitor) instead
Parameters:
packageExactName the exact package full name of the searched types.
If you want to use a prefix or a wild-carded string for package, you need to use searchAllTypeNames(char[], int, char[], int, int, IJavaSearchScope, TypeNameRequestor, int, IProgressMonitor) method instead. 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.
matchRule type name match rule 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 the type name is a camel case of the searched types name.
  • SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH if the type name is a camel case with same part count of the searched types name.
combined with 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
  • IJavaSearchConstants.CLASS: only look for classes
  • IJavaSearchConstants.INTERFACE: only look for interfaces
  • IJavaSearchConstants.ENUM: only look for enumeration
  • IJavaSearchConstants.ANNOTATION_TYPE: only look for annotation type
  • IJavaSearchConstants.CLASS_AND_ENUM: only look for classes and enumerations
  • IJavaSearchConstants.CLASS_AND_INTERFACE: only look for classes and interfaces
  • IJavaSearchConstants.TYPE: look for all types (i.e. classes, interfaces, enum and annotation types)
scope the scope to search in
nameRequestor the requestor that collects the results of the search
waitingPolicy one of
  • IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH if the search should start immediately
  • IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH if the search should be cancelled if the underlying indexer has not finished indexing the workspace
  • IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH if the search should wait for the underlying indexer to finish indexing the workspace
progressMonitor the progress monitor to report progress to, or null if no progress monitor is provided
Throws:
JavaModelException if the search failed. Reasons include:
  • the classpath is incorrectly set
Since:
3.1
 
 	public void searchAllTypeNames(
 		final char[] packageExactName,
 		final char[] typeName,
 		final int matchRule,
 		int searchFor,
 		final TypeNameRequestor nameRequestor,
 		int waitingPolicy,
 		IProgressMonitor progressMonitor)  throws JavaModelException {
 
 		searchAllTypeNames(packageExactName.typeNamematchRulesearchForscopenameRequestorwaitingPolicyprogressMonitor);
 	}

Searches for all top-level types and member types in the given scope. The search can be selecting specific types (given a package name using specific match mode and/or a type name using another specific match mode).

Parameters:
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 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 the package name is a camel case of the searched types package name.
  • SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH if the package name is a camel case with same part count of the searched types package name.
combined with 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.
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 the type name is a camel case of the searched types name.
  • SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH if the type name is a camel case with same part count of the searched types name.
combined with 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
  • IJavaSearchConstants.CLASS: only look for classes
  • IJavaSearchConstants.INTERFACE: only look for interfaces
  • IJavaSearchConstants.ENUM: only look for enumeration
  • IJavaSearchConstants.ANNOTATION_TYPE: only look for annotation type
  • IJavaSearchConstants.CLASS_AND_ENUM: only look for classes and enumerations
  • IJavaSearchConstants.CLASS_AND_INTERFACE: only look for classes and interfaces
  • IJavaSearchConstants.TYPE: look for all types (i.e. classes, interfaces, enum and annotation types)
scope the scope to search in
nameRequestor the requestor that collects the results of the search
waitingPolicy one of
  • IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH if the search should start immediately
  • IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH if the search should be cancelled if the underlying indexer has not finished indexing the workspace
  • IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH if the search should wait for the underlying indexer to finish indexing the workspace
progressMonitor the progress monitor to report progress to, or null if no progress monitor is provided
Throws:
JavaModelException if the search failed. Reasons include:
  • the classpath is incorrectly set
Since:
3.3
 
 	public void searchAllTypeNames(
 		final char[] packageName,
 		final int packageMatchRule,
 		final char[] typeName,
 		final int typeMatchRule,
 		int searchFor,
 		final TypeNameRequestor nameRequestor,
 		int waitingPolicy,
 		IProgressMonitor progressMonitor)  throws JavaModelException {
 
 		TypeNameRequestorWrapper requestorWrapper = new TypeNameRequestorWrapper(nameRequestor);
 		this..searchAllTypeNames(packageName,
 			packageMatchRule,
 			typeName,
 			typeMatchRule,
 			searchFor,
 			scope,
 			requestorWrapper,
 			waitingPolicy,
 			progressMonitor);
 	}

Searches for all top-level types and member types in the given scope. The search can be selecting specific types (given a package name using specific match mode and/or a type name using another specific match mode).

Provided TypeNameMatchRequestor requestor will collect TypeNameMatch matches found during the search.

Parameters:
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 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 the package name is a camel case of the searched types package name.
  • SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH if the package name is a camel case with same part count of the searched types package name.
combined with 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.
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.
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 the type name is a camel case of the searched types name.
  • SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH if the type name is a camel case with same part count of the searched types name.
combined with 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
  • IJavaSearchConstants.CLASS: only look for classes
  • IJavaSearchConstants.INTERFACE: only look for interfaces
  • IJavaSearchConstants.ENUM: only look for enumeration
  • IJavaSearchConstants.ANNOTATION_TYPE: only look for annotation type
  • IJavaSearchConstants.CLASS_AND_ENUM: only look for classes and enumerations
  • IJavaSearchConstants.CLASS_AND_INTERFACE: only look for classes and interfaces
  • IJavaSearchConstants.TYPE: look for all types (i.e. classes, interfaces, enum and annotation types)
scope the scope to search in
nameMatchRequestor the requestor that collects matches of the search.
waitingPolicy one of
  • IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH if the search should start immediately
  • IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH if the search should be cancelled if the underlying indexer has not finished indexing the workspace
  • IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH if the search should wait for the underlying indexer to finish indexing the workspace
progressMonitor the progress monitor to report progress to, or null if no progress monitor is provided
Throws:
JavaModelException if the search failed. Reasons include:
  • the classpath is incorrectly set
Since:
3.3
 
 	public void searchAllTypeNames(
 		final char[] packageName,
 		final int packageMatchRule,
 		final char[] typeName,
 		final int typeMatchRule,
 		int searchFor,
 		final TypeNameMatchRequestor nameMatchRequestor,
 		int waitingPolicy,
 		IProgressMonitor progressMonitor)  throws JavaModelException {
 
 		TypeNameMatchRequestorWrapper requestorWrapper = new TypeNameMatchRequestorWrapper(nameMatchRequestorscope);
 		this..searchAllTypeNames(packageName,
 			packageMatchRule,
 			typeName,
 			typeMatchRule,
 			searchFor,
 			scope,
 			requestorWrapper,
 			waitingPolicy,
 			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.

Parameters:
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 in
nameRequestor the requestor that collects the results of the search
waitingPolicy one of
  • IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH if the search should start immediately
  • IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH if the search should be cancelled if the underlying indexer has not finished indexing the workspace
  • IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH if the search should wait for the underlying indexer to finish indexing the workspace
progressMonitor the progress monitor to report progress to, or null if no progress monitor is provided
Throws:
JavaModelException if the search failed. Reasons include:
  • the classpath is incorrectly set
Since:
3.1
 
 	public void searchAllTypeNames(
 		final char[][] qualifications,
 		final char[][] typeNames,
 		final TypeNameRequestor nameRequestor,
 		int waitingPolicy,
 		IProgressMonitor progressMonitor)  throws JavaModelException {
 
 		TypeNameRequestorWrapper requestorWrapper = new TypeNameRequestorWrapper(nameRequestor);
 			qualifications,
 			typeNames,
 			scope,
 			requestorWrapper,
 			waitingPolicy,
 			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.

Provided TypeNameMatchRequestor requestor will collect TypeNameMatch matches found during the search.

Parameters:
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 in
nameMatchRequestor the requestor that collects matches of the search.
waitingPolicy one of
  • IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH if the search should start immediately
  • IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH if the search should be cancelled if the underlying indexer has not finished indexing the workspace
  • IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH if the search should wait for the underlying indexer to finish indexing the workspace
progressMonitor the progress monitor to report progress to, or null if no progress monitor is provided
Throws:
JavaModelException if the search failed. Reasons include:
  • the classpath is incorrectly set
Since:
3.3
 
 	public void searchAllTypeNames(
 		final char[][] qualifications,
 		final char[][] typeNames,
 		final TypeNameMatchRequestor nameMatchRequestor,
 		int waitingPolicy,
 		IProgressMonitor progressMonitor)  throws JavaModelException {
 
 		TypeNameMatchRequestorWrapper requestorWrapper = new TypeNameMatchRequestorWrapper(nameMatchRequestorscope);
 			qualifications,
 			typeNames,
 			scope,
 			requestorWrapper,
 			waitingPolicy,
 			progressMonitor);
 	}

Searches for all top-level types and member types in the given scope. The search can be selecting specific types (given a package or a type name prefix and match modes).

Deprecated:
Use searchAllTypeNames(char[], char[], int, int, IJavaSearchScope, TypeNameRequestor, int, IProgressMonitor) instead
Parameters:
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.
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.
matchRule 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.
combined with 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 one of
  • IJavaSearchConstants.CLASS if searching for classes only
  • IJavaSearchConstants.INTERFACE if searching for interfaces only
  • IJavaSearchConstants.TYPE if searching for both classes and interfaces
scope the scope to search in
nameRequestor the requestor that collects the results of the search
waitingPolicy one of
  • IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH if the search should start immediately
  • IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH if the search should be cancelled if the underlying indexer has not finished indexing the workspace
  • IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH if the search should wait for the underlying indexer to finish indexing the workspace
progressMonitor the progress monitor to report progress to, or null if no progress monitor is provided
Throws:
JavaModelException if the search failed. Reasons include:
  • the classpath is incorrectly set
Since:
3.0
	public void searchAllTypeNames(
		final char[] packageName,
		final char[] typeName,
		final int matchRule,
		int searchFor,
		final ITypeNameRequestor nameRequestor,
		int waitingPolicy,
		IProgressMonitor progressMonitor)  throws JavaModelException {
		TypeNameRequestorAdapter requestorAdapter = new TypeNameRequestorAdapter(nameRequestor);
		this..searchAllTypeNames(packageName.typeNamematchRulesearchForscoperequestorAdapterwaitingPolicyprogressMonitor);
	}

Searches for all top-level types and member types in the given scope. The search can be selecting specific types (given a package or a type name prefix and match modes).

Deprecated:
Use searchAllTypeNames(char[], char[], int, int, IJavaSearchScope, ITypeNameRequestor, int, IProgressMonitor) instead
Parameters:
workspace the workspace to search in
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.
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.
matchMode one of
  • IJavaSearchConstants.EXACT_MATCH if the package name and type name are the full names of the searched types.
  • IJavaSearchConstants.PREFIX_MATCH if the package name and type name are prefixes of the names of the searched types.
  • IJavaSearchConstants.PATTERN_MATCH if the package name and type name contain wild-cards.
isCaseSensitive whether the search should be case sensitive
searchFor one of
  • IJavaSearchConstants.CLASS if searching for classes only
  • IJavaSearchConstants.INTERFACE if searching for interfaces only
  • IJavaSearchConstants.TYPE if searching for both classes and interfaces
scope the scope to search in
nameRequestor the requestor that collects the results of the search
waitingPolicy one of
  • IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH if the search should start immediately
  • IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH if the search should be cancelled if the underlying indexer has not finished indexing the workspace
  • IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH if the search should wait for the underlying indexer to finish indexing the workspace
progressMonitor the progress monitor to report progress to, or null if no progress monitor is provided
Throws:
JavaModelException if the search failed. Reasons include:
  • the classpath is incorrectly set
	public void searchAllTypeNames(
		IWorkspace workspace,
		final char[] packageName,
		final char[] typeName,
		final int matchMode,
		final boolean isCaseSensitive,
		int searchFor,
		final ITypeNameRequestor nameRequestor,
		int waitingPolicy,
		IProgressMonitor progressMonitor)  throws JavaModelException {
			packageName,
			typeName,
			isCaseSensitive ? matchMode | . : matchMode,
			searchFor,
			scope,
			nameRequestor,
			waitingPolicy,
			progressMonitor);
	}

Searches for all declarations of the fields accessed in the given element. The element can be a compilation unit or a source type/method/field. Reports the field declarations using the given requestor.

Consider the following code:

  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);
   };
  }
 
then searching for declarations of accessed fields in method X.test() would collect the fields B.value and A.field1.

Parameters:
enclosingElement the field, method, type, or compilation unit to be searched in
requestor a callback object to which each match is reported
monitor the progress monitor used to report progress
Throws:
JavaModelException if the search failed. Reasons include:
  • the element doesn't exist
  • the classpath is incorrectly set
IllegalArgumentException if the given java element has not the right type
Since:
3.0
	public void searchDeclarationsOfAccessedFields(IJavaElement enclosingElementSearchRequestor requestor, IProgressMonitor monitorthrows JavaModelException {
		this..searchDeclarationsOfAccessedFields(enclosingElementrequestormonitor);
	}

Searches for all declarations of the fields accessed in the given element. The element can be a compilation unit, a source type, or a source method. Reports the field declarations using the given collector.

Consider the following code:

  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);
   };
  }
 
then searching for declarations of accessed fields in method X.test() would collect the fields B.value and A.field1.

Deprecated:
Use searchDeclarationsOfAccessedFields(IJavaElement, SearchRequestor, IProgressMonitor) instead.
Parameters:
workspace the workspace
enclosingElement the method, type, or compilation unit to be searched in
resultCollector a callback object to which each match is reported
Throws:
JavaModelException if the search failed. Reasons include:
  • the element doesn't exist
  • the classpath is incorrectly set
	public void searchDeclarationsOfAccessedFields(IWorkspace workspaceIJavaElement enclosingElementIJavaSearchResultCollector resultCollectorthrows JavaModelException {
		SearchPattern pattern = new DeclarationOfAccessedFieldsPattern(enclosingElement);
		this..searchDeclarations(enclosingElementnew ResultCollectorAdapter(resultCollector), patternresultCollector.getProgressMonitor());
	}

Searches for all declarations of the types referenced in the given element. The element can be a compilation unit or a source type/method/field. Reports the type declarations using the given requestor.

Consider the following code:

  class A {
  }
  class B extends A {
  }
  interface I {
    int VALUE = 0;
  }
  class X {
   void test() {
    B b = new B();
    this.foo(b, I.VALUE);
   };
  }
 
then searching for declarations of referenced types in method X.test() would collect the class B and the interface I.

Parameters:
enclosingElement the field, method, type, or compilation unit to be searched in
requestor a callback object to which each match is reported
monitor the progress monitor used to report progress
Throws:
JavaModelException if the search failed. Reasons include:
  • the element doesn't exist
  • the classpath is incorrectly set
IllegalArgumentException if the given java element has not the right type
Since:
3.0
	public void searchDeclarationsOfReferencedTypes(IJavaElement enclosingElementSearchRequestor requestor, IProgressMonitor monitorthrows JavaModelException {
		this..searchDeclarationsOfReferencedTypes(enclosingElementrequestormonitor);
	}

Searches for all declarations of the types referenced in the given element. The element can be a compilation unit, a source type, or a source method. Reports the type declarations using the given collector.

Consider the following code:

  class A {
  }
  class B extends A {
  }
  interface I {
    int VALUE = 0;
  }
  class X {
   void test() {
    B b = new B();
    this.foo(b, I.VALUE);
   };
  }
 
then searching for declarations of referenced types in method X.test() would collect the class B and the interface I.

Deprecated:
Use searchDeclarationsOfReferencedTypes(IJavaElement, SearchRequestor, IProgressMonitor) instead.
Parameters:
workspace the workspace
enclosingElement the method, type, or compilation unit to be searched in
resultCollector a callback object to which each match is reported
Throws:
JavaModelException if the search failed. Reasons include:
  • the element doesn't exist
  • the classpath is incorrectly set
	public void searchDeclarationsOfReferencedTypes(IWorkspace workspaceIJavaElement enclosingElementIJavaSearchResultCollector resultCollectorthrows JavaModelException {
		SearchPattern pattern = new DeclarationOfReferencedTypesPattern(enclosingElement);
		this..searchDeclarations(enclosingElementnew ResultCollectorAdapter(resultCollector), patternresultCollector.getProgressMonitor());
	}

Searches for all declarations of the methods invoked in the given element. The element can be a compilation unit or a source type/method/field. Reports the method declarations using the given requestor.

Consider the following code:

  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();
   };
  }
 
then searching for declarations of sent messages in method X.test() would collect the methods A.foo(), B.foo(), and A.bar().

Parameters:
enclosingElement the field, method, type or compilation unit to be searched in
requestor a callback object to which each match is reported
monitor the progress monitor used to report progress
Throws:
JavaModelException if the search failed. Reasons include:
  • the element doesn't exist
  • the classpath is incorrectly set
IllegalArgumentException if the given java element has not the right type
Since:
3.0
	public void searchDeclarationsOfSentMessages(IJavaElement enclosingElementSearchRequestor requestor, IProgressMonitor monitorthrows JavaModelException {
		this..searchDeclarationsOfSentMessages(enclosingElementrequestormonitor);
	}

Searches for all declarations of the methods invoked in the given element. The element can be a compilation unit, a source type, or a source method. Reports the method declarations using the given collector.

Consider the following code:

  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();
   };
  }
 
then searching for declarations of sent messages in method X.test() would collect the methods A.foo(), B.foo(), and A.bar().

Deprecated:
Use searchDeclarationsOfSentMessages(IJavaElement, SearchRequestor, IProgressMonitor) instead.
Parameters:
workspace the workspace
enclosingElement the method, type, or compilation unit to be searched in
resultCollector a callback object to which each match is reported
Throws:
JavaModelException if the search failed. Reasons include:
  • the element doesn't exist
  • the classpath is incorrectly set
	public void searchDeclarationsOfSentMessages(IWorkspace workspaceIJavaElement enclosingElementIJavaSearchResultCollector resultCollectorthrows JavaModelException {
		SearchPattern pattern = new DeclarationOfReferencedMethodsPattern(enclosingElement);
		this..searchDeclarations(enclosingElementnew ResultCollectorAdapter(resultCollector), patternresultCollector.getProgressMonitor());
New to GrepCode? Check out our FAQ X